Skip to content

feat(rules): add reliability/broken-forms for forms that lose submissions - #719

Closed
nc9 wants to merge 2 commits into
claude/703-broken-resourcesfrom
claude/707-broken-forms
Closed

nc9 wants to merge 2 commits into
claude/703-broken-resourcesfrom
claude/707-broken-forms

Conversation

@nc9

@nc9 nc9 commented Oct 12, 2026

Copy link
Copy Markdown
Contributor

Summary

Adds reliability/broken-forms (#707). Two faults lose form submissions with no visible error, and nothing in squirrel checked either before this rule:

  • A field with no name. The browser never submits it, so a visibly filled-in field is dropped. Warned when the form has a real action; reported as info when it has none, since a script may read the field.
  • An action that goes nowhere. A first-party action that answers 404 or 410 is an error. A staging, preview, development or localhost host (classified with the same helper content/dev-leakage uses) and mailto: are warnings, reported without any request. A 5xx, network failure, or third-party 404/410 is a warning. 429, 503 with Retry-After, and WAF challenges are reported as unverified info, never as broken.

Action checks run in this order. A mailto: or dev-host action is classified from its URL alone. A same-site action the crawl fetched uses the crawl's status. Anything else is probed through the shared probe budget with HEAD, and GET only when HEAD returns 405/501 or fails at the network level. The probe method type is "HEAD" | "GET", so no POST is possible. Each distinct action URL is probed at most once. Third-party actions are checked only when external link checking ran. Under passive probing the result says the action was not checked. Plain http: actions are left to security/form-https.

formaction on a submit button is checked the same way as the form's action. A control's owner is resolved from its form= attribute, falling back to its nearest <form>, so submit, button, reset, image, disabled and template-contained controls are never reported.

Stacking. This PR targets claude/703-broken-resources because the reliability category it uses lives on that branch (#714, still open). It must be retargeted to main after #714 merges. The Closes #707 link only takes effect once this lands on the default branch.

Verification

bun install --frozen-lockfile
bun test packages/rules/tests/broken-forms.test.ts          # 16 pass, 0 fail
bun test packages/rules/tests/broken-resources.test.ts packages/rules/tests/private-target-skip.test.ts   # 37 pass, 0 fail
cd packages/rules && bun run typecheck                      # tsgo --noEmit, clean
cd ../.. && bunx biome check packages/rules/src/reliability/broken-forms.ts packages/rules/src/reliability/index.ts packages/rules/tests/broken-forms.test.ts   # exit 0
make -C docs validate                                       # tangly check --strict: all checks passed

Targeted tests only, as requested. No whole-suite run.

Acceptance checklist

  • Warn on an unnamed email field in a form with a real action, naming the field and the form (test).
  • Fully named form produces no finding and passes (test).
  • No action or action="#" with an unnamed field gives info, not warn (test).
  • Unnamed submit/button/disabled and form=other controls are not reported against their own form; an unnamed control with form="contact" outside the form is reported against form#contact (test).
  • Same-origin action crawled and answering 404 gives an error with no extra request (test).
  • Uncrawled same-origin action answering 405 to HEAD and GET is not broken; 404 is (test).
  • No probe uses POST; passive probing sends no request for an uncrawled action and says so (test).
  • staging.example.com, localhost and mailto: actions each warn (test).
  • 429, 503 with Retry-After, and WAF challenges are unverified info, never broken (test).
  • Third-party action is requested only when external link checking is on (test).
  • http: action on an HTTPS page is left to security/form-https (test, public host).
  • Docs page at docs/rules/reliability/broken-forms.mdx, wired into nav and the Reliability index; make -C docs validate passes.

Deviations to review

  • http://localhost actions are both warned here (dev host, per the issue's fixture) and reported by security/form-https (insecure submission). The issue's two boxes conflict on this one case. This PR follows the fixture.
  • Third-party probes are sent by the rule's own HEAD/GET probe with the same verdict table. The external link checker lives in audit-engine, which packages/rules cannot import. When the checker already has a row for the URL (site.externalLinks), that row is used. The issue body asks for "the same checker", which this does not meet exactly.
  • Third-party 404/410 is a warning. The issue names no status for third-party dead actions, so this was my call.

Checklist

  • I added or updated tests for behavioral changes.
  • I did not include secrets, customer data, or incompatible third-party material.
  • Every commit includes a DCO Signed-off-by line (git commit -s).

🤖 Generated with Claude Code

https://claude.ai/code/session_01EAUNUbvoEuJsAyiazrJXLH


Generated by Claude Code

…egory #703

Scripts, stylesheets and fonts that a page references are fetched by the
asset phase, but no rule reported a 4xx/5xx or a failed request for them.
A deploy that deletes a hashed bundle left pages unstyled while the HTML
still answered 200.

reliability/broken-resources reads that existing asset data (no render,
no new requests):

- error: a first-party script or stylesheet answers 4xx/5xx
- warn: a third-party script or stylesheet or a font answers 4xx/5xx, or
  a request fails at the network level
- info: 429, 430 and 503 are throttling, reported as unverified, never
  broken
- info: a skipped fetch or an unmeasured kind makes the result partial
- one finding per resource URL, listing every referencing page

Adds the Reliability category (code reliability, group Performance) to the
canonical RuleCategory union, the rules and report category mirrors, the
loader, and the docs rules index and nav, with a category page and a rule
page under docs/rules/reliability/.

Signed-off-by: Claude <[email protected]>
Co-Authored-By: Claude <[email protected]>
Claude-Session: https://claude.ai/code/session_01EAUNUbvoEuJsAyiazrJXLH
…ions #707

Two faults lose form submissions with no visible error: a field with no
name is never sent, and an action that answers 404, points at a staging
or localhost host, or is mailto: never reaches a handler.

The rule is site-scoped. Unnamed controls are reported per form, split by
whether the form has a real action (warn) or not (info). Action checks
reuse the crawl's status for same-site URLs, report dev hosts and mailto:
without a request, and send at most one HEAD (then GET on 405/501 or a
network failure) per distinct uncrawled action, through the shared probe
budget. Third-party actions are checked only when external link checking
is on. No POST is ever sent, and passive probing says the action was not
checked.

Co-Authored-By: Claude <[email protected]>
Claude-Session: https://claude.ai/code/session_01EAUNUbvoEuJsAyiazrJXLH
Signed-off-by: Claude <[email protected]>
@claude

claude Bot commented Oct 12, 2026

Copy link
Copy Markdown

Reviewed the diff (docs, rule, index, tests). The design is sound: HEAD/GET only, a budgeted probe, one probe per distinct URL, and sensible handling of 429/WAF. I could not run the tests here.

  • (medium) packages/rules/src/reliability/broken-forms.ts (targetOf): the rule flags a form as non-production whenever its resolved host classifies as localhost, a private IP or a preview host. It never checks whether the audited site is itself on such a host. content/dev-leakage handles this around line 661 by skipping when the seed or site host is non-production. Auditing http://localhost:3000 or a *.vercel.app preview would warn on every relative form action. Mirror that guard. Alternatively, skip a dev classification when the target host equals the page host. Please add a test for it.
  • (low) broken-forms.ts (the mailto, non-production, dead, unreachable, unverified and unchecked labels): these interpolate target.href and source.form into labels unescaped. dev-leakage runs URLs through toSample to percent-encode markdown-active characters such as [](...), because a site-controlled href can inject links into the report. The mailto href is the raw attribute value, so it is the least sanitised. Apply the same escaping, ideally by reusing toSample.
  • (low) broken-forms.ts (verdictFor): the crawl-status shortcut treats any non-404/410/5xx status as ok. A same-site action whose crawled page returned a redirect to a 404 reads as fine. redirect: "manual" in send has the same blind spot. Probably acceptable, but the docs should say that redirects are not followed.
  • (low) broken-forms.ts (send): budget.record() is called before the request. A HEAD→GET fallback therefore spends two budget units for one action. This is intentional per the comment, but it could exhaust the budget sooner on sites with many distinct actions. Consider noting it in the docs.
  • (nit) broken-forms.ts (the mailto and dead .add(...) calls): these are long single lines, while the other calls are wrapped. Run the formatter.
  • (nit) The PR is stacked on claude/703-broken-resources, so it must be retargeted to main after feat(rules): add reliability/broken-resources and the Reliability category #703 #714 merges. The PR description already says so.

@nc9

nc9 commented Oct 12, 2026

Copy link
Copy Markdown
Contributor Author

Maintainer review (2026-10-12)

Verdict: needs fixes (high). I reviewed head f65b4c6. This PR targets claude/703-broken-resources, so only claude-review has run on it. The full CI will run for the first time once the base is main.

Acceptance criteria (#707)

All 12 boxes are ticked, each backed by unit tests in packages/rules/tests/broken-forms.test.ts.

The PR states two deviations itself:

  • A localhost http: action is reported both by this rule and by security/form-https.
  • Third-party actions are checked with the rule's own probe, not with the external checker.

Fixes

  1. Rebase onto main after feat(rules): add reliability/broken-resources and the Reliability category #703 #714 merges. This branch's parent is feat(rules): add reliability/broken-resources and the Reliability category #703 #714's first commit, f9cf0737. feat(rules): add reliability/broken-resources and the Reliability category #703 #714 lands as a squash, so drop that commit instead of replaying it:
    git fetch origin
    git rebase --onto origin/main f9cf0737 claude/707-broken-forms
  2. Golden gate. It will fail the same way it fails on the other rule PRs.
    • File: packages/audit-engine/tests/streaming-rules-canonical-golden.test.ts.
    • expect(v1.findings.length) (line 154, 101736 on today's main): reliability/broken-forms is site-scoped and adds one whole-crawl check. Raise it by 1. Add a comment line in the existing style, for example // <n> -> <n+1>: reliability/broken-forms is site-scoped and adds one whole-crawl check (#707). <its status on the fixture>.
    • expect(v1.perRuleTally.length) (line 176, 301 on today's main) fails next. Raise it by 1 and extend the tripwire comment.
    • Take the numbers from the main you rebase onto, because other rule PRs edit the same two lines.
    • Verify with cd packages/audit-engine && bun test tests/streaming-rules-canonical-golden.test.ts. healthScore.overall must not move, or the comment must explain why.
  3. High: false positives on local and preview audits.
    • targetOf marks any localhost, private-IP, preview or dev host as non-production. It never checks whether the audited site is itself on such a host.
    • So squirrel audit http://localhost:3000, the core coding-agent use case, warns on every form with a relative action. So does a *.vercel.app preview.
    • Mirror content/dev-leakage: skip the dev classification when the seed host (ctx.site.baseUrl) or the page host is itself non-production. Use isNonProductionSeedHost from packages/rules/src/content/dev-leakage.ts.
    • Add a test that audits a localhost site with a relative action.
  4. Hostile input in send().
    • send() calls globalThis.fetch directly. Bun then inflates a Content-Encoding body in full, even after body.cancel().
    • On the GET fallback (HEAD answers 405, then GET returns a gzip bomb), that reopens the memory blow-up that main's recent Content-Encoding fix (78c512f) closed for every other request.
    • Use fetchUndecoded from @squirrelscan/utils/response-body. Also send SQUIRRELSCAN_USER_AGENT and the configured custom or Web Bot Auth headers, as the other audit requests do.
  5. A probe 404 is an error, but often isn't one.
    • A HEAD or GET 404 becomes dead-form-action, an error. Express and Rails answer 404 to GET or HEAD on a route that only accepts POST.
    • Report a 404 from the probe as a warning that says "the endpoint may accept POST only". Keep the error for a status the crawl itself fetched.
    • The issue's own false-positive note points this way.
  6. Labels.
    • Labels interpolate the raw mailto: value and site-controlled form selectors. Truncate them, and escape them the way content/dev-leakage does with toSample.
    • Say in the unnamed-field warning that a script may read the field. The issue asks for this.
  7. Open review-bot findings not covered above:
    • A crawl status of 3xx reads as ok, and redirects are not followed. Say so in the docs.
    • HEAD then GET spends two probe-budget units. Say so in the docs.
    • Run the formatter (oxfmt) on the long .add(...) lines.

PR hygiene

  • CHANGELOG: add one line under ## [Unreleased] / ### Added, ending with squirrelscan/squirrelscan#707.
  • PR description: add a line saying whether the squirrelscan agent skill (squirrelscan/skills) needs a change. Drop the stacking note once the base is retargeted.
  • Attribution:
    • Remove the Co-Authored-By: and Claude-Session: trailers from the commit, and keep Signed-off-by:.
    • Remove the "Generated with Claude Code" footers and the session URL from the PR body.
    • No attribution lines of any kind in commit or PR text.
  • Docs: quote message templates with placeholders, never filled examples. No em-dashes.
  • Counts: leave the per-category counts in the README and docs tables (Reliability goes from 1 to 2). The maintainer will update them in one docs PR after these rule PRs merge.

Merge order

Sixth: after #714, #718, #717, #715 and #720.

@nc9

nc9 commented Oct 13, 2026

Copy link
Copy Markdown
Contributor Author

Superseded by #734 (same change, rebased onto main). GitHub closed this PR when its base branch was deleted on #714's merge, and a closed PR's base cannot be changed.

nc9 added a commit that referenced this pull request Oct 13, 2026
Status-only HEAD/GET probes of form actions through the egress guard (vet and pin, no credentials, no POST, no redirects), capped at 25 per audit and 10 per site. Replaces #719. 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

Development

Successfully merging this pull request may close these issues.

2 participants