Repository navigation
Conversation
…est with resume planning #1231 Signed-off-by: Nik Cubrilovic <[email protected]>
|
Reviewed the diff. The slice is well scoped: pure functions, linear scans, caps in
|
…d echo, caps, validated manifest, spec alignment #1231 Signed-off-by: Nik Cubrilovic <[email protected]>
|
Review of #1547 (slice 1: urls-file reader, manifest, strict host classifier). I read the
Overall, no blocking issues found. |
…arser-derived, conservative fallback); 3fff /20, ISATAP and residual special-use IPv6; edge tests #1231 Signed-off-by: Nik Cubrilovic <[email protected]>
|
Review of slice 1 (urls file reader, manifest and resume planning, strict host classifier). The code is careful and the untrusted-input handling is good: bounded lines, validated keys and report paths, and masked echoes. I found nothing blocking.
|
…usal, malformed address-shaped text refused, dummy 100:0:0:1::/64; cut-line echo test; header states what is echoed #1231 Signed-off-by: Nik Cubrilovic <[email protected]>
|
Review of #1547 (slice 1 of #1231: urls-file reader, manifest and resume planning, strict host classifier). The code reads carefully and the untrusted-input handling matches AGENTS.md. Findings:
I read the IPv4 and IPv6 range logic in |
|
Landed in bundle #1799, rebase-merged to main. nik |
Refs #1231 (slice 1 of 4). Groundwork only: two CLI modules and a stricter host classifier in
packages/utils, with tests. No CLI flag, no file or network I/O, no behaviour change for any command, so no docs, CHANGELOG or completion entry yet (they ship with slice 2, which adds the flag).Split of #1231 (L) into small PRs
--concurrency 1:squirrel audit --urls-file F --out-dir D, each URL as a childsquirrel audit, one report per key, the results file appended as each URL ends (arunningline when it starts), the status mapping from the child's exit code, batch exit codes 0, 1, 2 and 6, the rejected-flags message,completion.ts,docs/cli/audit.mdx, CHANGELOG.timeout, a child that dies without a record recorded ascrashed, never two URLs of one project at once.--concurrency Nabove 1 (after Concurrent squirrel audit processes fail with 'SQLite database is busy (locked)' #1226),--retry-failed, the retention notice and recipe, and the signed-in rules.What is in this PR
packages/utils/src/non-public-host.ts: newisNonPublicHostnameStrict, exported from@squirrelscan/utilsand@squirrelscan/utils/non-public-host. It is the shared classifier plus the special-use ranges the shared one accepts: IPv4 192.0.0.0/24, 192.0.2.0/24, 192.88.99.0/24, 198.18.0.0/15, 198.51.100.0/24, 203.0.113.0/24, multicast, reserved and broadcast (224.0.0.0 and up, which also covers 255.255.255.255 and 4294967295); IPv6 NAT6464:ff9b::/96(judged by the IPv4 it carries, so64:ff9b::808:808stays public) and local-use64:ff9b:1::/48, 6to4 (judged by its IPv4), Teredo, IPv4-compatible::a.b.c.d, site-local fec0::/10, documentation 2001:db8::/32 and 3fff::/20 (a true /20), multicast ff00::/8, discard 100::/64, and mapped, translated and ISATAP (::5efe:a.b.c.d,::200:5efe:under any prefix) IPv4 re-checked against the strict rules, and 2001:2::/48, 2001:10::/28, 2001:20::/28 and 5f00::/16. Deliberate deviation from the review: I added a separate function instead of changingisNonPublicHostname. The shared one also decides which delivery rules run on a page and whether a cloud handoff is attempted, and its callers (rules runner, cloud preflight, crawler seed redirect, TLS probe, MCP) and fixtures use documentation ranges; its tests are unchanged and still pass. Say so if you want the shared function changed instead.apps/cli/src/batch/urls-file.ts:parseUrlsFilereads the file as untrusted input. Blank lines and#lines are ignored; a BOM, CRLF and surrounding spaces are not part of a URL. A bareexample.comorlocalhost:3000is read as https. Refused with line number and reason, never dropped silently: not http or https, unparsable, a control character anywhere in the line (a lone CR no longer joins two URLs), userinfo (including a password alone), a non-public host by the strict classifier unlessallowPrivateHosts, a line over 2,048 characters, and a URL that is over 2,048 characters once parsed (2,000 multi-byte characters become 18,020). The echo of a refused line cannot carry a credential: when the WHATWG parser finds userinfo (it reads any mix of/and\after the scheme) the echo is rebuilt from its parts (scheme://***@host, path, masked query and fragment) and nothing of the original authority is kept; when the parse throws, a conservative fallback masks everything up to the last@, fullwidth or small@, or%40before the first?or#, and keeps only a real scheme (http, https, ftp, ws, wss, file). A line cut for length echoes only its size. Control characters show as U+FFFD. A randomized 3,000-line differential and the slash, fullwidth,%3a, over-long and unparsable shapes are tests. The rejected list is capped (default 1,000) andrejectedCountcounts all of them (an 8 MiB file ofalines made 4.19 million objects, 884 MB). More thanmaxUrls(default 100,000) distinct URLs is an error before any request, not a silent cut. Byte cap is the spec's 64 MiB, a parameter (maxBytes); a slice 2 caller must stat the file or read at most the cap plus one byte before decoding, because the check here runs on a decoded string (noted in the file header and the constant). A line far over the cap is refused from its head without being copied whole.apps/cli/src/batch/manifest.ts: the record (addsfinishedAt) with the issue's status vocabulary plusrunning.blockedandredirectedare failures:--retry-failedruns them again and they count toward exit code 6 (isFailedStatus), as the Batch mode for squirrel audit: --urls-file with concurrency, resume and per-URL failure records #1231 spec says (the first version treated them as final). Arunningline that is the last record of a URL is read ascrashed(effectiveStatus).parseManifestvalidates what it reads:keymust be 16 hex characters,reporta relative path with no..,., backslash, colon or control character,attemptan integer 1 to 1,000 (a tampered 1e308 no longer masks later records),score0 to 100,pagesandexitCodeintegers in range, non-finite numbers dropped, text fields and notes capped, a URL over the URL cap rejected, and a line over 64 KiB skipped without parsing.planBatchderives the plan from the urls file only: a record counts only when its key is a listed URL's key and its ownurlequals that URL, so a forged record cannot count a URL done or mask its real record. On a same-attempt tie the later line wins..exampleand.testhosts are refused by default (fixtures useallowPrivateHosts).What is not masked: the path and the names of query keys of a refused line are echoed, and an accepted URL keeps its path and query (they reach the manifest and child process args), so a secret carried in a path or a query key is not protected here (stated in the
urls-file.tsheader). Only userinfo, query values and the fragment are masked.Classifier, fail closed: an embedded IPv4 (NAT64, 6to4, ISATAP, mapped, translated) now only adds a refusal; a public one falls through to the prefix rules, so
ff02::5efe:808:808,fec0::5efe:808:808,3fff::5efe:808:808and100::5efe:808:808stay refused. Text with the shape of an address (a colon, or four dotted numbers) that is not well formed (nine groups, two::, a zone id, brackets, an octet over 255) is refused by the exported strict function;100:0:0:1::/64is refused.Notes for slice 2: accepted URLs keep their query strings, so they land in the manifest and in child process arguments; read the urls file at most
maxBytes + 1bytes before decoding; terminate a partial last manifest line (add a newline) before appending, or the next record joins it; stat or slice the urls file before decoding it; write therunningline when a URL starts.Acceptance criteria of #1231 touched by this slice (none complete alone): the untrusted-urls-file criterion is implemented here for the reader and wired in slice 2; the resume criteria and the record format are implemented here as pure functions and wired in slice 2.
Tests:
apps/cli/tests/batch/urls-file.test.ts29,manifest.test.ts27,packages/utils/tests/non-public-host-strict.test.tsplus the unchangednon-public-host.test.ts144. New cases: every special-use range and public neighbour, embedded-IPv4 forms, bare hosts, masked echo (userinfo,http://:pw@host, query, fragment), the rejected cap at 8 MiB of one-character lines, the 2,048 and 2,049 line cap boundary, control characters, grown-URL cap,maxUrlsandmaxBytesboundaries, manifest validation for each field,1e999, the line cap, forged and mismatched records, the same-attempt tie,runningas crashed. Mutants run one at a time with the file restored after each: 18 classifier mutants (one per family and sub-range), 9 urls-file mutants, 14 manifest mutants, each fails a test. Two survivors are equivalent: removingNumber.isFinitefrom the range check (the range already excludes Infinity and NaN) and removing the huge-line fast path (the line is refused as too long either way; it only avoids a copy).Gates (one at a time with
heavy.sh): the three test files above,bun run lint,bun run format:check,tsgo --noEmitinapps/cliandpackages/utils.Skill: no change needed (no user-facing change yet).
nik