Hardening a Static Site That Takes No Input
A static portfolio sounds like the most boring target on the internet: no login, no forms, no database, nothing to inject into. That is exactly why it is a good place to practice doing things properly. This post walks through how this site is locked down and, more importantly, why each control is there.
The threat model
No user input does not mean no attack surface. For a site like this one, the realistic risks are:
- Supply chain. Every third-party script is code I did not write, running in my visitors' browsers.
- Leftovers. Files that were never meant to be public but get deployed anyway.
- Framing and injection. Clickjacking, or a compromised dependency adding markup of its own.
- Platform defaults. Hosting features that are switched on until somebody switches them off.
Step one: delete things
The cheapest security control is deletion. The template this site started from shipped with a build toolchain, a PHP contact form and seventeen JavaScript libraries. The site needed three of them.
What got removed:
- A committed
node_modulesfolder and itspackage.json, both of which were being served to anyone who asked for them. - Two PHP files. The host does not execute PHP, so it was handing them out as plain source code instead.
- Unused libraries: sliders, popups, form validation, and jQuery itself. The home page went from twenty script files to five.
Step two: a Content Security Policy with no exceptions
With the pages down to first-party code only, the policy can afford to be strict: nothing inline, and nothing from any other origin. Even the fonts are served from this site, so a visit here talks to exactly one host.
default-src 'none';
script-src 'self';
style-src 'self';
font-src 'self';
img-src 'self' data:;
base-uri 'none';
form-action 'none';
frame-ancestors 'none';
upgrade-insecure-requests
Getting there meant moving every inline style attribute into a stylesheet and the one inline <script> into a file. There is no 'unsafe-inline' and no 'unsafe-eval' anywhere in the policy.
The rest of the headers
| Header | Value | Why |
|---|---|---|
X-Frame-Options |
DENY |
Nobody gets to frame the site. Backed up by frame-ancestors. |
X-Content-Type-Options |
nosniff |
The browser must trust the declared content type. |
Referrer-Policy |
same-origin |
Other sites do not learn which page you came from. |
Strict-Transport-Security |
max-age=31536000; includeSubDomains |
HTTPS only, remembered for a year. |
Permissions-Policy |
camera=(), microphone=(), geolocation=() and friends |
The site needs no device features, so it gives all of them up. |
Cross-Origin-Opener-Policy |
same-origin |
Windows opened by other sites get no handle on this one. |
Step three: platform defaults
Azure Static Web Apps comes with built-in sign-in endpoints under /.auth/login/. A portfolio has no accounts, so those routes now answer with a 404. Headers and routes live together in one file at the root of the repository (trimmed here for readability):
{
"routes": [
{ "route": "/.auth/login/github", "statusCode": 404 },
{ "route": "/.auth/login/aad", "statusCode": 404 }
],
"globalHeaders": {
"X-Frame-Options": "DENY",
"X-Content-Type-Options": "nosniff"
}
}
Check it yourself
Do not take my word for it. The headers are public:
$ curl -sI https://orbenshimon.com/ | grep -i -E "content-security|x-frame|strict-transport"
And if you find something I missed, there is a security.txt waiting for you.