From d4c6b5887bc42deba2a70839bfc7b8fb5ce73f2f Mon Sep 17 00:00:00 2001 From: Pieter Viljoen Date: Sun, 25 Oct 2026 16:47:01 -0700 Subject: [PATCH 1/3] Load the Search Page Only on a Run Over the Default List A run given another list with --urls, such as the family site's pages, no longer adds /search/, so it passes on its own pages. A list that wants the search page names it. Co-Authored-By: Claude Opus 5.5 --- OPERATIONS.md | 2 +- checks/check-csp-browser.py | 15 ++++++++++---- checks/tests/test_check_csp_browser.py | 28 +++++++++++++++++++++++--- 3 files changed, 37 insertions(+), 8 deletions(-) diff --git a/OPERATIONS.md b/OPERATIONS.md index d225c6b..c1799a1 100644 --- a/OPERATIONS.md +++ b/OPERATIONS.md @@ -104,7 +104,7 @@ checks/check-csp-browser.py "$SITE_BASE_URL" - **It needs Docker and `uv` on the host, and no browser.** Chromium runs in the Playwright image [`checks/browser/Dockerfile`](./checks/browser/Dockerfile) pins, where Dependabot moves it. `uv` installs the Playwright package inside it at the image tag's own version, so the two cannot drift. Its cache is `UV_CACHE_DIR` where that is set, or a directory under the system temporary root. - **The container shares the host network**, so it reaches a local mirror by the name the host resolves. -- **A violation fails the run unless [`checks/csp-browser-allow.txt`](./checks/csp-browser-allow.txt) lists it.** Each line is a directive, a blocked origin, and the reason, tab separated. A blocked scheme is written as the browser reports it, such as `data` with no colon. An entry that nothing matched fails a run over the default list, so an entry goes when its cause does. `--urls` takes another list, and such a partial run leaves unused entries alone. +- **A violation fails the run unless [`checks/csp-browser-allow.txt`](./checks/csp-browser-allow.txt) lists it.** Each line is a directive, a blocked origin, and the reason, tab separated. A blocked scheme is written as the browser reports it, such as `data` with no colon. An entry that nothing matched fails a run over the default list, so an entry goes when its cause does. `--urls` takes another list, and such a partial run leaves unused entries alone. It also loads `/search/` only where the list names it, since a list can be for the family site, which has no search page. - **A page that does not answer `200` fails the run**, since a trial over error pages proves nothing. - **It runs only against the local mirrors.** VPS staging sits behind the auth gate, which the check does not present. A full run is hundreds of pages. Production takes only a handful of probes per pass, since a burst there can get the reviewing network banned. - **It runs by hand rather than in the release.** It needs Docker, a browser image, and a running server, and neither the release build nor the unit suite has all three. diff --git a/checks/check-csp-browser.py b/checks/check-csp-browser.py index 6af97fa..3873577 100755 --- a/checks/check-csp-browser.py +++ b/checks/check-csp-browser.py @@ -48,15 +48,19 @@ def pinned_image(dockerfile_text): return found.group(1), found.group(2) -def read_paths(texts): - """The site paths the lists name, in order, once each, the search page always among them.""" +def read_paths(texts, search): + """The site paths the lists name, in order, once each, and the search page where asked. + + Only a run over the default list asks, since another list can be for a site with no search + page, and a list that wants it names it. + """ paths = [] for text in texts: for line in text.splitlines(): path = line.strip() if path and path not in paths: paths.append(path) - if SEARCH_PATH not in paths: + if search and SEARCH_PATH not in paths: paths.append(SEARCH_PATH) return paths @@ -253,7 +257,10 @@ def main(argv=None): image, version = pinned_image(DOCKERFILE.read_text(encoding="utf-8")) allow = read_allow(ALLOW.read_text(encoding="utf-8")) - paths = read_paths(p.read_text(encoding="utf-8") for p in (args.urls or [URLS])) + paths = read_paths( + (p.read_text(encoding="utf-8") for p in (args.urls or [URLS])), + search=args.urls is None, + ) cache = pathlib.Path( os.environ.get("UV_CACHE_DIR") or pathlib.Path(tempfile.gettempdir()) / "blog-csp-browser-uv" diff --git a/checks/tests/test_check_csp_browser.py b/checks/tests/test_check_csp_browser.py index b650386..4b6b999 100644 --- a/checks/tests/test_check_csp_browser.py +++ b/checks/tests/test_check_csp_browser.py @@ -56,13 +56,17 @@ def test_the_committed_allow_list_parses(self) -> None: class ListTest(unittest.TestCase): def test_paths_keep_order_drop_repeats_and_add_search(self) -> None: - paths = gate.read_paths(["/\n/a/\n\n", "/a/\n/b/\n"]) + paths = gate.read_paths(["/\n/a/\n\n", "/a/\n/b/\n"], search=True) self.assertEqual(paths, ["/", "/a/", "/b/", gate.SEARCH_PATH]) def test_a_listed_search_page_is_not_added_twice(self) -> None: - paths = gate.read_paths([f"{gate.SEARCH_PATH}\n/\n"]) + paths = gate.read_paths([f"{gate.SEARCH_PATH}\n/\n"], search=True) self.assertEqual(paths, [gate.SEARCH_PATH, "/"]) + def test_paths_not_asking_for_search_keep_only_their_own(self) -> None: + paths = gate.read_paths(["/en/\n/af/\n"], search=False) + self.assertEqual(paths, ["/en/", "/af/"]) + def test_an_allow_line_without_a_reason_is_refused(self) -> None: with self.assertRaises(ValueError): gate.read_allow("img-src\thttps://images.example\n") @@ -144,11 +148,29 @@ def run_main(self, records, argv=()): return code, out.getvalue() def test_every_page_loaded_clean_passes(self) -> None: - paths = gate.read_paths([gate.URLS.read_text(encoding="utf-8")]) + paths = gate.read_paths([gate.URLS.read_text(encoding="utf-8")], search=True) code, out = self.run_main([loaded(path) for path in paths]) self.assertEqual(code, 0, out) self.assertIn("PASS", out) + def test_a_run_over_another_list_loads_only_its_own_pages(self) -> None: + with tempfile.TemporaryDirectory() as folder: + urls = pathlib.Path(folder) / "family-urls.txt" + urls.write_text("/en/\n/af/\n", encoding="utf-8") + with ( + mock.patch.object( + gate, + "run_probe", + return_value=([loaded("/en/"), loaded("/af/")], None), + ) as probe, + mock.patch.object(gate, "docker_command", return_value=["true"]), + mock.patch.object(gate, "read_allow", return_value=[]), + contextlib.redirect_stdout(io.StringIO()) as out, + ): + code = gate.main([BASE, "--urls", str(urls)]) + self.assertEqual(code, 0, out.getvalue()) + self.assertEqual(probe.call_args.args[1], ["/en/", "/af/"]) + def test_a_page_that_never_reported_fails(self) -> None: code, out = self.run_main([loaded("/")]) self.assertEqual(code, 1) From 0254118e2545ea5e9c44d9da3027ed7088eaba29 Mon Sep 17 00:00:00 2001 From: Pieter Viljoen Date: Sun, 25 Oct 2026 16:53:22 -0700 Subject: [PATCH 2/3] Say in --help That Another List Names the Search Page Co-Authored-By: Claude Opus 5.5 --- checks/check-csp-browser.py | 7 +++++-- checks/tests/test_check_csp_browser.py | 22 ++++++++-------------- 2 files changed, 13 insertions(+), 16 deletions(-) diff --git a/checks/check-csp-browser.py b/checks/check-csp-browser.py index 3873577..d47059d 100755 --- a/checks/check-csp-browser.py +++ b/checks/check-csp-browser.py @@ -52,7 +52,7 @@ def read_paths(texts, search): """The site paths the lists name, in order, once each, and the search page where asked. Only a run over the default list asks, since another list can be for a site with no search - page, and a list that wants it names it. + page. A list that wants it names it. """ paths = [] for text in texts: @@ -238,7 +238,10 @@ def main(argv=None): "--urls", type=pathlib.Path, action="append", - help=f"a list of site paths, repeatable (default {URLS.name})", + help=( + f"a list of site paths, repeatable (default {URLS.name}, plus {SEARCH_PATH}," + f" which another list names where it wants it)" + ), ) parser.add_argument( "--probe", diff --git a/checks/tests/test_check_csp_browser.py b/checks/tests/test_check_csp_browser.py index 4b6b999..0d626dc 100644 --- a/checks/tests/test_check_csp_browser.py +++ b/checks/tests/test_check_csp_browser.py @@ -139,7 +139,9 @@ def setUp(self) -> None: def run_main(self, records, argv=()): with ( - mock.patch.object(gate, "run_probe", return_value=(records, None)), + mock.patch.object( + gate, "run_probe", return_value=(records, None) + ) as self.probe, mock.patch.object(gate, "docker_command", return_value=["true"]), mock.patch.object(gate, "read_allow", return_value=[]), contextlib.redirect_stdout(io.StringIO()) as out, @@ -157,19 +159,11 @@ def test_a_run_over_another_list_loads_only_its_own_pages(self) -> None: with tempfile.TemporaryDirectory() as folder: urls = pathlib.Path(folder) / "family-urls.txt" urls.write_text("/en/\n/af/\n", encoding="utf-8") - with ( - mock.patch.object( - gate, - "run_probe", - return_value=([loaded("/en/"), loaded("/af/")], None), - ) as probe, - mock.patch.object(gate, "docker_command", return_value=["true"]), - mock.patch.object(gate, "read_allow", return_value=[]), - contextlib.redirect_stdout(io.StringIO()) as out, - ): - code = gate.main([BASE, "--urls", str(urls)]) - self.assertEqual(code, 0, out.getvalue()) - self.assertEqual(probe.call_args.args[1], ["/en/", "/af/"]) + code, out = self.run_main( + [loaded("/en/"), loaded("/af/")], ["--urls", str(urls)] + ) + self.assertEqual(code, 0, out) + self.assertEqual(self.probe.call_args.args[1], ["/en/", "/af/"]) def test_a_page_that_never_reported_fails(self) -> None: code, out = self.run_main([loaded("/")]) From 3195386f556fecaddeb6400330ef388a1d2c624a Mon Sep 17 00:00:00 2001 From: Pieter Viljoen Date: Sun, 25 Oct 2026 16:58:30 -0700 Subject: [PATCH 3/3] Refuse a URL List That Names No Page Co-Authored-By: Claude Opus 5.5 --- checks/check-csp-browser.py | 4 +++- checks/tests/test_check_csp_browser.py | 13 +++++++++++++ 2 files changed, 16 insertions(+), 1 deletion(-) diff --git a/checks/check-csp-browser.py b/checks/check-csp-browser.py index d47059d..2117af2 100755 --- a/checks/check-csp-browser.py +++ b/checks/check-csp-browser.py @@ -8,7 +8,7 @@ event in the page and in each frame it holds, as it fires. The event fires for an enforcing policy and a Report-Only one alike. Each page is scrolled to its end so lazy images load, and its code-copy buttons are clicked. The search page also gets a typed query, so the index fetch and the -results run. +results run. A run over the default list always loads it, and another list only where it names it. The browser runs in the Playwright image `browser/Dockerfile` pins, where Dependabot moves it. The Playwright package is installed at the image tag's own version, so the two never disagree. The @@ -264,6 +264,8 @@ def main(argv=None): (p.read_text(encoding="utf-8") for p in (args.urls or [URLS])), search=args.urls is None, ) + if not paths: + parser.error("the --urls lists name no page, so there is nothing to load") cache = pathlib.Path( os.environ.get("UV_CACHE_DIR") or pathlib.Path(tempfile.gettempdir()) / "blog-csp-browser-uv" diff --git a/checks/tests/test_check_csp_browser.py b/checks/tests/test_check_csp_browser.py index 0d626dc..64586c6 100644 --- a/checks/tests/test_check_csp_browser.py +++ b/checks/tests/test_check_csp_browser.py @@ -197,6 +197,19 @@ def test_a_relative_base_url_is_a_usage_error(self) -> None: gate.main(["mirror.example"]) self.assertEqual(raised.exception.code, 2) + def test_a_list_naming_no_page_is_a_usage_error(self) -> None: + with tempfile.TemporaryDirectory() as folder: + urls = pathlib.Path(folder) / "empty-urls.txt" + urls.write_text("\n \n", encoding="utf-8") + with ( + mock.patch.object(gate, "run_probe") as probe, + contextlib.redirect_stderr(io.StringIO()), + self.assertRaises(SystemExit) as raised, + ): + gate.main([BASE, "--urls", str(urls)]) + self.assertEqual(raised.exception.code, 2) + probe.assert_not_called() + class CommandTest(unittest.TestCase): def test_the_container_installs_the_tag_version_and_reaches_the_host(self) -> None: