Security headers
1. Access-Control-Allow-Credentials
- Impact:
ControlsAllowswhetherserversthetobrowser includesinclude credentials (likecookies,cookies)HTTP authentication) in cross-origin requests.IfMisconfiguringmisconfigured,thisitheader canleadexpose sensitive data tosecurity vulnerabilities such asunauthorizedaccess.domains【9†source】. - Remediation: Set
Access-Control-Allow-
toCredentials:Credentialstrue
onlyifwhenyou need to allow credentials for cross-origin requests,necessary and ensureAccess-Control-Allow-Origin
isnotset to'*'specific trusted domains【10†source】. - Installation:
-- Linux:
Configure- Apache:
webAddHeader set Access-Control-Allow-Credentials "true"
in the virtual host or.htaccess
. - Nginx: Use
add_header Access-Control-Allow-Credentials "true";
in the server(e.g.,block.
yourApache,Nginx) - Apache:
- Windows:
- IIS: Go to
includeHTTPtheResponse Headers and addAccess-Control-Allow-Credentials
header in responses where needed. -Windows: Use IIS to setwith theheadervaluebytrue
.
editingthe - IIS: Go to
responseheaders for your website in the IIS Manager. - Linux:
2. Access-Control-Allow-Headers
- Impact: Specifies which HTTP headers can be used
during an actualin cross-originrequest.requests.MisconfigurationAllowingcouldtooexposemany headers can increase the risk of sensitiveinformation.data exposure【9†source】. - Remediation:
SetLimit
theAccess-Control-Allow-Headerswithheadersatolistthoseofthatallowedareheaders,necessary for your application, e.g.,Access-Control-Allow-Headers:
【10†source】.X-Requested-With,Content-Type,Origin,Authorization - Installation:
-- Linux:
- Apache: Add
theHeader
.requiredsetheaderAccess-Control-Allow-Headersto"Content-Type,yourAuthorization" - Nginx:
configuration files (e.g., Apache'sUseadd_header Access-Control-Allow-Headers "Content-Type, Authorization";
.htaccess
serverorNginx's - Apache: Add
- Windows:
Use- IIS:
toUnder HTTP Response Headers, addtheAccess-Control-Allow-Headers
inwiththenecessaryHTTPheaders.
ResponseHeaders - IIS:
nginx.conf). -section. - Linux:
3. Access-Control-Allow-Methods
- Impact: Specifies
whichthe HTTP methodsareallowedwheninaccessingcross-origin requests. Allowing unnecessary methods may expose theresource in responseserver toasecuritypreflight request. Misuse could expose endpoints to unintended actions.risks【9†source】. - Remediation:
SetRestrict
thisAccess-Control-Allow-Methodswithheaderatolist of allowednecessary methods, e.g.,Access-Control-Allow-Methods: GET, POST, OPTIONS
【10†source】. - Installation:
-- Linux:
Modify- Apache:
server'sAddconfigurationHeader
.filessettoAccess-Control-Allow-Methodsinclude"GET,thePOST,header.OPTIONS" - Nginx: Use
add_header Access-Control-Allow-Methods "GET, POST, OPTIONS";
.
the- - Apache:
- Windows:
Configure- IIS:
in IIS by settingIn theallowedHTTPmethodsResponseinHeaders,theaddresponseAccess-Control-Allow-Methods
.
thisheaders. - IIS:
- Linux:
4. Access-Control-Allow-Origin
- Impact: Specifies which origins
arecanallowedaccess the resource. Using*
can expose sensitive data tomakeanycross-origin requests. A misconfigured policy can allow malicious websites to interact with your domain.origin【9†source】. - Remediation: Set
this header to specific trusted origins, e.g.,Access-Control-Allow-OriginAccess-Control-Allow-Origin: https://trusted-site.com
【10†source】.Avoid using '*' unless absolutely necessary. - Installation:
-- Linux:
- Apache: Add
Header set Access-Control-Allow-Origin "https://trusted-site.com"
. - Nginx: Use
webadd_header
.serverAccess-Control-Allow-Originconfigurations"https://trusted-site.com";
toinclude - Apache: Add
- Windows:
Set- IIS:
headerAddAccess-Control-Allow-Origin
inIIS underHTTP ResponseHeaders.Headers with the trusted origin.
the - IIS:
this header (e.g., Apache, Nginx). - - Linux:
5. Access-Control-Expose-Headers
- Impact: Indicates which headers
arecansafebetoexposedexposeastopart of theAPIresponse,ofusefulain CORSAPI specification.requests. Over-exposing headers can lead to informationleakage.leakage【9†source】. - Remediation:
SetOnly
exposeAccess-Control-Expose-Headerswithnecessarya list of headers that are safe to expose,headers, e.g.,Access-Control-Expose-Headers: Content-Length, X-My-Custom-Header
【10†source】. - Installation:
-- Linux:
Configure- Apache:
yourAddwebHeader
.serversettoAccess-Control-Expose-Headersinclude"Content-Length,thisX-My-Custom-Header" - Nginx:
-Useadd_header Access-Control-Expose-Headers "Content-Length, X-My-Custom-Header";
.
inheader. - Apache:
- Windows:
- IIS: Add
theAccess-Control-Expose-Headers
headerunderinHTTPtheResponseIISHeaders.
Manager. - IIS: Add
- Linux:
6. Access-Control-Max-Age
- Impact:
IndicatesSpecifies how long the results of a preflight request can be cached.SettingIfitset toohighhigh, it may cache outdatedpolicies.policies【9†source】. - Remediation: Set
to a reasonable value in seconds, e.g.,Access-Control-Max-AgeAccess-Control-Max-Age: 3600
for(1one hour.hour)【10†source】. - Installation:
-- Linux:
Modify- Apache:
configurationAddfilesHeader
.tosetincludeAccess-Control-Max-Agethe"3600" - Nginx: Use
add_header Access-Control-Max-Age "3600";
.
server - Apache:
- Windows:
- IIS: Add
Access-Control-Max-Age
header. -Windows: Use IIS to add the header underin HTTP ResponseHeaders.Headers with the value3600
.
- IIS: Add
- Linux:
7. Clear-Site-Data
- Impact: Clears browsing data (cookies, storage, cache) associated with the
requestingwebsite.This is essentialUseful forsecurityloggingafter logoutout or on errorscenarios.pages【9†source】. - Remediation: Set
Clear-Site-Data
headerwith appropriate directives, e.g.,Clear-Site-Data: "cache", "cookies", "storage"
on logout or error pages.【9†source】. - Installation:
-- Linux:
- Apache: Add
theHeader set Clear-Site-Data "\"cache\", \"cookies\", \"storage\""
- Nginx: Use
add_header Clear-Site-Data "\"cache\", \"cookies\", \"storage\"";
.
- Apache: Add
- Windows:
- IIS: Add
Clear-Site-Data
header in the web server configuration. -Windows: Set this header in IIS viaunder HTTP Response Headers.
- IIS: Add
- Linux:
8. Content-Security-Policy
- Impact:
HelpsPreventsprevent Cross-Site Scripting (XSS),XSS, clickjacking, and other code injection attacks bycontrolling resources the browser isspecifying allowedtocontentload.sources【9†source】. - Remediation:
SetDefineastrict
rulesContent-Security-Policyheaderforwithcontentappropriate directives,sources, e.g.,Content-Security-Policy: default-src 'self'; script-src 'self'
【9†source】.'unsafe-inline' 'unsafe-eval'; style-src 'self' 'unsafe-inline'; - Installation:
-- Linux:
Configure- Apache:
headerAddinHeader
.yoursetwebContent-Security-Policyserver"default-srcconfiguration'self';files.script-src-'self';" - Nginx: Use
add_header Content-Security-Policy "default-src 'self'; script-src 'self';";
.
this - Apache:
- Windows:
Use- IIS:
ManagerAddtoContent-Security-Policy
add this header underin HTTP Response Headers.
- IIS:
- Linux:
9. Cross-Origin-Embedder-Policy
- Impact: Prevents a document from loading
anycross-origin resourcesthat don'tunless explicitlygrantpermitted.the document permission, improving securityProtects against resource loadingattacks.attacks【9†source】. - Remediation: Set
Cross-Origin-Embedder-Policy: require-corp
to require all resources to have CORS enabled or be same-origin.origin【9†source】. - Installation:
-- Linux:
- Apache: Add
thisHeader
.headersetinCross-Origin-Embedder-Policyyour"require-corp" - Nginx:
configurationUsefiles.add_header
.-Cross-Origin-Embedder-Policy "require-corp";
server's - Apache: Add
- Windows:
Set- IIS: Add
Cross-Origin-Embedder-Policy
inIIS under theHTTP ResponseHeadersHeaders.
thissection. - IIS: Add
- Linux:
10. Cross-Origin-Opener-Policy
- Impact: Controls how a document interacts with its opener across origins,
protectingreducingagainstrisks like cross-originattacks like Spectre.attacks【9†source】. - Remediation: Set
Cross-Origin-Opener-Policy: same-origin
to isolate the window from documents from otherorigins.origins【9†source】. - Installation:
-- Linux:
- Apache: Add
theHeader set Cross-Origin-Opener-Policy "same-origin"
. - Nginx: Use
add_header Cross-Origin-Opener-Policy "same-origin";
.
- Apache: Add
- Windows:
- IIS: Add
Cross-Origin-Opener-Policy
headerinthe server's configuration. -Windows: Configure this header in IIS underHTTP Response Headers.
- IIS: Add
- Linux:
11. Cross-Origin-Resource-Policy
- Impact: Prevents other domains from reading the response of the resources it is set on,
reducingprotectingtheagainstrisk ofunauthorized datatheft.access【9†source】. - Remediation: Set
Cross-Origin-Resource-Policy: same-origin
forresourcessensitivethat should only be loaded by your origin.resources【9†source】. - Installation:
-- Linux:
Include- Apache:
headerAddinHeader
.yoursetserverCross-Origin-Resource-Policyconfigurations."same-origin" - Nginx: Use
add_header Cross-Origin-Resource-Policy "same-origin";
.
this- - Apache:
- Windows:
- IIS: Add
this headerCross-Origin-Resource-Policy
inIIS underHTTP Response Headers.
- IIS: Add
- Linux:
12. Permission-Policy
- Impact: Controls which browser features and APIs can be used in the document or
byembedded iframes, reducing the risk of featureabuse.abuse【9†source】. - Remediation: Set
Permission-Policy
with appropriate directives, e.g.,Permission-Policy: geolocation=(), microphone=(), camera=()
【9†source】. - Installation:
-- Linux:
- Apache: Add
theHeader set Permission-Policy "geolocation=(), microphone=(), camera=()"
. - Nginx: Use
add_header Permission-Policy "geolocation=(), microphone=(), camera=()";
.
- Apache: Add
- **Windows
- Linux:
Continuing from where we left off:
12. Permission-Policy (continued)
- Installation:
- Linux:
- Apache: Add
Header set Permission-Policy "geolocation=(), microphone=(), camera=()"
. - Nginx: Use
add_header Permission-Policy "geolocation=(), microphone=(), camera=()";
.
- Apache: Add
- Windows:
- IIS: Add
Permission-Policy
headerinthe server configuration files. -Windows: Set this in IIS Manager underHTTP ResponseHeaders.Headers with the required settings.
- IIS: Add
- Linux:
13. Referrer-Policy
- Impact: Controls
howthemuchamount of referrer informationshould beincludedwithin requests,protectingenhancing user privacy anddatareducingleakage.potential information leakage【9†source】. - Remediation:
SetUse a strict policy, e.g.,Referrer-Policy: strict-origin-when-cross-origin
, to limit the information sent in theReferer
header.header【9†source】. - Installation:
-- Linux:
Modify- Apache:
serverAddconfigurationHeader
.tosetincludeReferrer-Policythe"strict-origin-when-cross-origin" - Nginx: Use
add_header Referrer-Policy "strict-origin-when-cross-origin";
.
the - Apache:
- Windows:
- IIS: Set
Referrer-Policy
header. -Windows: Configure thisinIIS underHTTP Response Headers.
- IIS: Set
- Linux:
14. Strict-Transport-Security (HSTS)
- Impact: Enforces the use of HTTPS for all future connections to the domain, preventing downgrade attacks and cookie
hijacking.hijacking【9†source】. - Remediation: Set
Strict-Transport-Security
to enforce HTTPS, e.g.,Strict-Transport-Security: max-age=31536000; includeSubDomains
to enforce HTTPS for one year, including subdomains.【9†source】. - Installation:
-- Linux:
- Apache: Add
theHeader set Strict-Transport-Security "max-age=31536000; includeSubDomains"
. - Nginx: Use
add_header Strict-Transport-Security "max-age=31536000; includeSubDomains";
.
- Apache: Add
- Windows:
- IIS: Add
Strict-Transport-Security
headerinyour server configuration. -Windows: Use IIS to include this header underHTTP Response Headers.
- IIS: Add
- Linux:
15. X-Frame-Options
- Impact: Prevents clickjacking attacks by
disablingcontrolling whether a browser should be allowed to render a page in a frame orrestricting iframe embedding of the web page.iframe【9†source】. - Remediation: Set
X-Frame-
toOptions: DENYOptionsprevent any domain from framing your content,DENY
orSAMEORIGIN
toallowcontrolonlyframing,youre.g.,ownX-Frame-Options:
【9†source】.domain.DENY - Installation:
-- Linux:
Include- Apache:
headerAddinHeader
.yoursetserver'sX-Frame-Optionsconfiguration"DENY" - Nginx:
-Useadd_header X-Frame-Options "DENY";
.
thisfiles. - Apache:
- Windows:
Set- IIS: Add
X-Frame-Options
headerinIIS underHTTP Response Headers.
the - IIS: Add
- Linux:
16. X-Permitted-Cross-Domain-Policies
- Impact: Controls which cross-domain policies the browser should allow, reducing
thepotential attacksurface.surfaces【9†source】. - Remediation: Set
X-Permitted-Cross-Domain-Policies
to a strict policy, e.g.,X-Permitted-Cross-Domain-Policies: none
to disallow all cross-domain policies, ormaster-onlyto allow only master policy files.【9†source】. - Installation:
-- Linux:
Configure- Apache:
headerAddinHeader
.yoursetwebX-Permitted-Cross-Domain-Policiesserver."none" - Nginx: Use
add_header X-Permitted-Cross-Domain-Policies "none";
.
this- - Apache:
- Windows:
Use- IIS:
to add theAddX-Permitted-Cross-Domain-Policies
header underin HTTP Response Headers.
- IIS:
- Linux: