Skip to content

feat(rules): add GraphQL introspection and GET mutation probing rules - #593

Merged
nc9 merged 6 commits into
mainfrom
claude/graphql-probe-rules-t662nl
Oct 8, 2026
Merged

nc9 merged 6 commits into
mainfrom
claude/graphql-probe-rules-t662nl

Conversation

@nc9

@nc9 nc9 commented Oct 8, 2026

Copy link
Copy Markdown
Contributor

Summary

Two sibling site-scoped probing rules that share one GraphQL helper. They are the first rules that send requests through the probing intensity setting (ctx.probe): on a passive run, or with no probe budget, each records one skipped check and sends nothing.

  • security/graphql-introspection (warning, weight 5): one GET /graphql?query={__schema{types{name}}} per endpoint. Warns when the answer is a 2xx GraphQL response with named types, naming the endpoint and the type count. On an aggressive run only, one POST of the same read-only query follows when the GET answer is GraphQL-shaped without a schema and does not say introspection is disabled.
  • security/graphql-get-mutations (error, weight 7): one GET /graphql?query=mutation{__typename} per endpoint. Fails when the server executes it (data.__typename is the mutation root). Never sends a POST.
  • packages/rules/src/security/graphql-probe.ts: candidate selection from the endpoint discovery pass plus /graphql and /api/graphql, strict same-origin re-check (probeEligible is not trusted as safe-to-send), never a path naming a state-changing action (logout, delete, update, reset and similar, whole words) or a PUT/PATCH/DELETE call site, robots.txt respected below aggressive, at most five endpoints. Requests are built from a fixed operation name, so no other query can be sent; they carry no cookies, do not follow redirects, have a 10 s timeout plus the shared budget deadline, and read a capped body (1 MB introspection, 64 KB mutation). GraphQL responses are parsed strictly: a JSON object with only data/errors/extensions, every error carrying a message, never HTML.

There is no tracking issue for this change; the criteria below are the acceptance checklist.

Design note: the introspection query is exactly {__schema{types{name}}} as specified, so the finding reports type counts (all types, and API-defined types without __* and built-in scalars), not field counts. Asking for fields{name} would make both the request and the answer larger.

Acceptance criteria

Shared helper

  • One helper used by both rules for candidate selection (discovery pass plus conventional paths), GraphQL-shaped response detection and the state-changing rule, with its own tests. Evidence: packages/rules/src/security/graphql-probe.ts; packages/rules/tests/graphql-probe.test.ts (19 tests).

security/graphql-introspection

  • GET first, with ?query={__schema{types{name}}}, to discovery candidates or conventional paths; state-changing call sites never probed; same-origin enforced by the helper, not by probeEligible. Tests: graphql-introspection.test.ts "a full schema over GET is flagged..." (exact requests sent), "a discovered endpoint is probed and named", "state-changing and cross-origin candidates are never requested"; graphql-probe.test.ts "state-changing call sites are never probed, by path or by method", "probeEligible is not trusted: a cross-origin URL is dropped even when marked eligible", "introspection over GET carries the query in the URL and nothing else".
  • POST only as an aggressive fallback after a GraphQL-shaped GET without a schema; body is the introspection query only; no POST below aggressive or when the GET is not GraphQL-shaped. Tests: "aggressive: one POST of the introspection query after a GraphQL-shaped GET without a schema", "active: a GraphQL error without a schema sends no POST and is not flagged", "aggressive: no POST when the GET is not GraphQL-shaped", "aggressive: no POST when the GET says introspection is disabled"; graphql-probe.test.ts "active sends a GET but never the POST; aggressive sends both", "introspection over POST sends only the read-only query as JSON".
  • Detects a full schema over either method. Tests: "a full schema over GET is flagged...", "aggressive: one POST of the introspection query..." (method POST in the finding).
  • Introspection disabled / errors not flagged. Tests: "aggressive: no POST when the GET says introspection is disabled", "aggressive: a POST that also fails is not flagged", "errors, empty schemas and non-2xx schemas are not flagged".
  • Finding names the endpoint and the exposed type count. Test: "a full schema over GET is flagged with the endpoint and type count" (8 types, 4 of them defined by the API, item meta).
  • One bounded request per endpoint; runs only under the probing intensity setting; same-origin only. Tests: "passive or no probe budget: skipped, nothing sent", "a spent budget skips the rule without sending", the exact request list in "a full schema over GET..."; graphql-probe.test.ts "at most 5 endpoints are selected", "a body over the cap is cut and marked truncated", "passive and an absent budget send nothing".

security/graphql-get-mutations

  • The only operation ever sent is the no-op mutation{__typename}, as a GET, to GraphQL candidates; state-changing candidates never probed; same-origin only; probeEligible not trusted. Tests: graphql-get-mutations.test.ts "nothing but the no-op mutation over GET is ever sent, at any level and any answer" (active and aggressive, four answer shapes, discovered state-changing, PATCH and cross-origin candidates in the surface; every request is a body-less same-origin GET whose only param is query=mutation{__typename}); graphql-probe.test.ts "the no-op mutation is GET only".
  • An executed mutation is flagged; a 405, a "mutations only over POST" error or an introspection-style error is not. Tests: "an executed mutation is flagged...", "custom mutation root names are recognised" (mutation_root, RootMutationType, MutationRoot), "405, POST-only errors, introspection-style errors and query answers are not flagged".
  • Confirmed by GraphQL-shaped JSON, not status alone; HTML or catch-all not flagged. Tests: "HTML, catch-all and non-GraphQL JSON answers are not flagged, whatever the status"; graphql-probe.test.ts "HTML, catch-all, REST and JSON:API bodies are not GraphQL".
  • One bounded, size-capped request per endpoint; runs only under the probing intensity setting; nothing sent when probing is off. Tests: "passive or no probe budget: skipped, nothing sent", "an oversized answer is not parsed or flagged", "robots.txt disallowed endpoints are not probed below aggressive", "a spent budget skips the rule without sending".
  • Finding names the endpoint, explains mutations reachable over GET (CSRF, non-idempotent GET) and gives the fix. Test: "an executed mutation is flagged, naming the endpoint, the risk and the fix".
  • Rule docs pages, rules index and counts, probing docs, CHANGELOG; make validate passes. Evidence: docs/rules/security/graphql-introspection.mdx, docs/rules/security/graphql-get-mutations.mdx, docs/rules/security/index.mdx, docs/rules/index.mdx, docs/index.mdx, README.md, docs/agent-setup/index.mdx, docs/docs.json, docs/configuration/security.mdx (new "Rules that probe" section), docs/cli/audit.mdx, CHANGELOG.md. cd docs && make validate: all checks passed.

Both rules: results are not cached

  • Site rules are not in the per-page rule-result cache, and every test runs the rule fresh against a stubbed fetch. Tests: "each run probes live: a later run sees the server's new answer" / "each run probes live: a fixed server passes on the next run".

Verification

  • bun test tests/graphql-probe.test.ts tests/graphql-introspection.test.ts tests/graphql-get-mutations.test.ts (packages/rules): 43 pass.
  • bun test tests/max-rules-limit.test.ts tests/meta-string-limits.test.ts tests/rule-verdict-scope.test.ts tests/discovery-probes.test.ts tests/noindex-skip.test.ts, then tests/shared-regex.test.ts tests/endpoint-surface.test.ts tests/probe-budget.test.ts (packages/rules): all pass.
  • bun test tests/streaming-rules-canonical-golden.test.ts (packages/audit-engine): pass, updated for 301 rules and 101736 findings (two skipped checks; this gate is passive). Overall score unmoved at 51.
  • bun test tests/golden-baseline.test.ts tests/publish-meta.test.ts tests/template-fanout-parity-golden.test.ts tests/noindex-site-rules-dual-path.test.ts, tests/endpoint-discovery.test.ts (packages/audit-engine): pass.
  • bun test tests/commands/audit-probe-wiring.test.ts, tests/commands/audit-discovery-probes-wiring.test.ts, tests/rules/loader.test.ts (apps/cli): pass.
  • bun run typecheck in packages/rules and packages/audit-engine: clean. Root bun run format:check and bun run lint: clean; oxlint with the CLI config on the new files: clean.
  • detect-secrets-hook --baseline .secrets.baseline on changed files: clean (one test URL with user:pw@ carries an inline allowlist pragma).

Agent skill

No change required: the skill does not list rule counts or probing rules. Optional for the maintainer: mention that these two findings appear only with --probe active or higher.

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 by Claude Code

Add two site-scoped probing rules that share one GraphQL helper, the first
rules that send requests through the probing intensity setting (ctx.probe).
On a passive run, or with no probe budget, both record one skipped check
and send nothing.

- security/graphql-introspection sends one GET with the read-only query
  {__schema{types{name}}} per endpoint and warns when the answer is a 2xx
  GraphQL response with named types, naming the endpoint and the type
  count. On an aggressive run only, one POST of the same query follows
  when the GET answer is GraphQL without a schema and does not say
  introspection is disabled.
- security/graphql-get-mutations sends one GET with the no-op mutation
  mutation{__typename}, which names no schema field and cannot write, and
  fails when the server executes it (data.__typename is the mutation
  root). A 405, a POST-only error, an introspection error, a query answer,
  HTML or a catch-all is not flagged. It never sends a POST.
- security/graphql-probe.ts selects candidates from the endpoint discovery
  pass plus /graphql and /api/graphql: strict same origin re-checked (not
  trusting probeEligible), a graphql or gql path segment, never a path
  that names a state-changing action or a PUT/PATCH/DELETE call site,
  robots.txt respected below aggressive, at most five endpoints. Requests
  are built from a fixed operation name, carry no cookies, do not follow
  redirects, use a per-request timeout plus the shared budget, and read a
  capped body. GraphQL responses are parsed strictly.

Rule pages, the security rules index, counts (301 rules, 20 in Security),
the probing docs and the changelog are updated. The canonical golden pins
two more rules and two skipped checks; the score is unmoved.

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

claude Bot commented Oct 8, 2026

Copy link
Copy Markdown

Reviewed the diff and read graphql-probe.ts and graphql-introspection.ts in full. I read only the first part of graphql-get-mutations.ts (its diff up to the pass/fail message) and did not open the test files. I did not run the tests.

The design is careful. Operations are fixed by name, so the rules can't send an arbitrary query. The origin is re-checked rather than trusting probeEligible. Requests carry no cookies, don't follow redirects, and read capped bodies. The POST path can only carry the introspection query. I found nothing that should block the merge.

  • (low) graphql-probe.ts:353-367 and both rules: a network error, timeout or abort still counts as probed. If every endpoint errors out, the rule reports a pass ("No GraphQL endpoint returned its schema (N probed…)"), which reads like a clean result. Consider counting errors separately and either mentioning them in the pass message or emitting a skipped or info check when nothing got a response.
  • (low) graphql-probe.ts:301-335 (readCapped): the cap is on raw bytes read. If fetch auto-decompresses (gzip/br), the cap applies after decoding, which is fine. The content-length precheck is only an optimisation. It's worth a comment that truncation is the real guard. The 10 s timeout also bounds a slow-drip body only because the signal is passed to fetch, so the reader loop should abort with it. A test for a stalled body would confirm this.
  • (low) graphql-probe.ts:223-228: seen.add(url) for a state-changing candidate also blocks a later safe call site with the same URL. Because a PUT call site on /graphql marks the path as never probed, the conventional /graphql check is silently dropped for the whole site. That is fail-safe and probably intended, but it should be documented in the rule docs, since it changes what "No GraphQL endpoint could be probed" means.
  • (nit) STATE_CHANGING_WORDS includes broad words such as set, clear, write and pay. They are whole-word matches, so false positives are rare, but a path like /graphql/clear-cache is skipped even though GraphQL is exactly what is being probed. It is fail-safe, so fine to keep.
  • (nit) graphql-get-mutations.ts: executedMutationType matches any __typename containing "mutation" (/mutation/i). A custom query root named, say, MutationQuery would be a false positive. Anchoring against the schema is impossible here, so this is an acceptable heuristic, but it could be noted in the docs.
  • (nit) graphql-introspection.ts:59: saysIntrospectionDisabled matches any error message containing "introspection". A message like "introspection query failed to parse" would suppress the aggressive POST fallback. Minor, and it errs on sending less.
  • (nit) The two rules repeat the same skeleton: passive skip, selection, empty-candidate pass, budget skip, pass summary. A small shared helper in graphql-probe.ts would cut the duplication.

Test coverage looks thorough, going by the PR description's per-criterion list. The one gap I'd add is the stalled or slow-body case above.

nc9 commented Oct 8, 2026 •

Copy link
Copy Markdown
Contributor Author

Thanks for the review. Nothing in it is critical, high or medium, so this round has no push. Here is what happens to each point:

  • Network errors count as probed (low). I'm leaving this as is in this PR. A pass after a run where every request failed can read as clean. The pass check's details carries probed and graphqlAnswers, but not an error count. If the maintainer wants it, the follow-up is to count errors separately and emit a skipped check (probe-errors) when no endpoint answered at all. That is about 10 lines per rule.
  • readCapped and a stalled body (low). I'm leaving this as is. The combined AbortSignal (the budget deadline plus a 10 s timeout) is passed to fetch, so it also aborts the body stream, and the reader.read() loop rejects into the caller's catch. The content-length precheck is only a shortcut, and the per-chunk cap is the real guard.
  • A state-changing URL also blocks the same URL from another source (low). This is intended and fail-safe. A PUT call site on /graphql means the conventional /graphql probe is dropped too. The skip counts are reported in the check's details (skippedStateChanging, skippedRobots, skippedCap).
  • Broad words in the state-changing list (nit). Keeping them. They match whole words only, and erring toward sending less is the point.
  • /mutation/i on __typename (nit). Keeping it. The rule cannot read the schema without introspection, and a query root whose name contains "mutation" is far less likely than a renamed mutation root (mutation_root, RootMutationType).
  • The "introspection" substring check (nit). Keeping it. It only ever suppresses the aggressive POST, so it errs toward sending less.
  • Duplicated rule skeleton (nit). Keeping it. The two rules differ in what they send and how they read the answer, and the shared part is already in graphql-probe.ts.

Status: all criteria in the PR body have tests. Format, lint, typecheck and sign-off checks pass, and the remaining CI jobs are running.

nc9 commented Oct 8, 2026 •

Copy link
Copy Markdown
Contributor Author

Status: CI is green on 5ec8a68: all 15 checks pass, including the CLI tests, the audit engine golden tests, docs, the secret scan and CodeQL. The bot review raised no critical, high or medium findings, and the replies are above. The PR is ready for review, and I have not merged it.

@claude

claude Bot commented Oct 8, 2026

Copy link
Copy Markdown

Review of #593 (GraphQL introspection and GET-mutation probing rules). I read the full diff of graphql-probe.ts and both rules. I did not run the test suite.

The design is careful. Probes are limited to fixed operation names, same-origin, with no cookies and no redirects. They are capped by body size, a timeout and an endpoint count, and they respect the probe budget. The passive skip path is also covered in the golden test. I found no blocking issues.

  • (medium) graphql-probe.ts readCapped / parseGraphqlBody: an introspection body over 1 MB is marked truncated and parsed as "not GraphQL". The rule then reports a pass, even though a very large schema is wide open. The false negative is silent. Consider a distinct truncated verdict (for example, a warn that the schema is open but too large to count), or raise the cap.
  • (low) both rules, final pass message: "No GraphQL endpoint returned its schema" is emitted even when every probe errored (timeout, DNS or TLS failure) or returned a 3xx, because outcome.error is silently skipped. Surface a count of failed probes in details, or use skipped when none produced a response, so a network failure does not read as a clean result.
  • (low) graphql-probe.ts STATE_CHANGING_WORDS: whole-word matching on set, pay, clear, edit and write will drop legitimate paths such as /api/v1/graphql/settings (no match) but also /set/graphql, /pay-api/graphql and /clear/gql. That errs on the safe side, but skippedStateChanging is only exposed in details. A short note in the rule docs would help users understand why an endpoint was not probed.
  • (low) sendGraphqlProbe: probe.record() is called before fetch, so a request that throws before leaving the process still counts against the budget. This is harmless and conservative. A comment would make it clear it is intentional.
  • (nit) buildGraphqlProbe: the throw for a non-introspection POST is unreachable given the GraphqlProbeRequest type. A type-level guarantee is enough, or keep it as a deliberate defensive check.
  • (nit) readCapped decodes with new TextDecoder().decode(buf). If the cap lands mid-codepoint, the output is garbled. It is irrelevant here because truncated bodies are discarded, but truncated could short-circuit before decoding.
  • (nit) The mutation rule's fail message is a long single string. Consider moving the remediation text into meta.solution, as the introspection rule does.

Test coverage looks good. There are dedicated tests for the probe helper, both rules and a local GraphQL server helper. I would add cases for the over-cap body and for a network-error-only run, to pin the behaviour of the first two findings.

An introspection answer longer than the 1 MB read cap was parsed as not
GraphQL, so a very large open schema passed silently. When the cut answer
opens exactly as an introspection answer does, the rule now counts the type
names in its first 1 MB and warns with lower-bound counts ("at least") and
truncated: true in the item meta. A large answer that does not open as a
schema, or is served as HTML, is still not flagged. readCapped no longer
skips the body on a declared content-length over the cap; the per-chunk cap
is the guard.

Both rules now count probes that failed with a network error or timeout,
and record a skipped check (probe-errors) instead of a pass when every
probe failed, so a failed run never reads as clean.

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

nc9 commented Oct 8, 2026 •

Copy link
Copy Markdown
Contributor Author

Reply to the second review. Commit b7b001e is about to be pushed:

  • (medium) A schema over 1 MB passes silently: fixed. When a cut answer opens exactly as an introspection answer does ({"data":{"__schema":{"types":[), the rule counts the type names in its first 1 MB and warns with at least counts and truncated: true in the item meta. A large answer that does not open as a schema, or is served as HTML, is still not flagged. readCapped now reads up to the cap even when content-length is larger. Tests: "a schema answer over the 1 MB cap is still flagged, with lower-bound counts", "a large answer that does not open as a schema is not flagged", and the truncatedSchemaTypeNames cases.
  • (low) Every probe erroring reads as a pass: fixed in the same push, since both reviews raised it. Both rules count failed probes in details.errored, and record a skipped check with reason probe-errors when every probe failed. Tests: "when every probe fails with a network error the rule skips, it does not pass" in both rule suites.
  • (low) record() before fetch: this is intended, and a comment now says so.
  • (low) Docs note on state-changing skips: the rule pages already say which paths are never probed, and the counts are in details. No change.
  • (nit) Unreachable throw in buildGraphqlProbe: kept as a deliberate runtime guard next to the type.
  • (nit) Decoding a cut buffer: harmless. A cut answer is only read through the anchored prefix match, and a split final code point cannot complete a "name":"..." pair.
  • (nit) Long fail message: kept. The acceptance criteria ask for the finding itself to give the fix, and meta.solution carries the longer text.

@claude

claude Bot commented Oct 8, 2026

Copy link
Copy Markdown

Reviewed the two rules and the shared graphql-probe.ts. I didn't run the tests, and CI was still pending when I looked. I found nothing blocking. The probe design is careful: operations are fixed by name, requests are same-origin, carry no cookies and don't follow redirects, response reads are capped, GraphQL parsing is strict, and passive runs send nothing.

  • (low) graphql-probe.ts (STATE_CHANGING_WORDS): the word list is broad. set, pay, clear, edit and save match any path segment, so a path like /settings/graphql is not affected, but /set/graphql or /pay/graphql would be skipped. That fails safe. It is worth noting in the docs that skipped endpoints are counted in skippedStateChanging.
  • (low) graphql-get-mutations.ts and graphql-introspection.ts: when endpoints were probed but none answered as GraphQL (a plain 404 on the convention paths), the check reports pass with "No GraphQL endpoint ...". That is accurate, but the pass is indistinguishable from a verified-safe GraphQL server. Consider skipped or not-applicable when graphqlAnswers === 0, so the score isn't credited for a clean result.
  • (nit) graphql-probe.ts (sendGraphqlProbe): the error branch returns err.name, which is often just Error or TypeError. Including a short message would help debugging.
  • (nit) readCapped decodes a truncated prefix with the default TextDecoder, which can split a multibyte character at the cap. That is harmless here because truncated bodies are only regex-scanned.
  • (nit) Test coverage looks good: there are unit tests for selection and parsing plus a local server helper. A test that pins buildGraphqlProbe output for the redirect and credentials options would guard the safety invariants against regressions.

…o count

Make the truncated introspection verdict explicit. When a 2xx answer opens as
a schema ({"data":{"__schema":{"types":[) but is longer than the 1 MB read
cap, the rule now always reports it as a lower-confidence finding that names
the endpoint: the schema is open but too large to count, with confidence
"lower" and truncated: true in the item meta. It is never a pass. The prefix
check returns an empty list rather than null when no complete type name fits
in the cap, so a schema whose first name alone is over the cap is still
flagged.

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

nc9 commented Oct 8, 2026 •

Copy link
Copy Markdown
Contributor Author

The medium finding about an introspection answer over 1 MB is now handled as its own truncated verdict in 42cf8b4, the PR head.

  • A 2xx answer that opens as a schema ({"data":{"__schema":{"types":[) but runs past the 1 MB cap is always a warning that names the endpoint. It is never a pass. Message: GraphQL introspection is open at <endpoint>: the schema answer is larger than 1 MB, too large to count (at least N types seen, answered over GET). The item meta has truncated: true and confidence: "lower".
  • The answer is still flagged when no complete type name fits in the cap; truncatedSchemaTypeNames returns [] instead of null for a matching prefix.
  • A large answer that does not open as a schema, or that is served as HTML, is still not flagged.

Tests:

  • "an oversized introspection body is flagged as open but too large to count, never a pass"
  • "an oversized schema with no complete type name in the cap is still flagged"
  • "a large answer that does not open as a schema is not flagged"
  • the truncatedSchemaTypeNames cases in graphql-probe.test.ts

The rule page documents the verdict. main was already merged in, so this is one push.

nc9 commented Oct 8, 2026 •

Copy link
Copy Markdown
Contributor Author

Reply to the third review, which looked at b7b001e. It found no critical, high or medium issues, so it gets no push of its own.

  • (low) Broad state-changing words: kept, because the list fails safe. The rule pages say which paths are never probed, and the count is in details.skippedStateChanging.
  • (low) A pass when no endpoint answered as GraphQL: kept. A site with no GraphQL endpoint at its discovered or conventional paths has nothing to fix, so a pass is the honest result. The message and details.graphqlAnswers say how many endpoints answered as GraphQL. Runs that checked nothing are already skipped: passive (probing-passive), a spent budget (probe-budget) and all requests failing (probe-errors).
  • (nit) Error name only: kept. The error is not shown in the report, and the counts are what the checks use.
  • (nit) A multibyte character split at the cap: harmless, as you note.
  • (nit) Pinning redirect and credentials: already covered. "introspection over GET carries the query in the URL and nothing else" asserts credentials: "omit" and redirect: "manual" on buildGraphqlProbe, and the rule tests assert both on every request actually sent.

@claude

claude Bot commented Oct 8, 2026

Copy link
Copy Markdown

Review of the GraphQL probing rules (graphql-probe.ts, graphql-introspection.ts, graphql-get-mutations.ts). I read the three source files in full and checked the ProbeBudget API they call (allows, signal, record and level all exist). I did not run the tests or read the test files, docs or golden-test changes.

The safety design is sound. Requests are built from a fixed operation name, are same-origin, carry no cookies, do not follow redirects, have capped response bodies, and go through the shared probe budget. The state-changing path filter and the strict response parser are careful. I found nothing that should block the merge.

  • (medium) graphql-introspection.ts:229 and graphql-get-mutations.ts:155: when the budget runs out partway (budgetStopped = true after probed > 0), the rule still emits a plain pass ("No GraphQL endpoint returned its schema"). Some endpoints were never probed, so this can hide an open endpoint. Consider a pass message that says the run was partial, or a skipped check with skipReason: "probe-budget" when budgetStopped is true and nothing was exposed. budgetStopped is currently only put in details.
  • (low) graphql-probe.ts:303-332, readCapped: if reader.read() throws (abort or timeout), the reader is never cancelled or released. The catch in sendGraphqlProbe handles the error, but the connection is held until GC. A try/finally with reader.cancel().catch(() => {}) would be cleaner.
  • (low) graphql-probe.ts:76-114, STATE_CHANGING_WORDS: whole-word matching on set, pay, edit, save and create is conservative, but it can silently skip legitimate endpoints such as /graphql/settings (not matched, since it is a whole-word match) versus /set/graphql (matched). That is fine, but the skip is only a counter in details. Consider surfacing skippedStateChanging > 0 in the pass message so users know why an endpoint was not checked.
  • (low) graphql-introspection.ts:86: introspection is only recognised on 2xx. Some servers return the schema with a non-2xx status, but that is rare. Worth a code comment, not a change.
  • (low) graphql-probe.ts:223-226: a method of undefined from a discovered candidate is treated as safe, but a candidate from a call site with an unknown method could still be a mutation endpoint. The path filter covers the main cases, so this is an edge case only.
  • (nit) graphql-introspection.ts:200: seen is empty-string-or-text, and schema.types > 0 ? ... : "" is always true for a truncated verdict that found names. When the prefix matches but no complete "name" pair fits, the message reads "too large to count (answered over GET)". It is correct but slightly awkward.
  • (nit) graphql-get-mutations.ts:37-41: /mutation/i on __typename would also accept a query root named something like MutationQuery. This is unlikely, and the comment explains the intent.

Test coverage: I did not review the tests. Please make sure there are cases for a mid-run budget stop (the first finding above), an aborted body read, and a robots.txt-disallowed path under active versus aggressive.

When the shared probe budget ran out partway through the endpoints and
nothing was flagged on the ones reached, both GraphQL rules reported a pass,
which could hide an open endpoint the run never reached. They now record a
skipped check (probe-budget) naming how many endpoints were probed out of
how many, so a run cut short never reads as clean. Findings on the endpoints
that were reached are still reported.

readCapped now cancels the reader in a finally block, so a read that aborts
or errors partway releases the connection instead of waiting for GC.

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

nc9 commented Oct 8, 2026 •

Copy link
Copy Markdown
Contributor Author

Reply to the fourth review. The fix is in e18328a, now the head:

  • (medium) A run that the budget cut short reported a pass: fixed in both rules. When the budget runs out partway and nothing was flagged on the endpoints reached, the rule records a skipped check with reason probe-budget, for example The probe budget ran out after 1 of 2 GraphQL endpoint(s). None of those probed returned its schema, but the rest were not checked. Findings on endpoints that were reached are still reported. Test: "a budget that runs out mid-run skips instead of passing", in both rule suites. The rule pages are updated.
  • (low) The reader was not released on an aborted read: fixed. readCapped now cancels the reader in a finally block. Test: "a body read that fails partway is reported as an error, not thrown".
  • (low) robots.txt at active versus aggressive: already covered by "robots.txt disallowed paths are skipped below aggressive and kept at aggressive" and "robots.txt disallowed endpoints are not probed below aggressive".
  • (low) Broad state-changing words: kept. They fail safe, the rule pages say which paths are never probed, and the skips are counted in details.skippedStateChanging.
  • (low) Introspection only counted on a 2xx: kept on purpose. A schema with an error status is rare, and requiring 2xx keeps false positives down.
  • (low) A discovered candidate with no method: the method is unknown when it comes from a string literal or a link. The path filter is the guard, and only read-only operations are ever sent.
  • (nit) Message when no type name was seen: it reads "too large to count (answered over GET)", which is correct.
  • (nit) /mutation/i: kept, as noted in earlier replies.

@claude

claude Bot commented Oct 8, 2026

Copy link
Copy Markdown

Review of the GraphQL probing rules. I read the two rules and `graphql-probe.ts` closely. I skimmed the docs and tests and didn't run the suite.

The design is careful. Requests come from a fixed operation enum, so no other query can be sent. Candidates get a strict same-origin re-check, the state-changing-path denylist, and a robots.txt check. Requests omit credentials, don't follow redirects, and have a body cap and a timeout. Response parsing is strict, and a budget-truncated run reports `skipped` instead of a clean pass. I found nothing that should block the merge.

  • (low) `graphql-probe.ts` `truncatedSchemaTypeNames`: the `"name":"..."` regex runs over the whole truncated prefix. Field, argument and enum-value names also match it, so `types` and `apiTypes` can overcount. The docs and message call them "at least N types seen", i.e. lower bounds, but they are neither. Either describe them as approximate, or drop the count and only say "larger than 1 MB".
  • (low) `graphql-get-mutations.ts` and `graphql-introspection.ts`: when some endpoints fail and others are skipped because the budget ran out (`exposed.length > 0 && budgetStopped`), no `skipped` check is added. The report shows findings but nothing says the remaining endpoints weren't checked. A budget note alongside the findings would keep the report honest.
  • (low) `graphql-probe.ts` `STATE_CHANGING_WORDS`: whole-word matching on `set`, `pay`, `write`, `clear`, `edit`, `save` and `create` will skip legitimate endpoints such as `/graphql/set` or `/api/pay/graphql`. Skipping errs on the safe side, but `skippedStateChanging` counts are only visible in `details`. Consider mentioning the count in the pass message so the skip isn't silent.
  • (nit) `graphql-probe.ts` `sendGraphqlProbe`: `probe.record()` runs before `fetch`, as the comment says. If `buildGraphqlProbe` threw, the budget would not be consumed. That can't happen for current inputs, so it's fine.
  • (nit) `graphql-probe.ts` `isRobotsTxtDisallowed`: it is checked against the query-less URL. That's right for the path, but a comment would help, since the real request carries `?query=`.
  • (nit) `graphql-introspection.ts` `probeEndpoint`: if the aggressive POST isn't sent because the budget ran out, the endpoint is reported as `graphql` with no schema. That's slightly optimistic. It's an edge case, but it could count as `budgetStopped`.

Test coverage looks solid. There are dedicated test files for each rule and for the helper, plus a local GraphQL server helper and an updated golden test. I'd add a test for the `exposed` plus `budgetStopped` combination.

nc9 commented Oct 8, 2026 •

Copy link
Copy Markdown
Contributor Author

Reply to the review of e18328a. It has no critical, high or medium findings, so nothing is pushed for it.

  • (low) truncatedSchemaTypeNames overcounting: this does not happen. The only query sent is {__schema{types{name}}}, so the answer holds type names only, with no fields, arguments or enum values. Every "name":"..." pair in the prefix is a type name, and because a cut answer is missing the types past the cap, the count is a true lower bound.
  • (low) Findings plus a budget stop: kept as is. The findings are reported and the run's details carry budgetStopped. A run that found an open endpoint is already a finding, so a second skipped check would add noise to the report. A run with no finding that was cut short is skipped (e18328a).
  • (low) Broad state-changing words: kept, as in the earlier replies.
  • (nit) record() before fetch: as you say, buildGraphqlProbe cannot throw for the fixed inputs.
  • (nit) robots.txt is checked on the URL without its query string: robots.txt rules in this repo are matched on the path, which is the same for the request.
  • (nit) A POST the budget blocked: partly correct. If any GET after it is refused, budgetStopped is set and a run with no finding is skipped. If the blocked POST belongs to the last endpoint, the run can still pass. That needs an aggressive run, a GraphQL-shaped GET without a schema on the last endpoint, and the budget ending between that GET and its POST. The fix is about 3 lines (treat a refused POST as budgetStopped). It is listed for the maintainer, because this PR has used its review rounds.

@nc9
nc9 merged commit 2e2e102 into main Oct 8, 2026
15 checks passed
@nc9
nc9 deleted the claude/graphql-probe-rules-t662nl branch October 8, 2026 21:33
nc9 pushed a commit that referenced this pull request Oct 9, 2026
* origin/main:
  feat(core-contracts): audit levels definition (quick, surface, full) (#602)
  test(rules): restore the real fetch when a graphql test stubs twice (#599)
  chore(release): v0.0.107 (#595)
  docs(changelog): release notes for v0.0.107 (#594)
  feat(rules): add GraphQL introspection and GET mutation probing rules (#593)
  fix(audit-engine): keep paid cloud prefetch results when the phase is abandoned (#582)
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