Skip to content

fix(parser,rules): empty-body pages and hostile ids no longer throw rule errors #1270 #1276 - #1290

Closed
nc9 wants to merge 3 commits into
mainfrom
fix/1270-1276-empty-doc-selectors
Closed

nc9 wants to merge 3 commits into
mainfrom
fix/1270-1276-empty-doc-selectors

Conversation

@nc9

@nc9 nc9 commented Oct 29, 2026 •

Copy link
Copy Markdown
Contributor

Fixes #1270
Fixes #1276

What

  • parseHTML (the one entry point in packages/parser/src/dom.ts) never returns a root-less document. An empty, whitespace, comment-only, plain-text, JSON or bare-doctype body is reparsed inside <html><head></head><body>..</body></html>, as a browser reads it. document.head / document.body no longer throw, so the burst of bogus Rule error fails on one degenerate page is gone at the source, not patched per rule.
  • New packages/rules/src/shared/attribute-lookup.ts: labelsFor(doc, id) (one pass per document) and elementsWithAttribute(root, attr, value) compare attribute values as plain strings. All page-controlled selector interpolations now use them: form-labels, form-field-multiple-labels, select-name, aria-input-field-name, aria-toggle-field-name, aria-meter-name, aria-progressbar-name, aria-command-name, aria-required-parent, aria-required-children, security/form-captcha. Constant-keyed ones (roles, captcha field names) went through the same helpers so the guard has no exceptions.
  • CLI and engine adapters treated an empty-string html as null ("corrupted state" error spam, page skipped); they now test == null.

Tests (failing first, 27 of 43 failed before the fix)

  • packages/parser/tests/empty-document-1270.test.ts: parseHTML / parseDocument / parsePage over each degenerate body.
  • packages/rules/tests/degenerate-pages-and-hostile-ids-1270-1276.test.ts: every enabled rule through RuleRunner.runPageRules on each degenerate body, asserts zero Rule error: checks; hostile ids (", \, ], space, mixed) through each listed rule with labels still associating; a guard that fails when a rule interpolates a value into an attribute selector.
  • apps/cli/tests/cli/audit-degenerate-pages-1270-e2e.test.ts: the real CLI over a site with plain-text, JSON, comment-only and bare-doctype pages: no Rule error. Fails on main, passes now.
  • The guard test now reads selector calls across lines, traces a variable to its template, and covers #${} and .${}; the known constant interpolations are allowlisted by file and snippet.
  • Updated the tests that pinned the old no-root behaviour (rules/tests/dom-size.test.ts, page-classifier/tests/featurize.test.ts).

Notes

  • AC "reported once as a page-level finding": a page whose body has markup-free content (plain text, JSON, a comment, a bare doctype served as text/html) now parses to an empty shell and is audited normally, with no Rule error. A zero-byte 200 body is NOT audited: the engine drops any page whose html is the empty string (!page.html in parsePageRecord, getParsedPages, isAuditablePage), so it gets neither findings nor a not-evaluated entry. That is a separate gap, filed as audit: a 200 page with an empty body is dropped silently before the rules run #1314, and this PR does not claim to fix it.
  • perf/dom-size no longer needs its "No document root found" skip (a root always exists); an empty body measures 0 nodes. Docs for the rule updated.
  • Skill (squirrelscan/skills): no change needed.
  • CHANGELOG bullets under ## [Unreleased] / Fixed.

nc9 added 2 commits October 30, 2026 10:17
…or/role lookups no longer build selectors #1270 #1276

Signed-off-by: Nik Cubrilovic <[email protected]>
…e; engine-level CLI test; broader selector guard #1270 #1276

Signed-off-by: Nik Cubrilovic <[email protected]>
@nc9

nc9 commented Oct 30, 2026

Copy link
Copy Markdown
Contributor Author

Landed in v0.0.142 via the stacked release PR #1331: 73780351 and the commits after it on main (rebase-merged, so this PR shows as closed rather than merged).

@nc9 nc9 closed this Oct 30, 2026
nc9 added a commit that referenced this pull request Oct 30, 2026
…ntBody test) and oxfmt of the content store

Signed-off-by: Nik Cubrilovic <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

2 participants