HTTP Security Headers
---
Overview
- HTTP Security Headers
- The Headers
- Demo: configure!
- Questions
---
HTTP Security Headers
----
## HTTP Header
- Metadata = Communication between server & client
- HTTP Status - HTTP Version, Status Code (200 success, 404 not found)
- General Headers - date, cache-control
- Request Headers - User-Agent, Cookie
- Response Headers - Server, Content-Type
- Entity Headers - Content-Encoding, Content-Language, Last-Modified
- Security Headers - [in this presentation]
- Custom Headers - password: Open sesame
----
### How to see HTTP Headers
Use Google Chrome >
Inspect >
Network >
click "your HTML page" >
Headers
----
## HTTP Security Headers
----
### HTTP Security Headers (HSH) - Where?
- Server configuration
- .htaccess
- PHP
- HTML (only CSP)
- Joomla core plugin
----
### HSH - Server configuration
in Nginx
```txt
add_header X-Content-Security-Level "topsecret" always;
```
----
### HSH - .htaccess
```txt
Header set X-Content-Security-Level "topsecret"
```
----
### HSH - PHP
```php
header('X-Content-Security-Level: topsecret');
```
### HSH - HTML
Only CSP...
```html
```
----
### HSH - Joomla core plugin
System > Plugins > System - HTTP Headers
---
The Headers
----
### The HTTP Security Headers
- X-Frame-Options
- Referrer-Policy
- X-Content-Type-Options
- Permissions-Policy
- Strict-Transport-Security
- Content-Security-Policy
- Cross-Origin Resource Sharing (CORS)
---
X-Frame-Options
----
## X-Frame-Options - Issue
- Your nice website
- is loaded on other website in an iframe
- with invisible layer on top
- visitor tries to click button original website...
----
## X-Frame-Options - Issue
- Clickjacking
- Malicious website displays transparent iframe
over a legitimate webpage
- tricking the user into clicking on elements
of the hidden page
----
## X-Frame-Options - Solution
- Do not allow your website
to be loaded via iframe
- "x-frame-options: SAMEORIGIN"
---
Referrer-Policy
----
## Referrer-Policy - Issue
- Your nice website
- links to external website
- visitor clicks on link to external website
- external website knows where visitor came from...
----
## Referrer-Policy - Issue
- Your visitor clicks on a hyperlink to another site
- browser communicates where you come from to new site (via referrer in HTTP header)
- Issue: your website https, target website http = "downgrade" of the connection for the visitor
----
## Referrer-Policy - Solution
- Disable referrer
- "Referrer Policy: no-referrer-when-downgrade"
---
Cross-Origin-Opener-Policy
----
### Cross-Origin-Opener-Policy (COOP)
Issue
- Visitor visits your nice website
- in a second tab they open another website
- the second website might have code
- that influences the first tab...
----
### Cross-Origin-Opener-Policy (COOP)
Solution
- Instructs browser to restrict conditions
how new browsing context (new window or tab) can be created or interacted with
- "Cross-Origin-Opener-Policy: same-origin"
---
X-Content-Type-Options
----
### X-Content-Type-Options - Issue
- A visitor on your nice website
- uploads an example.png file
- that contains JavaScript
- visitor 2 opens page with example.png
- the browser loads that example.png
- sees the file as JavaScript and executes it
----
### X-Content-Type-Options - Solution
- Disable content determination via MIME
- "X-Content-Type-Options: nosniff"
---
Permissions-Policy
----
## Permissions-Policy - Issue
- your nice website
- loads other website in iframe
- your visitor gets access camera request
- thinks it's yours and allowes it
- other website has access to camera
----
### Permissions-Policy - Solution
- configure which features are allowed to be used
- by website, frames, or iframe embedded content
- (formerly known as Feature Policy)
- Permissions-Policy: accelerometer=(), camera=(), geolocation=(), gyroscope=(), magnetometer=(), microphone=(), payment=(), usb=()
---
Strict-Transport-Security
----
### Strict-Transport-Security - Issue
- your nice website
- always uses https
- hence, the connection is encrypted
- one day, https changed to http
- because of a Man-(or Female)-in-the-Middle attack
- the communication of form input not safe
----
### Strict-Transport-Security - Issue
- Traffic to your site is protected via SSL/TLS (https)
- Due to some technical difficulty, the website is served without SSL/TLS (as http)
- The returning visitor expects https and submits a form with personal details
----
#### Strict-Transport-Security - Solution
- Be strict and enforce https
- Deny the returning visitor's browser to use http
- strict-transport-security: max-age=15768000 (convert all HTTP requests on this
website to HTTPS in the next 6 months)
---
Content-Security-Policy
----
### Content-Security-Policy - Issue
- your nice website
- has an old 3rd party comments extension
- which has a vulnerability
- a bad visitor adds comment
- with malicious JavaScript
- another visitor reads the comment
- and browser automatically executes the JavaScript
----
### Content-Security-Policy - Solution
- Be strict
- specify what internal/external sources you allow
- like Javascript, CSS, images etc
- Content-Security-Policy: default-src 'self'; script-src 'self'
'unsafe-inline' stats.db8.nl/matomo.js; style-src 'self' 'unsafe-inline'; connect-src 'self' stats.db8.nl/matomo.php; img-src 'self'
data: https://i.ytimg.com; base-uri 'self'; form-action 'self'; style-src-attr 'self' 'unsafe-inline'; style-src-elem 'self'
'unsafe-inline'; frame-src 'self' www.youtube.com
----
### Content-Security-Policy - Solution
- script-src - JavaScript
- 'self' - from website itself (using same scheme, host, and port)
- 'unsafe-inline' (not the most secure!) - permits inline JavaScript and event-handling HTML attributes (like onclick)
- example.com/matomo.js explicitly allows loading the JavaScript file matomo.js from example.com
----
### Content-Security-Policy -
"nonce" and "script hashes"
- Nonce (number used once) - unique token generated by server for each HTTP response
- Content-Security-Policy: script-src 'nonce-YourUniqueNonceValue';
- or inline JS:
< script nonce="YourUniqueNonceValue">
// Your inline script here
< /script >
- Script Hashes - allow script to execute if content matches cryptographic hash specified in CSP
- Content-Security-Policy: script-src 'sha256-abc123';
----
### Content-Security-Policy -
How to config?
- Switch on CSP with "Report Only"
- Use Google Chrome > Inspect > Console
- Check and solve errors
- Take extra care: CAPTCHA, Youtube videos, Google Maps/OpenStreetMap, etc
---
Cross-Origin Resource Sharing (CORS)
----
### Cross-Origin Resource Sharing - Issue
- your nice website
- a registered user is logged in
- did not log out and visits malicious website
- malicious website posts form to your website
- together with session cookie of registered user
----
### Cross-Origin Resource Sharing
- same-origin policy = too strict for access to resources
(like fonts, APIs, or scripts) hosted on different domains
- CORS = safely relax this policy under controlled conditions
- In Global Configuration: Server > Web Services > Enable CORS
---
Demo time!
---
Questions?
----
## Photo Credits
- https://unsplash.com/photos/lines-of-html-codes-4hbJ-eymZ1o
- https://unsplash.com/photos/boy-standing-near-dock-lVCHfXn3VME
- https://pixabay.com/photos/notebook-paper-pages-open-731212/
- https://unsplash.com/photos/lines-of-html-codes-4hbJ-eymZ1o
- https://unsplash.com/photos/guard-standing-near-brown-wall-qTLyiHW1nIc
- https://unsplash.com/photos/person-hand-holding-photo-frame-3_Xwxya43hE
- https://unsplash.com/photos/person-using-laptop-FlPc9_VocJ4
- https://unsplash.com/photos/gray-bottle-opener-beside-opened-bottle-voJB2goG0us
- https://unsplash.com/photos/woman-smelling-bouquet-of-purple-lavender-Wv9Bn8te3as
- https://unsplash.com/photos/no-drones-signage-on-brown-wooden-post-across-mountain-with-fogs-oMqswmrie4Y
- https://unsplash.com/photos/box-truck-passing-through-toll-gate-Pj6TgpS_Vt4
- https://unsplash.com/photos/time-lapse-photography-of-square-containers-at-night-ahi73ZN5P0Y
- https://unsplash.com/photos/pizza-on-white-ceramic-plate-WcV2YkM3Dls
- https://app.leonardo.ai/image-generation
- https://unsplash.com/photos/question-mark-neon-signage-8xAA0f9yQnE