Repository navigation
feat(rules): add GraphQL introspection and GET mutation probing rules - #593
Conversation
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]>
|
Reviewed the diff and read 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
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. |
|
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:
Status: all criteria in the PR body have tests. Format, lint, typecheck and sign-off checks pass, and the remaining CI jobs are running. |
|
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. |
|
Review of #593 (GraphQL introspection and GET-mutation probing rules). I read the full diff of 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.
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]>
|
Reply to the second review. Commit b7b001e is about to be pushed:
|
Signed-off-by: Nik Cubrilovic <[email protected]>
|
Reviewed the two rules and the shared
|
…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]>
|
The medium finding about an introspection answer over 1 MB is now handled as its own truncated verdict in 42cf8b4, the PR head.
Tests:
The rule page documents the verdict. main was already merged in, so this is one push. |
|
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.
|
|
Review of the GraphQL probing rules ( 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.
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 |
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]>
|
Reply to the fourth review. The fix is in e18328a, now the head:
|
|
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.
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. |
|
Reply to the review of e18328a. It has no critical, high or medium findings, so nothing is pushed for it.
|
* 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)
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 apassiverun, or with no probe budget, each records one skipped check and sends nothing.security/graphql-introspection(warning, weight 5): oneGET /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 anaggressiverun only, onePOSTof the same read-only query follows when theGETanswer is GraphQL-shaped without a schema and does not say introspection is disabled.security/graphql-get-mutations(error, weight 7): oneGET /graphql?query=mutation{__typename}per endpoint. Fails when the server executes it (data.__typenameis the mutation root). Never sends aPOST.packages/rules/src/security/graphql-probe.ts: candidate selection from the endpoint discovery pass plus/graphqland/api/graphql, strict same-origin re-check (probeEligibleis not trusted as safe-to-send), never a path naming a state-changing action (logout, delete, update, reset and similar, whole words) or aPUT/PATCH/DELETEcall site,robots.txtrespected belowaggressive, 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 onlydata/errors/extensions, every error carrying amessage, 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 forfields{name}would make both the request and the answer larger.Acceptance criteria
Shared helper
packages/rules/src/security/graphql-probe.ts;packages/rules/tests/graphql-probe.test.ts(19 tests).security/graphql-introspection
?query={__schema{types{name}}}, to discovery candidates or conventional paths; state-changing call sites never probed; same-origin enforced by the helper, not byprobeEligible. 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".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".8 types, 4 of them defined by the API, item meta).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
mutation{__typename}, as a GET, to GraphQL candidates; state-changing candidates never probed; same-origin only;probeEligiblenot 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 isquery=mutation{__typename});graphql-probe.test.ts"the no-op mutation is GET only".mutation_root,RootMutationType,MutationRoot), "405, POST-only errors, introspection-style errors and query answers are not flagged".graphql-probe.test.ts"HTML, catch-all, REST and JSON:API bodies are not GraphQL".make validatepasses. 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
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, thentests/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 typecheckin packages/rules and packages/audit-engine: clean. Rootbun run format:checkandbun run lint: clean; oxlint with the CLI config on the new files: clean.detect-secrets-hook --baseline .secrets.baselineon changed files: clean (one test URL withuser: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 activeor higher.Checklist
Signed-off-byline (git commit -s).Generated by Claude Code