From ac9159f81188f9d58ef22b4654ac3a68722f1c68 Mon Sep 17 00:00:00 2001 From: Pieter Viljoen Date: Sat, 24 Oct 2026 13:34:04 -0700 Subject: [PATCH] Probe the Family Site's 404 for Its Security Headers The family site answers its 404 from a handle_errors block of its own, and the live check probed only the blog's. A missing .png on the family host now has to answer 404 with the family's headers, at the cost of one more static request in the sampled run. Co-Authored-By: Claude Opus 5.5 --- OPERATIONS.md | 4 ++-- checks/README.md | 4 ++-- checks/check-live-urls.sh | 10 ++++++++++ checks/tests/test_check_live_urls_sample.py | 13 ++++++++++--- 4 files changed, 24 insertions(+), 7 deletions(-) diff --git a/OPERATIONS.md b/OPERATIONS.md index 87ba570..b15a41a 100644 --- a/OPERATIONS.md +++ b/OPERATIONS.md @@ -90,7 +90,7 @@ Sourcing the environment file first puts the deploy root and the base URL in the It refuses to install a release that fails the build gate. `check-live-urls.sh` does take a base URL, which is where the sourced `$SITE_BASE_URL` goes. It follows every URL in the contract against the running mirror, checking each redirect's destination rather than trusting its status code. -Expect a `PASS` naming the number of URLs honored. That is the three lists' combined length, plus the family pages where `SITE_EXTRA_BASE_URL` is set, plus the one missing file that must answer `404`. Every response must also carry the security headers in [`checks/security-headers.txt`](./checks/security-headers.txt) with their exact values. Anything less is a finding, and the output names each URL that failed and what it answered. +Expect a `PASS` naming the number of URLs honored. That is the three lists' combined length plus one missing file that must answer `404`. Where `SITE_EXTRA_BASE_URL` is set, the family pages and a family missing file add to it. Every response must also carry the security headers in [`checks/security-headers.txt`](./checks/security-headers.txt) with their exact values. Anything less is a finding, and the output names each URL that failed and what it answered. A documentation-only or workflow-only change does not need this. A change to the four paths above does, because for those CI's green is not evidence. @@ -129,7 +129,7 @@ The deploy root and the base URL are the only host-specific values. A local run **A VPS release is named by its deploy run, never by a commit.** The hub's deploy task names each release `--` and verifies the site against that id itself. To check a VPS site by hand afterwards, pass that id as `EXPECT_RELEASE`. Read it from the **Deploy site job**'s log, where `make-release.sh` prints `==> installing release ` with the id ending in the run's own id and attempt. The Validate sources job prints the same line earlier in the run, for a scratch bundle stamped with a bare timestamp, so the first match of a log search is the wrong id. Never copy it from the site's `X-Blog-Release` header, since a stale config still serves the previous id and the check would then pass against it. A short SHA never matches, so the check waits out its timeout and fails. -**Production's deploy checks a sample of the contract, and every other run checks all of it.** The production edge bans a client that requests more than 40 distinct pages in a burst. It also bans one when more than 10 distinct pages answer `404`, `403` or `400`. A full run from the GitHub runner therefore gets it banned. The deploy hook sets `SAMPLE_CONTRACT=1` for `production` alone, and the check then requests one URL from each class. That covers each redirect class, each shape of page that must render, each media tree, and the family pages. It also covers `/all/`, `/feed.xml`, and `/sitemap.xml`, the fixed redirect destinations no list names. The script holds that to 30 distinct pages at most, and none is expected to answer an error. Its one `404` is a missing `.png`, which the edge counts as a static request rather than a page. Staging and the local mirrors keep the whole contract, which is where it is proven. **A hand run against the VPS production site sets `SAMPLE_CONTRACT=1` too**, for the same reason the hook does. The local production mirror sits behind no such edge and keeps the whole contract. `checks/check-live-urls.sh --print-sample` lists what a sampled run requests without requesting anything. [`deploy/README.md`](./deploy/README.md#environment-variables) carries the budget. +**Production's deploy checks a sample of the contract, and every other run checks all of it.** The production edge bans a client that requests more than 40 distinct pages in a burst. It also bans one when more than 10 distinct pages answer `404`, `403` or `400`. A full run from the GitHub runner therefore gets it banned. The deploy hook sets `SAMPLE_CONTRACT=1` for `production` alone, and the check then requests one URL from each class. That covers each redirect class, each shape of page that must render, each media tree, and the family pages. It also covers `/all/`, `/feed.xml`, and `/sitemap.xml`, the fixed redirect destinations no list names. The script holds that to 30 distinct pages at most, and none is expected to answer an error. Its `404`s are a missing `.png` on each site, which the edge counts as a static request rather than a page. Staging and the local mirrors keep the whole contract, which is where it is proven. **A hand run against the VPS production site sets `SAMPLE_CONTRACT=1` too**, for the same reason the hook does. The local production mirror sits behind no such edge and keeps the whole contract. `checks/check-live-urls.sh --print-sample` lists what a sampled run requests without requesting anything. [`deploy/README.md`](./deploy/README.md#environment-variables) carries the budget. **A hand run counts as measured through Cloudflare only once every host it reaches prints ` proxied`.** The check prints a verdict for the base host after its preflight and for the family host after its pages. It prints `proxied` only when the response carries `server: cloudflare` with a `cf-ray` header. Right after a hostname flips to proxied, the resolver on the machine running the check can keep answering with the origin for minutes. Another resolver can already answer with Cloudflare by then. A run in that window prints ` UNCONFIRMED`, since it reached the origin directly, so run it again once the resolver catches up. diff --git a/checks/README.md b/checks/README.md index 6491744..fea362c 100644 --- a/checks/README.md +++ b/checks/README.md @@ -109,9 +109,9 @@ wc -l checks/golden-urls.txt checks/redirect-urls.txt checks/golden-media-legacy ## `security-headers.txt`, and why every response's headers are read -`security-headers.txt` holds, per site, each security header `deploy/Caddyfile` sends and its exact value. `check-live-urls.sh` reads it and asserts those headers on every response it requests. That covers the preflight, each page, redirect, followed destination, and media file, the `404` probe, and each family page. A header that goes missing or loses strength fails the run, where a presence check would pass a shortened HSTS lifetime or a loosened policy. +`security-headers.txt` holds, per site, each security header `deploy/Caddyfile` sends and its exact value. `check-live-urls.sh` reads it and asserts those headers on every response it requests. That covers the preflight, each page, redirect, followed destination, and media file, the `404` probes, and each family page. A header that goes missing or loses strength fails the run, where a presence check would pass a shortened HSTS lifetime or a loosened policy. -**One request is added, a missing `.png` under `/media/`.** The `404` answers from the Caddyfile's `handle_errors` block rather than from the route every other request takes, so it is checked on its own. The probe is a static file, so it stays out of the sampled run's page budget. +**One request per site is added, a missing `.png` under `/media/`.** Each site answers its `404` from its own `handle_errors` block rather than from the route other requests take, so each is checked. The probes are static files, so they stay out of the sampled run's page budget. **The values live once here, and a unit case holds them to the Caddyfile.** `checks/tests/test_check_live_urls_sample.py` reads the Caddyfile through `caddy adapt`, so Caddy's own parser decides what each directive covers. It compares every header a site sets on all its responses with this file, in both directions. The cache headers and the site's own markers are left out. It also fails on a security header that reaches fewer responses than all of them. A matcher, a status requirement, an error route, a deletion, or a handler answering first each narrows one. diff --git a/checks/check-live-urls.sh b/checks/check-live-urls.sh index 9d6f5e8..840401e 100755 --- a/checks/check-live-urls.sh +++ b/checks/check-live-urls.sh @@ -193,6 +193,7 @@ if [ -n "$SAMPLE" ]; then SAMPLE_PLAN+=("family"$'\t'"family page"$'\t'"${#FAMILY_PAGES[@]}"$'\t'"${page%%|*}") done SAMPLE_PLAN+=("missing"$'\t'"missing file"$'\t'"1"$'\t'"$MISSING_PROBE") + SAMPLE_PLAN+=("missing"$'\t'"family missing file"$'\t'"1"$'\t'"$MISSING_PROBE") # The budget counts distinct non-static paths per host, which is never less than the edge counts, with the preflight's / among them. # A sampled redirect is not followed, so each costs one path, and a legacy media URL costs two requests, since it takes a hop. @@ -747,6 +748,15 @@ if [ -n "$FAMILY_BASE" ]; then check_headers "family $page_path" "$(<"$FAMILY_HEAD")" "$FAMILY_SECURITY_HEADERS" fi done + # The family site answers its 404 from a handle_errors block of its own. + n_family=$((n_family + 1)) + if ! code=$(curl -q -sS -o /dev/null -D "$FAMILY_HEAD" -w '%{http_code}' --max-time 30 "${family_auth[@]}" "$FAMILY_BASE$MISSING_PROBE?$CACHE_BUST" 2>"$CURLERR"); then + echo "family missing $MISSING_PROBE could not be reached: $(head -1 "$CURLERR")" >>"$FAILED" + elif [ "$code" != "404" ]; then + echo "family missing $MISSING_PROBE expected 404, got $code" >>"$FAILED" + else + check_headers "family missing $MISSING_PROBE" "$(<"$FAMILY_HEAD")" "$FAMILY_SECURITY_HEADERS" + fi [ -s "$FAMILY_HEAD" ] && proxy_verdict "${FAMILY_BASE#*://}" "$(<"$FAMILY_HEAD")" else echo "==> SITE_EXTRA_BASE_URL is unset, so the family site is not checked" diff --git a/checks/tests/test_check_live_urls_sample.py b/checks/tests/test_check_live_urls_sample.py index e9ba75c..32e35c3 100644 --- a/checks/tests/test_check_live_urls_sample.py +++ b/checks/tests/test_check_live_urls_sample.py @@ -121,7 +121,8 @@ def test_render_media_and_family_are_each_sampled(self) -> None: self.assertLessEqual(MEDIA_CLASSES, by_kind["media"]) self.assertEqual(by_kind["family pages"], FAMILY_PAGES) self.assertEqual( - [url for kind, _, _, url in entries if kind == "missing"], [MISSING_PROBE] + {cls: url for kind, cls, _, url in entries if kind == "missing"}, + {"missing file": MISSING_PROBE, "family missing file": MISSING_PROBE}, ) def test_every_sampled_url_comes_from_its_list(self) -> None: @@ -312,7 +313,8 @@ def test_sampled_run_requests_exactly_the_planned_paths(self) -> None: SITE_EXTRA_BASE_URL=family.base, ) requested = list(site.requested) - family_requested = set(family.requested) + family_all = list(family.requested) + family_requested = non_static(family_all) self.assertEqual(result.returncode, 0, result.stdout + result.stderr) self.assertIn("sampled URLs honored", result.stdout) self.assertNotIn(DESTINATION, requested) @@ -322,7 +324,7 @@ def test_sampled_run_requests_exactly_the_planned_paths(self) -> None: self.assertEqual( len(planned) + len(family_requested), budget["distinct non-static paths"] ) - statics = [p for p in requested if p not in non_static(requested)] + statics = [p for p in requested + family_all if p not in non_static([p])] self.assertEqual(len(statics), budget["static requests"]) def test_full_run_is_the_default_and_follows_every_redirect(self) -> None: @@ -545,6 +547,11 @@ def test_a_missing_header_fails_on_every_kind_of_response(self) -> None: result = self.sampled(family=without(csp, "/en/")) self.assertEqual(result.returncode, 1, result.stdout) self.assertIn(f"family /en/ sends {csp} ''", result.stdout) + result = self.sampled(family=without(csp, MISSING_PROBE)) + self.assertEqual(result.returncode, 1, result.stdout) + self.assertIn( + f"family missing {MISSING_PROBE} sends {csp} ''", result.stdout + ) def test_headers_are_asserted_on_the_config_the_reload_converges_on(self) -> None: class Reloading(Handler):