Challenge - Security package
Write a secure page with CSP, referrer policy and noopener.
Security header package
The core HTML layer of web security has three pieces. <meta http-equiv="Content-Security-Policy" content="..."> declares external resource restrictions; it limits which scripts and styles may load. <meta name="referrer" content="..."> controls the referrer information sent with outbound links.
When outbound links use target="_blank", add rel="noopener noreferrer"; this prevents the new tab from reaching the opener object and modifying the page, and keeps the referrer private. Together these form a small but consistent security baseline.
Exercise Write the security package
Write a secure page skeleton. In head add a charset meta (charset="utf-8"), a viewport meta (name="viewport"), a CSP meta (http-equiv="Content-Security-Policy"), and a referrer meta (name="referrer"). In body place an external link that opens with target="_blank" and includes rel="noopener noreferrer".
Show example solution
head has four metas, body has one safe external link.
Example solution:
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="Content-Security-Policy" content="default-src 'self'">
<meta name="referrer" content="no-referrer">
<title>Secure Page</title>
</head>
<body>
<a href="https://site.example" target="_blank" rel="noopener noreferrer">External link</a>
</body>
Test yourself
-
Which meta tag declares CSP?
- <meta name="csp" content="...">
- <meta http-equiv="Content-Security-Policy" content="...">
- <meta charset="csp">
- <meta rel="csp">
Show answer
<meta http-equiv="Content-Security-Policy" content="..."> — Correct. CSP is declared with http-equiv="Content-Security-Policy".
-
Make the external link safe
<a href="https://site.example" target="_blank" ____>External link</a>Show answer
<a href="https://site.example" target="_blank" rel="noopener noreferrer">External link</a> -
Match the security concepts
- Content-Security-Policy
- External resource limits
- name="referrer"
- Referrer information limit
- noopener
- Blocks opener access
- noreferrer
- Hides referrer information
-
What should be added to secure a target="_blank" link?
- Only rel="noopener" is enough
- The crossorigin attribute
- The download attribute
- rel="noopener noreferrer"
Show answer
rel="noopener noreferrer" — Correct. noopener cuts opener access, noreferrer cuts the referrer together.