Adding a response header to specific resources | Community
Skip to main content
Level 2
February 23, 2021
Solved

Adding a response header to specific resources

  • February 23, 2021
  • 1 reply
  • 4410 views

I am trying to add response header, specifically - Content-Security-Policy script-src to requests on resources under /content/dam/ or resources with .png extension.  Should I add the filters on sling? or is there any other way to it directly add headers on dispatcher.

This post is no longer active and is closed to new replies. Need help? Start a new post to ask your question.
Best answer by raj_mandalapu

There are two approaches, using sling filters or adding this in the Apache layer

If you go with the filter you need to put proper conditions because the filter executes for every request. you need to put the proper pattern and also need to put condition only to execute images files something like .svg, png, etc.

check below link, it sets header location header

http://www.coderss.in/aem-sling-filters-2/

The other way is handling this at the apache level, refer to the below articles. I prefer to use Apache configurations.

https://stackoverflow.com/questions/42791279/how-to-set-apache-conditional-header-based-on-url

https://ole.michelsen.dk/blog/secure-your-website-with-content-security-policy/

 

1 reply

raj_mandalapu
raj_mandalapuAccepted solution
Level 7
February 23, 2021

There are two approaches, using sling filters or adding this in the Apache layer

If you go with the filter you need to put proper conditions because the filter executes for every request. you need to put the proper pattern and also need to put condition only to execute images files something like .svg, png, etc.

check below link, it sets header location header

http://www.coderss.in/aem-sling-filters-2/

The other way is handling this at the apache level, refer to the below articles. I prefer to use Apache configurations.

https://stackoverflow.com/questions/42791279/how-to-set-apache-conditional-header-based-on-url

https://ole.michelsen.dk/blog/secure-your-website-with-content-security-policy/