Repository navigation
fix(pages): the Pages site loads nothing from a third-party host (#272) - #273
Merged
Merged
Conversation
…livr.net (#272) Every docs page with a diagram loaded https://cdn.jsdelivr.net/npm/mermaid@11/dist/mermaid.min.js, an unpinned major version from a CDN that received each visitor's IP address on page load (measured on the live site, engine#272). The build now copies the bundle of the mermaid devDependency, the version package-lock.json pins (11.16.1), to docs-site/assets/mermaid.min.js, and the pages load it by a relative path, so it resolves under the /learn-content-engine/docs/ sub-path the site is served from. docs-site/ now holds a JavaScript file, and ESLint 9 does not read .gitignore: after a local docs build, 'npm run lint' linted the minified bundle (9329 errors). docs-site/** joins docs-api/** in the ignores. Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
…not remote images (#272) TypeDoc renders README.md into /api/index.html, and with it the npm and CI badges: on the Pages site the visitor's browser fetched them from img.shields.io and github.com on every visit (measured on the live site, engine#272). On github.com and npmjs.com the same images load through the platform's image proxy, so only the Pages copy leaked the IP address. A local TypeDoc plugin, registered in typedoc.json, listens to MarkdownEvent.PARSE below TypeDoc's own Markdown renderer and replaces each remote <img> (absolute http(s) or protocol-relative source) with its alt text. "npm version" and "CI" stay links to the same targets; images the site serves itself stay untouched. The README keeps its badges for GitHub and npm. Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
) Nothing checked what the Pages site loads: the Mermaid CDN script and the remote badges reached the live site with every gate green, and pages.yml runs only on main. Now: - scripts/check-external-hosts.mjs scans an assembled site for resources the browser fetches from another host: fetching <link> rels, script, img, iframe and media src and srcset, <object data>, meta refresh, CSS url() and @import, service worker and web manifest entries. Hyperlinks, rel=canonical/alternate, other meta content, JSON-LD and string constants in JS bundles are not findings. Exit 1 on a finding, 2 when the run proves nothing (no directory, no HTML page in it). - npm run docs:pages assembles _site exactly as pages.yml did (docs-api to api, docs-site to docs, schema/*.json to schema, the landing page). pages.yml and ci.yml both run it and then npm run docs:pages:check, so the deploy and every pull request scan the same site. make pages-check runs both locally. The rules are a port of bibliogon's scripts/check_external_hosts.py (bibliogon#874), not a new design. Why a port instead of the original: it is a repository script, not a published package, so using it means copying it or fetching another repository's main at CI time; the engine's gates are Node scripts tested with Vitest, and pages.yml has no Python step (ci.yml installs Python only for the shipped validator helper and the prose gate). Differences: jsdom parses the HTML (the original uses html.parser), the --sources mode for a Vite frontend has no counterpart here, and the floor rule of engine#93 is added: the original passes on an empty or missing directory. The TypeDoc plugin now takes its definition of a remote URL from the same module as the gate (scripts/remote-url.mjs), so the two agree; a module of its own keeps jsdom out of every TypeDoc run. Measured: the gate finds the 6 references of engine#272 (3 hosts) in the site assembled from main, and none in the site assembled from this branch (133 HTML pages, 2 stylesheets). Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
…heck in CONTRIBUTING (#272) The Unreleased section records what the live site loaded from other hosts (measured 2026-10-20), the three changes and the gate; CONTRIBUTING lists the new make target next to the other useful targets. Docs audit per .claude/rules/release.md: README.md, CONTRIBUTING.md, docs/*.md, docs/blog/*.md (EN and DE) and docs/proposals/*.md searched for pages, docs-site, jsdelivr, mermaid, CDN, shields, badge, TypeDoc and the workflow and npm script names. No doc described the Pages build or claimed anything the change breaks; the README keeps its badges, which load through the GitHub and npm image proxies there. The module docstrings of the touched scripts were updated in their commits. Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
#272) The scanner, ported unchanged from bibliogon, passed nine kinds of page that make the browser fetch from another host (astrapi69/bibliogon#1124). It reads them now. Each has its own test with the page seeded for that issue as the fixture (src/__fixtures__/external-hosts/, byte for byte), and each test was red before the fix: - a CSS url() in a style attribute, <video poster>, <input type=image src>; - SVG <image href> (also xlink:href, and feImage, use and script); - <link rel=preload imagesrcset>; <iframe srcdoc>, parsed as a page; - references resolved as the browser resolves them: against a <base href> on another host, and by the URL standard, so \\host\x.js is //host/x.js; - the text of every <script>: import and export from, import(), importScripts(), new Worker() and new SharedWorker() with a string literal, and import map entries; CSS and JavaScript escapes resolved. The control, a <script src> from a CDN, still fails; hyperlinks still pass, an SVG <a> and a relative link under a foreign base included. Each variant in the tests was loaded in Chromium first and fetched, except a cross-origin worker, which Chromium refuses before any request (that finding is conservative). 25 seeded mutations of the rules each turn at least one test red. remote-url.mjs resolves by the URL standard now instead of a prefix test, so the TypeDoc plugin also reads a backslash source as remote. The module docstring names bibliogon#1124 as the reason this scanner is a copy, lists what it reads and what it cannot see (a request JavaScript makes at runtime), and no longer refers to a runtime capture this repository does not have. Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
…#272) The docs site serves mermaid.min.js itself since this branch's first commit, and the bundle does not carry Mermaid's own notice (its licence blocks cover lodash-es, DOMPurify, js-yaml and cytoscape only), while the MIT licence asks for the notice in every copy. npm run docs:site now copies node_modules/mermaid/LICENSE to assets/mermaid.min.js.LICENSE.txt, next to the bundle (/docs/assets/ on the site): named after the bundle as bundlers name an extracted licence, and .txt so GitHub Pages serves it as text/plain instead of a download. The test, red first, checks that the build writes it byte-identical to the installed package's LICENSE. Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
As bare alt text, the README's npm and CI badges on /api/ rendered as two adjacent links, "npm version" and "CI", that read as one: "npm version CI". The local TypeDoc plugin now puts a remote image's alt text in brackets, so /api/ shows "[npm version] [CI]", two links to the same targets as before. The brackets stand where the badge's box stood, which also keeps an image inside a sentence recognisable as one. A remote image with empty or blank alt text is still dropped. Tests, red first: the rendered markup, and the visible text with the tags stripped is "[npm version] [CI]". Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
The gate's own words promised more than a file scan can see. Its OK line said "no third-party resource fetch", and the module and test texts said the site "loads nothing from another host". The scan reads files for the forms external-hosts-lib.mjs lists and runs no JavaScript, so a request a script makes at runtime is outside it. - check-external-hosts.mjs: the OK line reads "no third-party reference in <dir> (N file(s) read, M HTML page(s))" and adds which forms are read and that no JavaScript is run; a failure counts "third-party reference(s)", since some findings are conservative (a cross-origin worker, an import map entry). Tests updated first. - Docstrings: the CLI names the forms list and bibliogon#1124; docs-site and build-docs-site say that no page loads Mermaid from another host, which is what they decide, not that the site loads nothing from one. - Test names in external-hosts.test.ts and docs-site.test.ts say what the gate checked. Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
… the host gate reads (#272) They said the gate fails on "any resource from another host" and that the site "loads nothing from" one. The gate reads the site's HTML, CSS, web manifests and service workers for the forms external-hosts-lib.mjs lists, and it runs no JavaScript. The texts say that now: - CHANGELOG [Unreleased]: the gate bullet names what it reads, says that a request a script makes at runtime is outside it, and that the rules are a copy until astrapi69/bibliogon#1124. The after-measurement is dated (a browser capture of all 133 pages, no request to another host, 2026-10-20), and the Mermaid licence file and the bracketed badge links are recorded. - CONTRIBUTING (make pages-check), the Makefile help line, and the step names and comments of the host gate in ci.yml and pages.yml. Docs audit per .claude/rules/release.md: README.md, CONTRIBUTING.md, docs/*.md, docs/blog/*.md (EN and DE) and docs/proposals/*.md searched for bibliogon, external hosts, third-party, CDN, jsdelivr, unpkg, shields, badge, mermaid, LICENSE, docs:pages, pages-check, the plugin name and the Pages site URL. No other doc describes the gate, how the site loads Mermaid or how the badges render, so none had to change. Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
…Chromium fetched (#272) fcddcba said each variant in the tests was loaded in Chromium and fetched, except a cross-origin worker. Loaded again (headless Chromium 149, playwright-core 1.61.1, every request to another host answered locally and also read from Chromium's NetLog, 2026-10-20), more of the reported URLs are never requested. The scan reports them all the same, since a file scan cannot tell what a page runs or which element a style rule matches. The tests and the module docstring now say which: - a worker or shared worker script on another origin: Chromium refuses it before any request (in the test input that script does not even run, import.meta in a classic script is a syntax error); - an SVG <use> reference on another origin, refused the same way (the console reads "Unsafe attempt to load URL"; no NetLog entry); - a protocol-relative importScripts() URL, which does not resolve in a blob: worker, so the call fails before its first fetch (a.js on its own is fetched); - a script of a worker type the page never runs (fetched once the page makes a worker of its text); - an import map entry nothing imports (fetched once imported); - the url() of a <style> rule no element matches (fetched once one does); - <input type=" image ">: with the spaces the keyword makes no image button. The test had it as the case-insensitive example; that case is now type="IMAGE" (fetched), and " image " is its own, conservative, input. Every other URL the tests report was requested, and Chromium requested no third-party URL the scan leaves out. All ten pages seeded for bibliogon#1124 were requested; the gate before fcddcba exits 0 on nine of them, after it 1 on all ten. Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
Owner
Author
|
Correction to the PR body, from the independent verification after the merge (details in #274 and #275):
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
The Pages site (
https://astrapi69.github.io/learn-content-engine/) sent requests to third-party hosts on page load. This PR removes them and adds a gate that reads the assembled site for third-party references on every PR, not only on the deploy frommain.Before (from #272)
Live crawl of 40 pages on 2026-10-20:
cdn.jsdelivr.net:mermaid@11/dist/mermaid.min.json every docs page with a diagram (scripts/docs-site-lib.mjs:16, an unpinned major from a CDN).img.shields.ioandgithub.com: the npm and CI badges ofREADME.md:3-4, which TypeDoc renders into/api/index.html.Reproduced locally before any change, with the same capture used for the after-measurement below, on the site assembled from
main: exactly these 3 hosts (cdn.jsdelivr.netfrom the 4 diagram pages, both badges from/api/and/api/index.html). The gate as first ported (d9d7200) reported the same 6 references on that site and exited 1.What changed
fix(pages)):npm run docs:sitecopies the bundle of themermaiddevDependency (11.16.1, pinned bypackage-lock.json) todocs-site/assets/mermaid.min.js, and the diagram pages loadassets/mermaid.min.jsby a relative path, so it resolves under/learn-content-engine/docs/. Mermaid's licence ships next to it (see "Licence" below).docs-site/**joinsdocs-api/**in the ESLint ignores: ESLint 9 does not read.gitignore, and after a local docs buildnpm run lintlinted the minified bundle (9329 errors).fix(pages)): a local TypeDoc plugin,scripts/typedoc-plugin-remote-images.mjs, registered intypedoc.json. It listens toMarkdownEvent.PARSEat priority -100, after TypeDoc's own markdown-it renderer (priority 0), and replaces each remote<img>with its alt text in brackets./api/now reads "[npm version] [CI]", two links to the same targets as before (bare alt text ran together as "npm version CI"). A remote image with empty alt text is dropped. The README keeps its badges; on GitHub and npm they load through the platform's image proxy.chore(ci), thenfix(pages)):scripts/check-external-hosts.mjswith the rules inscripts/external-hosts-lib.mjs, a copy of bibliogon'sscripts/check_external_hosts.py(bibliogon#874, commit 3a92b3a7)..cssfiles, web manifests and service workers. In HTML:<link>with a fetching rel (hrefandimagesrcset);src/srcsetof script, img, iframe and media elements;<video poster>;<input type=image src>;<object data>;href/xlink:hrefof SVGimage,feImage,useandscript; meta refresh; CSSurl()and@importin<style>and instyleattributes; the loads an inline script names (import/export ... from,import(),importScripts(),new Worker()/new SharedWorker()with a string literal, import map entries);<iframe srcdoc>parsed as a page;<template>content. References resolve as in the browser: against a<base href>, and by the URL standard (\\host\x.jsis//host/x.js); CSS and JavaScript escapes are resolved first.rel=canonical/alternate, other<meta>content, JSON-LD, string constants in JS bundles.OK: no third-party reference in _site (135 file(s) read, 133 HTML page(s)).npm run docs:pagesassembles_siteexactly aspages.ymldid (docs-apitoapi,docs-sitetodocs,schema/*.jsontoschema,.github/pages/index.html);npm run docs:pages:checkscans it.pages.ymlruns both before the upload,ci.ymlon every PR,make pages-checklocally.scripts/remote-url.mjsholds the one definition of a remote URL that the gate and the TypeDoc plugin share; a module of its own keeps jsdom out of every TypeDoc run.docs): CHANGELOG[Unreleased],make pages-checkin CONTRIBUTING, the Makefile help line and the step names of the gate inci.ymlandpages.ymlsay what the gate reads.Why a JavaScript port and not the Python original
The original is a repository script in bibliogon, not a published package, so using it would mean copying it or fetching another repository's
mainat CI time. The engine's gates are Node scripts tested with Vitest, andpages.ymlhas no Python step;ci.ymlinstalls Python 3.12 only for the shipped validator helper and the prose gate. astrapi69/bibliogon#1124 (open) proposes one shared, versioned scanner for bibliogon, this repository and adaptive-learner. Until it exists, this copy names that issue in its docstring, and a fix to the rules belongs in both copies. Differences from the original: jsdom parses the HTML (the original useshtml.parser); its--sourcesmode for a Vite frontend has no counterpart here; this repository's floor rule (engine#93) is added, because the original passes on an empty or missing directory; and the nine forms of bibliogon#1124 are read.Probe: the pages seeded for bibliogon#1124
Each case is one page from
seeded/(copied byte for byte intosrc/__fixtures__/external-hosts/), scanned with--origin https://astrapi69.github.io. "Before" is the gate at e7ea79b, the port with bibliogon's rules unchanged; "after" is the gate at d35eb67. "Chromium" is headless Chromium 149 (playwright-core 1.61.1) loading the page from 127.0.0.1, with two records. First, Playwright's interception: every request to another host is recorded and answered locally. Second, independent of the interception: the page loaded again without it, through a local proxy (Playwright'sproxylaunch option) that forwards only 127.0.0.1 and records and refuses every other connection (for https it sees the host only, from the CONNECT), so nothing leaves the machine. Both records agree on every page. Measured 2026-10-20.An earlier run (the one d35eb67's commit message cites) took Chromium's NetLog as the second record, started with
--log-net-log. Chrome flags that switch as an unsupported command-line flag, so both tables here were measured again without it, with the proxy record instead. Gate exits, intercepted requests and scan output came out identical on all 29 pages of that run, and the proxy record agrees with them, so no claim changed, only the record behind it.control-script-src<script src>from a CDN (control)cdn.jsdelivr.net/.../mermaid.min.jsinline-style-urlurl()in astyleattributecdn.example/hero.jpgvideo-poster<video poster>cdn.example/poster.jpginput-image<input type=image src>cdn.example/button.pngsvg-image-href<image href>cdn.example/i.pngbase-href<script src>under a foreign<base href>cdn.example/app.jspreload-imagesrcset<link rel=preload imagesrcset>cdn.example/a.pngiframe-srcdoc<img src>inside<iframe srcdoc>cdn.example/x.pngbackslash-src<script src="\\cdn.example\x.js">cdn.example/x.jsesm-import-mermaidimportin an inline module scriptcdn.jsdelivr.net/.../mermaid.esm.min.mjsThe test file runs the same ten pages through the CLI and requires exit 1 and one report per case.
Conservative findings
The same capture was run over every input of the tests around the nine forms, and over each finding below on a page of its own. Chromium requested no third-party URL that the scan leaves out. It requested every URL the scan reports, except these, which the scan reports all the same because a file scan cannot tell what a page runs or which element a style rule matches. The tests and the module docstring name each one:
new Worker()/new SharedWorker()on another origin<use href>on another originrequestevent for it<use>reference only from the page's own originimportScripts("https://.../a.js", "//cdn.example/b.js")in a blob: worker//...does not resolve against a blob: URL, so the call fails before its first fetcha.json its own is fetchedtext/js-worker)url()of a<style>rule<input type=" image ">type="IMAGE"(any case, no spaces) is fetchedThe last one corrects a test: it had
" IMAGE "as the fetched example. It now hastype="IMAGE"(fetched) and" image "as its own, conservative input (d35eb67).Licence
Self-hosting Mermaid makes this site a distributor of it. Mermaid 11.16.1 is MIT-licensed, and the MIT licence asks for its copyright and permission notice in every copy. The minified bundle carries the licence blocks of what it bundles (lodash-es, DOMPurify, js-yaml, cytoscape) but not Mermaid's own notice.
npm run docs:sitetherefore copiesnode_modules/mermaid/LICENSEtodocs-site/assets/mermaid.min.js.LICENSE.txt, next to the bundle (/docs/assets/on the site): named after the bundle as bundlers name an extracted licence, and.txtso GitHub Pages serves it as text instead of a download. A test checks that the build writes it byte-identical to the installed package'sLICENSE.How it was measured after
Gates at d35eb67, 2026-10-20:
Runtime capture:
_siteserved under/learn-content-engine/on 127.0.0.1 and loaded in headless Chromium 149 (playwright-core1.61.1). Every request is recorded withcontext.on('request'). A request to any host other than 127.0.0.1 is recorded and then aborted, so the measurement itself sends nothing out. Each page is loaded, left to reach network idle, and scrolled to the bottom, and the capture waits until everypre.mermaidholds an<svg>. Every same-origin link on those pages is followed. On/api/the TypeDoc search box is used (queryparseLesson, first result clicked).main)/api/media/and/schema/), all 200cdn.jsdelivr.net,img.shields.io,github.com/api/searchThe 14 SVGs carry real diagram types (
flowchart-v2,sequence,stateDiagram,quadrantChart), none of them Mermaid's error graphic, so the self-hosted bundle actually renders. The capture shows what the browser loads; the gate shows what CI can check on every PR without a browser.Tests (TDD, each red first)
src/docs-site.test.ts(+5): Mermaid loads relatively from the site and never from a CDN; the build ships a bundle byte-identical to the lockedmermaid; it ships Mermaid's licence byte-identical to the package's; only the diagram pages load the bundle; the gate finds no foreign reference in the built docs site.src/typedoc-remote-images.test.ts(8): the reproduction uses TypeDoc's exact badge markup, and the visible text of the two links is "[npm version] [CI]". Also covered: local and data: images stay untouched, every spelling of a remote source is caught (a backslash read as a slash, as the gate reads it), a missing alt drops the image, alt text is kept inert, escaped markup in code samples is left alone, and the plugin is wired below priority 0.src/external-hosts.test.ts(43): bibliogon's pytest cases, ported; the branches they leave untested (srcset and media,<object>, meta refresh,<style>, rel naming,<template>content,node_modules, an unreadable host, the scanned-file list); one test per seeded page of bibliogon#1124 plus the control; the variants around the nine forms and the non-findings next to them (hyperlinks under a foreign base, in SVG, inside srcdoc, look-alike calls in a script), with comments naming what Chromium fetched and which findings are conservative; and the CLI's exit codes 0/1/2,--origin, and its OK line saying what it reads.preconnectfrom the rels, dropping the<template>recursion and disabling the floor each turn exactly the matching test red; 25 seeded mutations of the nine-form rules each turn at least one test red; a CDN stylesheet seeded into the docs page template turns the docs-site gate test red, naming all four diagram pages.Noticed, not changed here
docs:api:checkstays inci.ymlas its own named gate, althoughdocs:pagesnow runs the full TypeDoc build there too (about 2 s).scriptsentries inpackage.json. No consumer re-pin is needed.Docs audit (
.claude/rules/release.md)README.md, CONTRIBUTING.md,
docs/*.md,docs/blog/*.md(EN and DE) anddocs/proposals/*.mdsearched for pages, docs-site, bibliogon, external hosts, third-party, CDN, jsdelivr, unpkg, shields, badge, mermaid, LICENSE, TypeDoc, docs:pages, pages-check, the plugin name, the workflow names and the Pages site URL. No doc describes the Pages build, the gate, how the site loads Mermaid or how the badges render, so none had to change. Updated: CHANGELOG ([Unreleased]), CONTRIBUTING (useful targets), the Makefile help line, the gate's step names and comments inci.ymlandpages.yml, and the module docstrings ofscripts/build-docs-site.mjs,scripts/docs-site-lib.mjs,scripts/check-external-hosts.mjsandscripts/external-hosts-lib.mjs(the last one now lists the conservative findings).Checklist
make release-checkis green (lint + typecheck + test + build).feat:,fix:,docs:, ...), one commit per logical change.schema/*.jsonis untouched - or the schema change is deliberate: byte baseline + generated types updated in the same commit, changelog entry added (see CONTRIBUTING, "Adding a new exercise type").Closes #272
🤖 Generated with Claude Code