Skip to content

feat(rules): security/json-sensitive-fields flags credentials and bulk PII in JSON API responses (repo#1956) - #1882

Merged
nc9 merged 2 commits into
mainfrom
boat/json-sensitive-fields-1956
Nov 14, 2026
Merged

nc9 merged 2 commits into
mainfrom
boat/json-sensitive-fields-1956

Conversation

@nc9

@nc9 nc9 commented Nov 14, 2026

Copy link
Copy Markdown
Contributor

Summary

Adds security/json-sensitive-fields, a site-scoped probing rule for squirrelscan/repo#1956 (part of the API and data exposure epic, repo#1952). It builds on the endpoint discovery pass (repo#1953) and the shared probe budget and levels (repo#1931, repo#1945).

  • What is sent: on an active or aggressive run, one quiet GET to each same-origin endpoint that discovery found, at most ten. Only call sites that use GET or state no method qualify. Requests carry no cookies (credentials: "omit"), do not follow redirects (redirect: "manual"), read at most 1 MB of decoded body through the GraphQL probe's capped reader (so a compression bomb is never inflated), and are bounded by the shared probe budget plus a 10 s timeout. Skipped: GraphQL paths, paths or queries that name a state-changing action (isStateChangingPath), robots-disallowed paths below aggressive, and anything cross-origin (origin re-checked, probeEligible not trusted). No path is guessed.
  • Fail (json-sensitive-fields): password hashes by format (bcrypt, argon2, scrypt, PBKDF2, crypt), server-side keys the leaked-secrets matchers recognise (high confidence or a server-only type, never publishable keys), and passwords, salts, secrets, API keys, tokens, SSNs, Luhn-valid card numbers or CVVs under fields named for them. Placeholders, label dictionaries, CSRF and pagination tokens, and public-by-design keys (such as a Firebase apiKey) are not flagged.
  • Warn (json-bulk-pii): 5 or more distinct emails or phone numbers, or 5 or more records with an address or date of birth. Role and admin fields are counted in the message. A single email is not flagged.
  • Redaction: no character of a value reaches the report. Items carry the endpoint, the folded field path ($[].passwordHash), the kind, the record count and the value length. Paths are clamped to 160 chars, at most 20 items per endpoint.
  • The rule copy says plainly that an anonymous probe cannot prove cross-user access.

The only change to shared code is that readCapped in graphql-probe.ts is now exported.

Closes squirrelscan/repo#1956 (private tracker).

Acceptance criteria

  • The rule parses JSON responses and flags sensitive field names and values. Evidence: scanJsonValue / scanJsonResponse; tests "card numbers, SSNs and plaintext passwords in user records are a fail" and "labels, placeholders, CSRF tokens, cursors and publishable keys are not flagged" (packages/rules/tests/json-sensitive-fields-1956.test.ts).
  • Password hashes, tokens and secrets in a response are high severity. They produce a fail check and the rule severity is error. Tests "password hashes are a fail, by shape and by key, with no value in the output" and "tokens, secrets and leaked-secrets provider keys are a fail" (leaked-secrets reuse catches a Postgres connection string under an unnamed key).
  • Bulk PII (emails or phones for many records) is flagged. Tests "emails for many records are a warning, redacted", "addresses and dates of birth across many records are bulk" and "one email ... is not bulk".
  • Values are redacted in output and the snippet is bounded. Tests assert that the raw hash, token, secret, email and phone substrings are absent from the serialized checks, and "items, paths and keys are bounded" (20 items, path at most 160, snippet at most 200, control characters stripped). In the end-to-end CLI run, grep -c for the hash and for an email in the JSON report both returned 0.
  • Runs only per fix(rules): content/reading-level skips code blocks (repo#1639) #1931, same-origin only. Tests "passive or no probe budget: skipped, nothing sent", "a zero budget sends nothing", "active sends one GET per endpoint: no cookies, no redirect follow, no body", "same origin only: cross-origin and probe-ineligible candidates are never requested" and "selection skips non-GET call sites, GraphQL, state-changing paths, robots and the cap". --disable-discovery-probes already forces the budget to passive in the CLI controller.

Verification

  • bun test packages/rules/tests/json-sensitive-fields-1956.test.ts: 18 pass
  • bun test rule-check-declarations, docs-index-rule-counts, docs-category-table, docs-rule-pages (with the new test file): 78 pass
  • graphql-probe, graphql-probe-decoding-722, graphql-introspection, graphql-get-mutations: 60 pass
  • meta-string-limits, discovery-probes and others: 355 pass. rule-verdict-scope: 359 pass
  • audit-engine streaming-rules-canonical-golden: 1 pass (findings 109735 to 109736, tally 328 to 329, the new rule's one skipped check). golden-finding-messages-229 regenerated (one added line) and passing: 3 pass. golden-baseline and streaming-collector-rules-golden: 8 pass
  • CLI: plugin-manager, mcp/server, audit/report and rules ignore-1262: 50 pass
  • tsgo typecheck for packages/rules (src and tests), packages/audit-engine and apps/cli: clean. oxlint (CLI config) on the new files: clean
  • make validate in docs/: all checks passed (rule-checks block generated, hub regenerated)
  • End to end: ran squirrel audit http://localhost:4799/ --probe active against a local fixture whose page calls fetch("/api/users"), which returns 8 users with bcrypt hashes. Result: json-sensitive-fields fail ($[].passwordHash: bcrypt hash (8 records)) and json-bulk-pii warn (8 distinct emails), with no value in the report.

Agent skill

The squirrelscan agent skill does not need a change. It describes rule categories and probing levels in general terms, and this rule adds no flag or config key.

@nc9

nc9 commented Nov 14, 2026

Copy link
Copy Markdown
Contributor Author

Review requirement for this rule: add or point to a test with a fixture JSON response that holds real-looking secrets (API keys, tokens, passwords) and email addresses, and assert that none of those values appear in any finding, finding detail, report output or log line. Only field names, counts and the endpoint may appear. Please also say in the PR body whether a fix round pushes the diff past about 1,500 lines.

nc9 added 2 commits November 14, 2026 23:33
…k PII in JSON API responses (repo#1956)

A site-scoped probing rule. On an active or aggressive run it sends one
cookie-less GET (redirects not followed, 1 MB decoded read cap, shared
probe budget) to each same-origin endpoint the discovery pass found whose
call site uses GET or states no method, at most ten. GraphQL paths,
state-changing paths or queries, and robots-disallowed paths below
aggressive are skipped. A passive run or no budget sends nothing.

A 2xx JSON answer is walked (bounded depth and nodes). Password hashes by
format, server-side keys the leaked-secrets matchers recognise, and
tokens, secrets, SSNs, Luhn-valid card numbers or CVVs under fields named
for them fail. Five or more distinct emails or phones, or records with an
address or date of birth, warn. Items carry the field path, kind and
length, never the value.

Docs page, security tables and counts (25 Security rules), probing table,
changelog and the canonical goldens (one skipped check) are updated.

Signed-off-by: Nik Cubrilovic <[email protected]>
… value (repo#1956)

One response can carry a public Firebase apiKey and a server apiKey. The
memo keyed only by field name let whichever was checked first decide the
other, so the public key could be reported as a secret, or the server key
hidden as public. The memo now keys on the normalized name and the value.

Signed-off-by: Nik Cubrilovic <[email protected]>
@nc9
nc9 force-pushed the boat/json-sensitive-fields-1956 branch from 550597a to 5005961 Compare November 14, 2026 23:33
@nc9
nc9 marked this pull request as ready for review November 14, 2026 23:51
@nc9
nc9 merged commit 5e1ddf0 into main Nov 14, 2026
16 checks passed
@nc9
nc9 deleted the boat/json-sensitive-fields-1956 branch November 14, 2026 23:51
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.

1 participant