Skip to content

Serve Every Page's Resources From the Site Itself, and Fail the Build Otherwise #529

Closed

Description

@ptr727

Summary

Every resource a page loads should come from the site itself. Nothing enforces that today. 95 images on eight archived posts were hotlinked from hosts that no longer served them, and no check noticed. They came to light only when #501 surveyed every origin the site loads for the Content-Security-Policy. #513 restores them under each post's own media. This issue makes "served locally" a build gate, so the next off-site reference fails CI instead of waiting for someone to notice a broken page.

Why nothing caught the dead images

  • The migration's localize step looked for two hosts only. capture/localize-external.py matched ggpht.com and googleusercontent.com. The docs.google.com/File?id= images and the elcolighting.com image were outside its pattern, so it neither fetched them nor reported skipping them.
  • The parity gate checks local references only. check-url-parity.py proves every /media/ and /external/ reference resolves. An absolute URL on another host is not a local reference, so it is never examined.
  • The CSP build gate does not cover images, styles, or fonts. check-csp-scripts.py checks scripts, frames, media, and objects against the policy. Once Enforce a Blog Content-Security-Policy Behind a Script Hash Gate #514 set img-src 'self', only the hand-run check-csp-browser.py saw the blocked images, and they went onto its allow list as known exceptions.
  • No gate fetches an off-site URL, by design, so a dead one and a live one look the same to the build.

What still loads from elsewhere

A scan of the built HTML and CSS on the #513 branch finds one remaining source, Google Fonts, on every page of both sites:

  • Blog. layouts/_partials/extend_head.html loads Lexend 400 from fonts.googleapis.com, which serves the font files from fonts.gstatic.com.
  • Family site. Both pages load Cormorant Garamond (500, 600, 700, 500 italic) and EB Garamond (400, 500, 400 italic) the same way. sites/viljoen.family/README.md already lists self-hosting under "Ideas Not Yet Done".

Decided, 2026-10-25: both sites self-host their fonts. The fonts are under the SIL Open Font License, which permits redistribution and self-hosting as long as the license travels with the files. Browsers have partitioned their HTTP caches by site since about 2020, so a shared Google CDN copy no longer saves a reader anything. Each page view to Google also sends the reader's IP address and referrer to a third party. Self-hosting removes both Google hosts from both policies.

Work

  1. Self-host the fonts, as its own pull request. Serve woff2 files for each family and weight in use, with each font's OFL.txt, from the site's own tree. Cover the Latin and Latin Extended ranges the English and Afrikaans text needs. Replace the Google <link> and preconnect lines with local @font-face rules. Tighten both policies in checks/security-headers.txt and deploy/Caddyfile to style-src 'self' 'unsafe-inline' and font-src 'self', and drop the family policy's Google connect-src hosts. Run the CSP browser check on both sites before the pull request opens.
  2. Fail the build on any subresource from another origin, in the release build that CI runs. Cover the built HTML and CSS of both sites: img src and srcset, picture source, video, audio, and track sources and posters, script, iframe, embed, object, link with a loading rel (stylesheet, icon, preload, modulepreload, manifest, preconnect), style attributes, <style> blocks, and CSS url() and @import. A plain <a href> to another site stays allowed, since it loads nothing. Extending check-csp-scripts.py to img-src, style-src, and font-src is one way to do this, and a separate check is another. With the fonts local, the gate needs no exception list.

Done

Every page on both sites loads only from its own origin, both policies name no other host, and the release build fails when a change adds anything served from elsewhere.

🤖 Generated with Claude Code

Activity

  1. added
    enhancement
    on Oct 25, 2026
  2. ptr727 commented on Oct 25, 2026

    @ptr727
    OwnerAuthor

    Decided, 2026-10-25: the gate extends the CSP gate. checks/check-csp-scripts.py becomes checks/check-csp.py. It checks every fetch a page makes on both sites, against each site's own policy: images and srcset, link loads, CSS url() and @import, style attributes, and fonts. It also fails where either policy names a host. One scanner then reads the pages, and each policy is the one statement of what a site may load. The alternative was a separate local-only check, which would have repeated the HTML scan the CSP gate already does.

    Step 1, the self-hosted fonts, is #531.

    🤖 Generated with Claude Code

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancement

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions