Skip to content

Instantly share code, notes, and snippets.

@apolloclark
Last active April 5, 2024 12:52
Show Gist options
  • Save apolloclark/1dde8de984afeef44fd4ac4563f3a587 to your computer and use it in GitHub Desktop.
Save apolloclark/1dde8de984afeef44fd4ac4563f3a587 to your computer and use it in GitHub Desktop.

HTTP Security Headers

Overview

HTTP Security Headers do not prevent server-side attacks, but they do help mitigate some client-side attacks, within browsers that support the headers.

Set-Cookie

Instructs the browsers when and how to set cookies. It helps to prevent man-in-the-middle (MitM) attacks, Cross Site Request Forgery (CSRF), session hijacking, and session fixation.

Example

Set-Cookie: Secure, SameSite

Vulnerability

Documentation

Browser Support

Referrer-Policy

Instructs browsers when to set the Referrer Header during requests. This helps prevent referrer spoofing, and information disclosure.

Example

Referrer-Policy: strict-origin

Vulnerability

Documentation

Browser Support

Cross-Origin Resource Sharing (CORS)

Prevents browsers from sending AJAX requests to unapproved domains, preventing XSS and Cross-Site Request Forgery (CSRF).

Example

Access-Control-Allow-Origin: https://www.example.com

Vulnerability

Documentation

Browser Support

X-Frame-Options

This helps prevent "click-jacking," where a webpage is embedded into an IFRAME on another attacker controlled website, and tricks the user into clicking. This header lets the owner of the website decide which sites are allowed to iframe their webpages.

Example

X-Frame-Options: SAMEORIGIN

Vulnerability

Documentation

Browser Support

X-XSS-Protection

This will enable browser XSS protection.

Example

X-XSS-Protection: 1; mode=block

Vulnerability

Documentation

Browser Support

X-Content-Type-Options

This helps mitigate a "content sniffing" attack, where an attacker will claim to be sending a non-malicious filetype such as an image, but then send malicious javascript to perform Cross Site Scripting (XSS).

Example

X-Content-Type-Options: nosniff

Vulnerability

Documentation

Browser Support

Content-Security-Policy

Mitigate Cross Site Scripting (XSS) attacks, by whitelisting allowed local and remote source of javascript, css, images, video, and other files.

Example

Content-Security-Policy: default-src 'self'

Documentation

Browser support

HTTP Strict Transport Security (HSTS)

Prevents web browsers from accessing a website over HTTP, and helps prevent SSL downgrade attacks. This also helps prevent the browser from allowing the user to overriding SSL certificate warnings.

Example

Strict-Transport-Security: max-age=31536000; 

Vulnerability

Documentation

Browser Support

HTTP Public Key Pinng (HPKP)

Prevents web browsers from using forged X.509 cerficiates, by caching the certificate after initially receiving it. This is only secure, assuming the user's first visit is secure.

"Public-Key-Pins-Report-Only" is the best option, as it will instruct the web browser to report to the web server whenever a certificate does not match the initially cached certificate, but the browser will not block access.

Example

public-key-pins-report-only:
  max-age=500;
  pin-sha256="WoiWRyIOVNa9ihaBciRSC7XHjliYS9VwUGOIud4PB18=";
  pin-sha256="r/mIkG3eEpVdm+u/ko/cwxzOMo1bk4TyHIlByibiA5E=";
  pin-sha256="q4PO2G2cbkZhZ82+JgmRUyGMoAeozA+BSXVXQWB8XWQ=";
  report-uri=http://reports.fb.com/hpkp/

Vulnerability

Documentation

Browser Support

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment