HTTPS and security headers
Unit 3 of 5 in Web fundamentals.
You will be able to explain what HTTPS, HSTS and a content security policy each add to a site.
Lesson
HTTPS: HTTP inside TLS
HTTPS is HTTP carried over TLS. TLS gives the connection authentication of the server, confidentiality so that only the two endpoints can read the data, and integrity so that tampering is detected. Without it, anyone on the path can read or change what is sent, including session cookies.
OWASP's TLS guidance covers choosing strong protocols and ciphers, patching cryptographic libraries, and TLS certificate care, which you met in the cryptography class.
HSTS: never try plain HTTP again
Redirecting from HTTP to HTTPS leaves a first request exposed. The Strict-Transport-Security header tells browsers that a host should only be accessed using HTTPS, and that any future attempt to use HTTP should automatically be upgraded to HTTPS. On later connections the browser also will not let a user bypass secure connection errors such as an invalid TLS certificate.
That second sentence matters: it removes the click-through that fools many people.
Content Security Policy: tell the browser what scripts to trust
A Content Security Policy is a series of instructions from a website to a browser that restrict what the code of the site is allowed to do. Its primary use is to control which resources, in particular JavaScript, a document may load, mainly as a defense against cross-site scripting.
OWASP's XSS guidance, covered in the next unit, advises against relying only on a CSP: it is a second layer behind proper output encoding, which fits the defense in depth you learned earlier.
Read the headers a site sends
You can see all of these in a response's headers. A site that sends HSTS, a CSP and secure cookies has done basic hardening; one that sends none has not. The lab for this unit teaches you to check with a single command and to judge what is missing.
Key points
- HTTPS is HTTP over TLS: authentication, confidentiality and integrity.
- HSTS makes browsers refuse plain HTTP and certificate click-throughs for a host.
- CSP limits what scripts a page may load, as a second layer against XSS.
- Check a site's headers with a single command.
Sources
- RFC 8446: The Transport Layer Security (TLS) Protocol Version 1.3
- MDN: Strict-Transport-Security header
- MDN: Content Security Policy (CSP)
- OWASP Transport Layer Security Cheat Sheet
Practice in the labs
Read the headers real sites send, then use a header to turn off browser features you do not need.
- Read a website's HTTP security headers: You pick the security headers out of a response and say in a sentence what each does.
- Restrict browser features with a Permissions-Policy header: You use a header to switch off camera, location and other features a page does not need, least privilege in the browser.
Knowledge check
- What does the HSTS header tell a browser? Answer: Only use HTTPS for this host, and upgrade any HTTP attempts. MDN: HSTS informs browsers that the host should only be accessed using HTTPS and that future HTTP attempts should be upgraded automatically.
- What is a content security policy mainly for? Answer: Controlling which resources, especially scripts, a page may load. MDN: the primary use case for CSP is to control which resources, in particular JavaScript, a document is allowed to load, as a defense against cross-site scripting.
- Which properties does TLS aim to provide? Answer: Authentication, confidentiality and integrity. RFC 8446 lists authentication of the server, confidentiality of data after setup, and integrity.
Back to the syllabus or see all classes.