Skip to content

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

Merged
nc9 merged 1 commit into
mainfrom
nik/707-broken-forms
Oct 13, 2026
Merged

nc9 merged 1 commit into
mainfrom
nik/707-broken-forms

Conversation

@nc9

@nc9 nc9 commented Oct 13, 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 the crawl found 404 or 410 is an error; a 404 to the rule's own probe warns that the endpoint may accept POST only. 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 endpoint is probed at most once, within the caps above. Third-party actions are checked only when external link checking ran. Under passive probing the result says the action was not checked.

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.

Changes from the maintainer review (2026-10-12) and two Opus security passes:

  • Replaces feat(rules): add reliability/broken-forms for forms that lose submissions #719, which GitHub closed when its base branch (claude/703-broken-resources) was deleted on feat(rules): add reliability/broken-resources and the Reliability category #703 #714's merge. Rebased onto main after feat(rules): add reliability/broken-resources and the Reliability category #703 #714, feat(rules): add links/broken-anchors for in-page anchor links #718, feat(rules): add security.txt and version-disclosure rules (#713) #717 and feat(rules): mobile/web-app-manifest checks the linked manifest and its icons (#710) #715, so no other PR's rule is carried here. It does not depend on feat(rules): add content/common-misspellings #709 #720 (content/common-misspellings), which is on hold.
  • Golden gate re-rolled from main: findings 101741 -> 101742 and tally rows 306 -> 307 (info "No forms detected" on the synthetic site), pinned; healthScore.overall stays 51.
  • Local and preview audits: dev hosts the audit is itself on are not leaks. Auditing localhost, a private-IP box or a tunnel (ngrok, trycloudflare), no localhost, private-IP, preview or dev action is reported; auditing a preview deployment (*.vercel.app, *.netlify.app), preview and dev actions are its own but localhost and private-IP actions are still reported. Tests audit a localhost site with a relative action and a preview site.
  • Probe hardening: fetchUndecoded (no compression bomb inflated, #2717), squirrel's User-Agent and Accept only, no cookies and none of the audit's custom headers (as the GraphQL probes), no redirects followed, body cancelled. Every probe goes through @squirrelscan/utils/public-egress, pinned to the vetted address: same-site probes stay on the site's host and subdomains and may resolve privately only on the site's own origin (a public site's subdomain or another port must resolve publicly), third-party probes go to public addresses only (unless the audited site is itself private), never link-local or metadata. This replaces the original globalThis.fetch call, which a background SSRF scan flagged. A refused probe spends no budget and reads as not checked.
  • Probe cap: at most 25 endpoints per audit and 10 per site (registrable domain), the site's own first; query variants of one endpoint share one probe.
  • Probe 404: a 404/410 to the HEAD/GET probe warns that the endpoint may accept POST only (form-action-not-found-to-probe); a 404/410 the crawl itself fetched stays an error.
  • Labels: site text is cut at 120 characters with markdown-link characters percent-encoded (selectors keep their brackets readable; URLs go through toSample); item ids and meta are cut at 2 KB. The unnamed-field warning says a script may still read the field.
  • On an http site, same-site http actions are judged from crawl status only; on an https site they are left to security/form-https.
  • Docs: 3xx reads as reachable and redirects are not followed; HEAD then GET spends two probe-budget units; the cap and the egress limits.
  • CHANGELOG line under [Unreleased] / ### Added.

Agent skill: yes, the squirrelscan agent skill (squirrelscan/skills) should learn the new rule; the maintainer files that as a private issue. The Reliability count (1 -> 2) is left for the maintainer's batched docs PR.

Closes #707

Verification

bun install --frozen-lockfile
(cd packages/rules && bun test tests/broken-forms.test.ts)                      # 31 pass, 0 fail
(cd packages/audit-engine && bun test tests/streaming-rules-canonical-golden.test.ts)  # 1 pass
(cd packages/rules && bun run typecheck)                                        # tsgo --noEmit, clean
(cd docs && bun run check)                                                      # tangly check --strict: all checks passed
detect-secrets-hook over the PR files                                           # clean

The rule and test files are oxfmt- and oxlint-clean. New tests cover: a localhost site's relative action, preview sites, probe headers and credentials: "omit" / redirect: "manual" / undecoded, pinning (connects to the vetted IP, Host is the name), private and metadata targets never requested (including a same-site name resolving to the metadata address), the caps and endpoint sharing, the IPv6-literal site, the probe-404 warning, and markdown-link injection in labels.

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).

@claude

claude Bot commented Oct 13, 2026

Copy link
Copy Markdown

Reviewed packages/rules/src/reliability/broken-forms.ts in full. I only skimmed the tests, docs and golden-test changes, and I did not run the test suite.

Overall this is a careful rule. It never sends a POST, because the HEAD/GET method type rules it out. Probes go through the egress guard, are capped, and don't follow redirects. Selectors and hrefs are escaped before they reach labels. I found nothing that should block merge.

  • (low) broken-forms.ts Pass 2: probes run one at a time, because verdictFor is awaited inside the loop. With the caps (25 probes, up to 2 requests each, 10s per request) the worst case is long. The shared budget deadline should bound it, but running the first-party and third-party probes in parallel, with per-host limits, would keep slow hosts from stalling the rule.
  • (low) probeWithinQuota dedupes by origin and path and ignores the query string. That is reasonable for a status check. A form whose action routes on the query (?action=x) could get a verdict from a different variant. A short comment would document this.
  • (low) reachOf with fromProbe=false reports dead (an error) from the crawl's 404. The crawl probably fetched the action with GET. A POST-only endpoint that was linked or crawled would then be reported as an error, not the softer "probe-missing" warning. This is unlikely in practice, but the wording "submissions are lost" is definite.
  • (nit) selectorOf calls forms.indexOf(form) for every field and action, which is O(n²) on pages with many forms. Precompute an index map.
  • (nit) The pass check (formCount and hasProblem) never emits pass when only info items exist. That seems intentional, but a test for it would pin the behaviour.
  • (nit) severity: "error" in the rule meta while most findings are warnings. Confirm this matches how other reliability rules are scored.

Test coverage: packages/rules/tests/broken-forms.test.ts is included and the golden test is updated. Please make sure the probe-cap, per-site-cap and egress-refusal paths are covered.

…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 (a crawl 404/410 is an error),
report dev hosts and mailto: without a request, and send at most one HEAD
(then GET on 405/501 or a network failure) per uncrawled endpoint, through
the shared probe budget. A 404 to that probe warns that the endpoint may
accept POST only. 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.

- Dev hosts the audit is itself on are not leaks: a localhost, private-IP
  or tunnelled site reports none; a preview deployment still reports
  localhost and private-IP actions.
- Probes send squirrel's User-Agent and Accept only (no cookies, no custom
  headers), are fetched undecoded with the body cancelled, follow no
  redirect, and go through the @squirrelscan/utils/public-egress guard,
  pinned to the vetted address: same-site probes stay on the site's hosts,
  and only the site's own origin may resolve privately (a public site's
  subdomain or another port on its host must resolve publicly); third-party probes go to public addresses
  only (unless the site itself is private); never link-local or metadata. A
  refused probe spends no budget.
- At most 25 endpoints per audit and 10 per site are probed, the site's own
  first; query variants of one endpoint share one probe.
- Labels cut site text at 120 characters and percent-encode the characters
  that would form a markdown link; item ids and meta are cut at 2 KB.
- On an http site, same-site http actions are judged from crawl status
  only, never probed; on an https site they are left to security/form-https.
- The rule is built by createBrokenFormsRule({ resolve }) so tests inject
  DNS; brokenFormsRule uses the system resolver.

Golden gate: +1 finding and +1 tally row (info "No forms detected" on the
synthetic site); healthScore.overall stays 51.

Signed-off-by: Nik Cubrilovic <[email protected]>
@nc9
nc9 force-pushed the nik/707-broken-forms branch from 0c7a63d to b29af25 Compare October 13, 2026 04:19
@claude

claude Bot commented Oct 13, 2026

Copy link
Copy Markdown

Review of reliability/broken-forms (read the full diff of the rule, the dev-leakage export and the wiring; I did not run the tests or check CI).

No blocking problems. The probe path is well hardened: HEAD/GET only, no cookies, redirects not followed, undecoded body, egress guard, per-site and total caps, and markdown-safe labels.

  • (medium) broken-forms.ts verdictFor (crawl-status branch): a same-site action the crawl found 404 or 410 is reported as dead (error severity). The crawl fetched it with GET, so it has the same POST-only ambiguity as the probe case (Express and Rails return 404 to GET on a POST-only route). That ambiguity is why probe-missing is only a warning. A form action is usually not linked, so this case is rare, but when it does fire it can be a false-positive error. Consider downgrading to probe-missing unless the URL was reached as a normal link, or say so in the docs.
  • (low) Pass 2 awaits verdictFor serially. With up to 25 probes at a 10s timeout each, a slow site could add several minutes before the shared budget deadline cuts it off. Running the probes with small bounded concurrency, or checking the budget deadline up front, would help.
  • (low) dead, probe-missing and unreachable verdicts are cached per resolved href in verdicts, but probeWithinQuota is keyed by endpoint (origin and path). That is consistent. Note that a probe cap reached verdict is cached per href, so a later query variant of an already-probed endpoint still gets the real verdict (good), but any other endpoint gets unchecked. The unchecked message could say how many were skipped by the cap.
  • (low) localityOf hardcodes TUNNEL_SUFFIXES. It is fine now, but the list will drift from the dev-leakage classifier. Consider moving it next to classifyHost.
  • (nit) The rule now imports classifyHost, isLoopbackHost, isNonProductionSeedHost, isPrivateIpHost, registrableDomain, siteOriginOf and toSample from content/dev-leakage. A shared util module would avoid a cross-rule dependency.
  • (nit) The reach branch of targetOf silently skips plain-http actions from https sites. The comment explains why (security/form-https covers them), but a one-line note in the rule docs would help.
  • (nit) The pass check is skipped when only info-level buckets exist. That is intentional, but a test pinning the behavior would be good if it is not already covered.

Test coverage: the PR adds broken-forms.test.ts and updates the canonical golden test, which looks sufficient. I did not run them. A test for the dead vs probe-missing distinction on crawled 404s would cover the first finding.

@nc9
nc9 merged commit 2619fbc into main Oct 13, 2026
15 checks passed
@nc9
nc9 deleted the nik/707-broken-forms branch October 13, 2026 04:31
@nc9 nc9 mentioned this pull request Oct 13, 2026
14 tasks done
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.

New rule: forms that silently lose submissions (unnamed fields, dead or staging actions)

1 participant