Skip to content

Assert the Security Headers on Every Response the Live Check Reads - #504

Merged
ptr727 merged 10 commits into
developfrom
feature/assert-security-headers
Oct 24, 2026
Merged

ptr727 merged 10 commits into
developfrom
feature/assert-security-headers

Conversation

@ptr727

@ptr727 ptr727 commented Oct 24, 2026 •

Copy link
Copy Markdown
Owner

Summary

Works issue #500. checks/check-live-urls.sh asserted X-Blog-Env and X-Blog-Release and no security header, so a Caddyfile edit that dropped one passed every gate.

The issue's two design questions were answered in session:

  • Which responses: every response the check already requests, read with curl's %header{} at no extra request: the preflight, each render page, redirect, followed same-origin destination, and media file, plus each family page. One 404 probe is added, a missing /media/live-check-missing.png, since the 404 answers from handle_errors rather than the main route. It counts as a static request (5 of 8) and takes no page path, so the sampled run stays at 30 of 30 pages.
  • What to assert: the exact value. The values live once, in checks/security-headers.txt, and a unit case holds them equal to deploy/Caddyfile in both directions. That case reads the Caddyfile through caddy adapt, in the image checks/caddy/Dockerfile pins, run with networking off. A security header that a matcher, a status requirement, an error route, a deletion, a route group, or an earlier responder narrows is refused. Dependabot's new docker entries track the image pin on both branches.

The issue's comment is folded in too. The check prints <host> proxied or <host> UNCONFIRMED for the base host after its preflight and for the family host after its pages, and the hand probe in OPERATIONS.md "Deploying" is replaced by a pointer to that line.

Other changes:

  • The EXPECT_RELEASE wait refreshes the whole preflight dump, so the headers are asserted on the converged config rather than the pre-reload one.
  • One header_value reader replaces the inline grep | tr | sed copies.
  • deploy/README.md names the curl 7.84 floor %header{} needs. The ubuntu-24.04 runner has 8.5.

Verification

  • python3 -m unittest discover -s checks/tests: the whole suite passes. New cases cover the Caddyfile sync through caddy adapt with each narrowing shape both ways, a missing header on each response kind and on a family page, a weakened HSTS value, a followed destination, a reload that converges after a stale first answer, and the proxied verdict both ways. Each new live-check case was shown failing with the check mutated out or against the pre-fix script.
  • Full contract against the local staging mirror: PASS - 1295 URLs honored, both hosts UNCONFIRMED as expected for a DNS-only mirror.
  • shellcheck, shfmt, ruff, mypy --strict, pyright, markdownlint, and the prose gate (--allow-comments, plus sentence-length) are clean on the diff. The added comments each carry a reason, so this PR carries the comments label.

Local strict review

Frontier-tier passes ran before each push. They fixed the pre-reload preflight dump, the duplicate header reader, the unchecked followed destination, an off-site media hop, the two read paths disagreeing on a repeated header, and the missing curl floor. The Caddyfile reader went through a line regex and a nesting-aware tokenizer before the maintainer chose Caddy's own parser in a container, which also closes the review thread on path- and block-scoped directives. Every finding an earlier version of this body listed as open is fixed on the branch: deferred writes count as scoped, encode, rewrite, and templates pass through, and a matched error route repeating a site-wide value is accepted. A deletion of an unasserted header such as -Server is no longer refused. The 404 probe is listed by --print-sample, a failed image build reports Docker's error, and the 404 probe and the render check share one check_status helper. The final pass over the head raised no findings.

Declined with evidence

  • Repeated header read two ways: curl's %header{} printed only the first copy when curl 8.14 was sent two differing copies, which matches the dump reader's head -n 1, so both paths give one verdict.
  • curl before 7.84: no deployment reaches it. The ubuntu-24.04 runner has 8.5, the maintainer's host 8.14, and deploy/README.md states the floor.

Dropped findings

  • checks/tests/test_check_live_urls_sample.py test_each_redirect_destination_is_a_fixed_caddyfile_target, consolidation on text this change did not touch: it still reads redirects with a regex where adapt could supply them.

🤖 Generated with Claude Code

ptr727 and others added 3 commits October 24, 2026 10:04
The live check read no security header, so a Caddyfile edit that dropped
one passed every gate. Each response it already requests now carries the
exact values in checks/security-headers.txt, which a unit case holds to
the Caddyfile. One missing .png probes the handle_errors route, at the
cost of a static request rather than a page.

The preflight and the family pages also print whether the run reached
the Cloudflare edge, which replaces the hand probe in OPERATIONS.md.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
The preflight assertion read the dump taken before the release wait, so a
release that changed a header value failed against the previous config.
The wait now refreshes the whole dump. A same-origin redirect destination
is header-checked too, one header_value reader replaces the copies, and
the Caddyfile test reads a bare value as well as a quoted one.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
A media hop to another host is no longer held to this site's list, a
repeated header reads as its first instance on both read paths, as curl's
%header{} does, and a matcher-scoped security header in the Caddyfile
fails the sync test rather than being demanded on every response. The
curl row in deploy/README.md names the 7.84 floor %header{} needs.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Copilot AI lite review requested due to automatic review settings October 24, 2026 17:29
@coderabbitai

coderabbitai Bot commented Oct 24, 2026 •

Copy link
Copy Markdown

Important

  • 🔍 Trigger review

This repository does not receive automatic reviews because it has fewer than 10 stars.

Run configuration
  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: Organization UI
  • Review profile: ASSERTIVE
  • Plan: Advanced
  • Run ID: 7fb61488-d73b-4a91-8f09-1ce31d9a110b
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@ptr727 ptr727 added the comments Permits the comment lines the pull request adds or edits, which the prose gate otherwise refuses label Oct 24, 2026
@ptr727

ptr727 commented Oct 24, 2026

Copy link
Copy Markdown
Owner Author

A recorded local strict-review pass covers head c9b4ecc70700f1e32721cdef355f15c857d6d776, the content this pull request carries at that commit against develop, and it recorded 2 findings.

@codecov

codecov Bot commented Oct 24, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 49.70%. Comparing base (64b8793) to head (554bf93).

Additional details and impacted files
@@           Coverage Diff            @@
##           develop     #504   +/-   ##
========================================
  Coverage    49.70%   49.70%           
========================================
  Files           10       10           
  Lines         3058     3058           
========================================
  Hits          1520     1520           
  Misses        1538     1538           
Flag Coverage Δ
python-3.13 49.70% <ø> (ø)

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 Changes recommended

The Caddyfile parity test does not safely reject path- or block-scoped header directives, and the printed sample omits the 404 probe.

1 open issue
What changed in this PR

This pull request strengthens the live URL check by validating exact security headers across blog, family, redirect, media, and 404 responses, while synchronizing expected values with the Caddyfile.

Changes:

  • Adds shared security-header expectations and Caddyfile synchronization tests.
  • Extends check-live-urls.sh with header validation, a missing-media 404 probe, reload-convergence handling, and proxy verdict output.
  • Updates operational and deployment documentation, including the curl version requirement.
File Description
OPERATIONS.md Documents security-header validation, the 404 probe, and proxy verdict output.
deploy/​README.md Documents the curl version requirement and header-value synchronization contract.
checks/​tests/​test_check_live_urls_sample.py Adds live-check, Caddyfile synchronization, and proxy-verdict tests.
checks/​security-headers.txt Defines expected security headers and exact values for both sites.
checks/​README.md Documents the security-header contract and missing-file coverage.
checks/​check-live-urls.sh Reads and validates headers across live responses and adds the 404 probe.

Review effort: Lite

ptr727 and others added 3 commits October 24, 2026 10:36
The sync case read each line alone, so a path matcher was skipped and a
header inside a matcher-scoped block read as site-wide, and it reached
only an allowlist of names. It now tokenizes each line, tracks the block
a header sits in, reads every header a site sets on all responses apart
from its cache headers and markers, and refuses any other header scoped
to fewer responses.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Each review round found another directive form the hand-written reader
misread: path matchers, matcher-scoped blocks, status requirements,
scoped deletions. The sync case now runs caddy adapt in a pinned image,
offline, and walks the JSON, where a matcher, a require, an error route,
or a delete is explicit. Dependabot tracks the image pin.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
A header in one of several mutually exclusive handle routes, or behind a
handler that answers first, read as site-wide. Both now count as scoped.
An error route repeating a value every response already carries is no
longer refused.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@ptr727

ptr727 commented Oct 24, 2026

Copy link
Copy Markdown
Owner Author

A recorded local strict-review pass covers head cd8ffed3b755f85fb25930fbec5b39a1cd964a5d, the content this pull request carries at that commit against develop, and it recorded 4 findings.

ptr727 and others added 3 commits October 24, 2026 11:48
A deferred header write misses error responses, so it now counts as
scoped. A header after encode, rewrite, or templates still reaches every
response, and an error route with its own matcher that repeats a
site-wide value narrows nothing, so neither is refused any longer.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Removing a header the site never sets on every response, such as Server,
narrows nothing the live check asserts, so the sync case no longer
refuses it. Deleting a site-wide security header on some responses is
still refused, in the main routes and in an error route.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
--print-sample counted the probe in its static budget without listing
it, so the listing and the budget could not be reconciled. It is now a
plan row like any other request. A failed build of the Caddy image
reports Docker's own output rather than a bare exit status.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@ptr727

ptr727 commented Oct 24, 2026

Copy link
Copy Markdown
Owner Author

A recorded local strict-review pass covers head 21e898bbeae18fd8875c5ccbca349f34aaed771b, the content this pull request carries at that commit against develop, and it recorded 1 finding.

The 404 probe repeated check_render step for step. Both now call
check_status with a label, the expected status, and the URL.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@ptr727

ptr727 commented Oct 24, 2026

Copy link
Copy Markdown
Owner Author

A recorded local strict-review pass covers head 554bf9340d7442ff063c663f277f1d3e4996f3ba, the content this pull request carries at that commit against develop, and it recorded 0 findings.

@ptr727
ptr727 merged commit 2c450a5 into develop Oct 24, 2026
12 checks passed
@ptr727
ptr727 deleted the feature/assert-security-headers branch October 24, 2026 19:53
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

comments Permits the comment lines the pull request adds or edits, which the prose gate otherwise refuses

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants