How To Implement Security HTTP Headers To Prevent Vulnerabilities
How To Implement Security HTTP Headers To Prevent Vulnerabilities
- Geekflare
By Chandan Kumar
on January 30, 2020
https://geekflare.com/http-header-implementation/ 1/28
5/22/2020 How to Implement Security HTTP Headers to Prevent Vulnerabilities? - Geekflare
In this article, I will talk about various HTTP Headers to implement in multiple web
servers, network edge & CDN providers for better website protection.
Notes:
You are advised to take a backup of configuration file prior making changes
Some of the headers may not be supported on all the browsers, so check out the
compatibility before the implementation.
Post-implementation, you can use secure headers online tool to verify the results.
Using WordPress?: you may want to try using HTTP Headers plugin, which takes care
of these headers and a lot more.
X-XSS-Protection
X-Frame-Options
X-Content-Type-Options
X-Permitted-Cross-Domain-Policies
Referrer-Policy
Expect-CT
Feature-Policy
1 X-XSS-Protection
https://geekflare.com/http-header-implementation/ 2/28
5/22/2020 How to Implement Security HTTP Headers to Prevent Vulnerabilities? - Geekflare
Google, Facebook, Github use this header, and most of the penetration testing
consultancy will ask you to implement this.
There are four possible ways you can configure this header.
Nginx
Add the following in nginx.conf under http block
https://geekflare.com/http-header-implementation/ 3/28
5/22/2020 How to Implement Security HTTP Headers to Prevent Vulnerabilities? - Geekflare
MaxCDN
If you are using MaxCDN, then adding header is easy and on-the-fly.
Go to Edge Rules >> click “New Rule” and select “Add X-XSS-Protection Header” from
the drop-down.
Microsoft IIS
Open IIS Manager
Before implementing this header, you must ensure all your website page is accessible
over HTTPS else they will be blocked.
HSTS header is supported on all the major latest version of a browser like IE, Firefox,
Opera, Safari, and Chrome. There are three parameters configuration.
Nginx
To configure HSTS in Nginx, add the next entry in nginx.conf under server (SSL) directive
Cloudflare
If you are using Cloudflare, then you can enable HSTS in just a few clicks.
https://geekflare.com/http-header-implementation/ 6/28
5/22/2020 How to Implement Security HTTP Headers to Prevent Vulnerabilities? - Geekflare
https://geekflare.com/http-header-implementation/ 7/28
5/22/2020 How to Implement Security HTTP Headers to Prevent Vulnerabilities? - Geekflare
Select the settings the one you need, and changes will be applied on the fly.
Microsoft IIS
Launch the IIS Manager and add the header by going to “HTTP Response Headers” for
the respective site.
3 X-Frame-Options
Use the X-Frame-Options header to prevent Clickjacking vulnerability on your
website. By implementing this header, you instruct the browser not to embed your web
page in frame/iframe. This has some limitations in browser support, so you got to
check before implementing it.
Frame/iframe of content is
SAMEORIGIN only allowed from the same
site origin.
https://geekflare.com/http-header-implementation/ 8/28
5/22/2020 How to Implement Security HTTP Headers to Prevent Vulnerabilities? - Geekflare
ALLOW-FROM
Allow framing the content only
on a particular URI.
Let’s take a look at how to implement “DENY” so no domain embeds the web page.
Apache
Add the following line in httpd.conf and restart the webserver to verify the results.
Nginx
Add the following in nginx.conf under server directive/block.
F5 LTM
Create an iRule with the following and associated with the respective virtual server.
when HTTP_RESPONSE {
You don’t need to restart anything, changes are reflected in the air.
WordPress
You can get this header implemented through WordPress too. Add the following in a
wp-config.php file
header('X-Frame-Options: DENY);
https://geekflare.com/http-header-implementation/ 9/28
5/22/2020 How to Implement Security HTTP Headers to Prevent Vulnerabilities? - Geekflare
If you are not comfortable editing the file, then you can use a plugin as explained here
or mentioned above.
Microsoft IIS
Add the header by going to “HTTP Response Headers” for the respective site.
4 X-Content-Type-Options
Prevent MIME types security risk by adding this header to your web page’s HTTP
response. Having this header instruct browser to consider files types as defined and
disallow content sni ng. There is only one parameter you got to add “nosni ”.
Apache
You can do this by adding the below line in httpd.conf file
Don’t forget to restart the Apache webserver to get the configuration active.
Nginx
Add the following line in nginx.conf file under server block.
https://geekflare.com/http-header-implementation/ 10/28
5/22/2020 How to Implement Security HTTP Headers to Prevent Vulnerabilities? - Geekflare
Microsoft IIS
Open IIS and go to HTTP Response Headers
You can pin the root certificate public key or immediate certificate. At the time of
writing, HPKP currently works in Firefox and Chrome and support SHA-256 hash
algorithm.
https://geekflare.com/http-header-implementation/ 11/28
5/22/2020 How to Implement Security HTTP Headers to Prevent Vulnerabilities? - Geekflare
optional.
pin-
Specify the pins here
sha256=”sha256key”
This is applicable to a
IncludeSubDomains
subdomain as well.
public-key-pins-report-only:max-age=500; pin-sha256="WoiWRyIOVNa9ihaBciRSC7XHj
If this is something you need to implement on your website, then head to the
implementation guide written by Scott Helme.
All browsers don’t support CSP, so you got to verify before implementing it. There are
three ways you can achieve CSP headers.
If you are still using deprecated one, then you may consider upgrading to the latest
one.
https://geekflare.com/http-header-implementation/ 12/28
5/22/2020 How to Implement Security HTTP Headers to Prevent Vulnerabilities? - Geekflare
There are multiple parameters possible to implement CSP, and you can refer to
OWASP for an idea. However, let’s go through the two most used parameters.
The following example of loading everything from the same origin in various web
servers.
Apache
Get the following added in httpd.conf file and restart the webserver to get e ective.
Nginx
Add the following in the server block in nginx.conf file
Microsoft IIS
Go to HTTP Response Headers for your respective site in IIS Manager and add the
following
https://geekflare.com/http-header-implementation/ 13/28
5/22/2020 How to Implement Security HTTP Headers to Prevent Vulnerabilities? - Geekflare
7 X-Permitted-Cross-Domain-Policies
Using Adobe products like PDF, Flash, etc.? You can implement this header to instruct
the browser how to handle the requests over a cross-domain. By implementing this
header, you restrict loading your site’s assets from other domains to avoid resource
abuse.
Value Description
Apache
If you don’t want to allow any policy.
https://geekflare.com/http-header-implementation/ 14/28
5/22/2020 How to Implement Security HTTP Headers to Prevent Vulnerabilities? - Geekflare
Nginx
And, let’s say you need to implement master-only then add the following in
nginx.conf under server block.
8 Referrer-Policy
https://geekflare.com/http-header-implementation/ 15/28
5/22/2020 How to Implement Security HTTP Headers to Prevent Vulnerabilities? - Geekflare
Looking to control the referrer-policy of your site? There are certain privacy and
security benefits. However, not all the options are supported by all the browsers,
so
review your requirements before the implementation.
Value Description
Referrer
information
will not be
no-referrer
sent with
the
request.
The default
setting
where
referrer is
sent to the
no-referrer-when-
same
downgrade
protocol as
HTTP to
HTTP,
HTTPS to
HTTPS.
send only
when a
strict-origin
protocol is
HTTPS
send the
origin URL
origin
in all the
requests
send FULL
URL on the
same
origin.
origin-when-cross-
However,
origin
send only
origin URL
in other
cases.
Apache
You can add the following if you want to set no-referrer.
And after the restart, you should have in the response headers.
https://geekflare.com/http-header-implementation/ 17/28
5/22/2020 How to Implement Security HTTP Headers to Prevent Vulnerabilities? - Geekflare
Nginx
Let’s say you need to implement same-origin, so you got to add the following.
9 Expect-CT
A new header still in experimental status is to instruct the browser to validate the
connection with web servers for certificate transparency (CT). This project by Google
aims to fix some of the flaws in the SSL/TLS certificate system.
https://geekflare.com/http-header-implementation/ 18/28
5/22/2020 How to Implement Security HTTP Headers to Prevent Vulnerabilities? - Geekflare
max-
In seconds, for how long the browser should cache the policy.
age
report- Browser to send a report to the specified URL when valid certificate
uri transparency not received.
Apache
Let’s assume you want to enforce this policy, report, and cache for 12 hours then you
got to add the following.
Nginx
https://geekflare.com/http-header-implementation/ 19/28
5/22/2020 How to Implement Security HTTP Headers to Prevent Vulnerabilities? - Geekflare
10 Feature-Policy
Control browser’s features such as geolocation, fullscreen, speaker, USB, autoplay,
speaker, vibrate, microphone, payment, vr, etc. to enable or disable within a web
application.
Apache
Let’s say you need to disable the fullscreen feature, and to do so, you can add the
following in httpd.conf or apache2.conf.
https://geekflare.com/http-header-implementation/ 20/28
5/22/2020 How to Implement Security HTTP Headers to Prevent Vulnerabilities? - Geekflare
The above code will instruct the browser to disable fullscreen and microphone.
Nginx
Let’s take another example – disable vibrate feature.
https://geekflare.com/http-header-implementation/ 21/28
5/22/2020 How to Implement Security HTTP Headers to Prevent Vulnerabilities? - Geekflare
All the Nginx configuration goes under http block in nginx.conf or any custom file
you use.
Conclusion
https://geekflare.com/http-header-implementation/ 22/28
5/22/2020 How to Implement Security HTTP Headers to Prevent Vulnerabilities? - Geekflare
READ
READ
https://geekflare.com/http-header-implementation/ 23/28
5/22/2020 How to Implement Security HTTP Headers to Prevent Vulnerabilities? - Geekflare
READ
READ
https://geekflare.com/http-header-implementation/ 24/28
5/22/2020 How to Implement Security HTTP Headers to Prevent Vulnerabilities? - Geekflare
READ
READ
https://geekflare.com/http-header-implementation/ 25/28
5/22/2020 How to Implement Security HTTP Headers to Prevent Vulnerabilities? - Geekflare
yourwebsite.com
Run Audit
Netsparker
Netsparker uses the Proof-Based Scanning™ to automatically verify the identified
vulnerabilities with proof of exploit, thus making it possible to scan thousands of
web applications and generate actionable results within just hours.
Try Netsparker
Kinsta
Probably the best managed WordPress cloud platform to host small to enterprise
sites. Kinsta leverages Google's low latency network infrastructure to deliver
https://geekflare.com/http-header-implementation/ 26/28
5/22/2020 How to Implement Security HTTP Headers to Prevent Vulnerabilities? - Geekflare
content faster. Free SSL, CDN, backup and a lot more with outstanding support.
You'll love it.
Try Kinsta
Sucuri
A global CDN and cloud-based web application firewall for your website to
supercharge the performance and secure from online threats. SUCURI WAF
protects from OWASP top 10 vulnerabilities, brute force, DDoS, malware, and
more.
Try Sucuri
Stay up to date
https://geekflare.com/http-header-implementation/ 27/28
5/22/2020 How to Implement Security HTTP Headers to Prevent Vulnerabilities? - Geekflare
© 2020 · Geekflare
Advertise Authors
Privacy Disclosure
Sitemap
https://geekflare.com/http-header-implementation/ 28/28