From 89ade2ad5bb460655a48733eb0ab2036070e02d7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jaroslav=20Bene=C5=A1?= Date: Fri, 13 Nov 2026 09:22:28 +0000 Subject: [PATCH] scripts/hygiene.sh: nothing private in the tracked files, checked in CI The same check the other LLeMbas repositories run: private domains, .lan names, container numbers, private address ranges, machine names. Three lines are allowed, each with its reason in the script: the public forge the release workflow republishes from, a theme's former name read from old configurations, and the made-up private hosts the web tool's test needs (renamed to made-up ones). Wired into scripts/ci.sh as its first step. Co-Authored-By: Claude Fable 5.2 --- scripts/ci.sh | 4 ++++ scripts/hygiene.sh | 43 +++++++++++++++++++++++++++++++++++++++++++ tests/web.test.ts | 4 ++-- 3 files changed, 49 insertions(+), 2 deletions(-) create mode 100755 scripts/hygiene.sh diff --git a/scripts/ci.sh b/scripts/ci.sh index 37cbcd1..aa9ee3d 100755 --- a/scripts/ci.sh +++ b/scripts/ci.sh @@ -32,6 +32,10 @@ if ! command -v bun >/dev/null 2>&1; then fi bun --version +# The repository is public: nothing private in its tracked files (scripts/hygiene.sh). +step "hygiene" +scripts/hygiene.sh + step "dependencies" bun install --frozen-lockfile diff --git a/scripts/hygiene.sh b/scripts/hygiene.sh new file mode 100755 index 0000000..e1bba7a --- /dev/null +++ b/scripts/hygiene.sh @@ -0,0 +1,43 @@ +#!/usr/bin/env bash +# The repository is public: nothing in it may name the private estate it was written on. +# The rule "everything public is current-state and estate-free", as a check that runs in CI on +# every push rather than a sentence somebody has to remember. +# +# Patterns are the kinds of thing that leak: a private domain, an internal `.lan` name, a +# container number, a private address range, a machine's name. This file is the one place that +# may spell them, and is skipped. +set -euo pipefail +cd "$(dirname "$0")/.." + +patterns=( + 'houmeres' + '\b[a-z0-9-]+\.lan\b' + '\bCT ?2[0-9]{2}\b' + '\b10\.0\.0\.[0-9]+' + '\b192\.168\.[0-9]+\.[0-9]+' + '\bgamebox\b' + '\bthor\b' +) + +# What is allowed to match, each for a reason — a line of `file:line:text` as grep prints it: +allowed=( + # The public forge the releases are made on: the workflow that republishes them must name it. + '^\.github/workflows/release\.yml:[0-9]+:.*git\.houmeres\.sk' + # A theme's former name, still read from a configuration written before it was renamed. + '^src/tui/palette\.ts:[0-9]+:export const RENAMED_THEMES' + # Made-up private names and addresses the web tool must refuse to fetch: the test needs them. + '^tests/web\.test\.ts:[0-9]+:.*(files\.lan|device\.lan|192\.168\.1\.10)' +) +allow="$(IFS='|'; echo "${allowed[*]}")" + +found=0 +for pattern in "${patterns[@]}"; do + hits="$(git ls-files -z | grep -zv '^scripts/hygiene.sh$' | xargs -0 grep -nIEi -- "$pattern" | grep -vE -- "$allow" || true)" + if [ -n "$hits" ]; then + printf '%s\n' "$hits" + echo "hygiene: the lines above match /$pattern/" >&2 + found=1 + fi +done +[ "$found" -eq 0 ] && echo "hygiene: nothing private in the tracked files" +exit "$found" diff --git a/tests/web.test.ts b/tests/web.test.ts index 6200219..2d361f6 100644 --- a/tests/web.test.ts +++ b/tests/web.test.ts @@ -104,7 +104,7 @@ describe("web tools", () => { test("webfetch on the local network asks; the public web does not", () => { const perm = { mode: "manual" as const, rules: toRules(DEFAULT_RULES), hardline: hardlineRules(), root: "/p" } expect(evaluate(webFetchTool.permission({ url: "https://docs.example.com/x" }, ctx()), perm).action).toBe("allow") - for (const u of ["http://192.168.1.10/", "http://localhost:3000", "https://nas.lan/admin", "http://[::1]/", "http://printer/"]) + for (const u of ["http://192.168.1.10/", "http://localhost:3000", "https://files.lan/admin", "http://[::1]/", "http://device/"]) expect(evaluate(webFetchTool.permission({ url: u }, ctx()), perm).action).toBe("ask") expect(isPrivateHost("100.100.1.1")).toBe(true) // tailnet expect(isPrivateHost("8.8.8.8")).toBe(false) @@ -121,7 +121,7 @@ describe("web tools", () => { // Audit: private addresses in other spellings, redirects, and pages built to stall a regex. import { fetchPage as fp13, htmlToMarkdown as h13, isPrivateHost as ip13, PrivateAddressError as PAE13 } from "../src/search/fetch.ts" test("private in every spelling; public names starting with fc/fd are not", () => { - for (const h of ["[::ffff:127.0.0.1]", "[::ffff:7f00:1]", "[::]", "[::ffff:a9fe:a9fe]", "localhost.", "printer.lan.", "[fe90::1]", "[fd12::1]"]) expect(ip13(h)).toBe(true) + for (const h of ["[::ffff:127.0.0.1]", "[::ffff:7f00:1]", "[::]", "[::ffff:a9fe:a9fe]", "localhost.", "device.lan.", "[fe90::1]", "[fd12::1]"]) expect(ip13(h)).toBe(true) for (const h of ["fcc.gov", "fdroid.org", "example.com", "[2001:db8::1]"]) expect(ip13(h)).toBe(false) }) test("a redirect to another local address is not followed, even from an approved local host", async () => {