GeezerVison is showing github.com — Allow parsing of graphQL queries by dpup · Pull Request #14 · majorcontext/keep
Conversation
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
graphql(params.body) parses a GraphQL-over-HTTP request body into
{valid, error, operations, queries, mutations, subscriptions}. Each root
field carries its real name, alias, and args with variables and variable
defaults substituted. Every operation is reported regardless of
operationName, root fragment spreads and inline fragments are expanded,
and directives are ignored, so rules see every root field the document
contains. Malformed input returns valid=false with empty lists.
The function is registered for the original-params rewrite so it parses
the body as sent, even in case-insensitive scopes: GraphQL names and node
IDs are case-sensitive.
The rewrite now skips call text inside string literals and at the end of
longer identifiers; previously `'hasSecrets(x)'` in a literal was
rewritten and corrupted.
Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_0181tDqDyMAGnCcqMAd2JEWf
Engine.RequiresBodyFor(scope, call) narrows RequiresBody by operation: a
rule that reads params.body counts only when its operation glob matches
the call (normalized as Evaluate normalizes it). Pinning a body rule to
one endpoint, e.g. `post api.github.com/graphql`, lets a gatekeeper
buffer bodies for that endpoint alone instead of making the whole scope
JSON-only. An unknown scope returns true.
Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_0181tDqDyMAGnCcqMAd2JEWf
ValidateRuleBytes compiled each when expression as written, without
substituting defs or injecting original-case params, so a rule file
that LoadFromBytes accepts failed validation with "undeclared
reference". Both paths now prepare expressions through
keepcel.PrepareWhen.
Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_0181tDqDyMAGnCcqMAd2JEWf
claude
Bot
commented
Nov 2, 2026
•
edited
Loading
Uh oh!
There was an error while loading. Please reload this page.
|
Claude finished @dpup's task in 34s —— View job
Review of #14: graphql() request parser
I read the diff but didn't run the tests or linter. I found no blocking issues.
What I checked
- Fail-closed behavior:
ParseGraphQLRequest never errors. Malformed input returns valid=false with empty lists, so .exists() is safe.
- Operation reporting: Every operation in the document is reported regardless of
operationName. This closes the "run a different operation" bypass.
- Expansion limits: Fragment expansion is bounded by depth (32), a root-field cap (1000) and a cycle check. Every leaf of the expansion is a field, so the field cap also bounds fan-out from repeated spreads, and the 32-level depth cap keeps recursion shallow.
- Variable defaults:
lookup calls r.value(d.DefaultValue) on a default. gqlparser parses defaults as const values, so a variable can't appear there and the recursion can't loop.
RequiresBodyFor: It uses the same normalization as Evaluate, and an empty glob matches everything, as documented. An unknown scope returns true, which fails safe.
PrepareWhen: Sharing it between NewEvaluator and ValidateRuleBytes fixes the def-substitution validation mismatch.
Minor, non-blocking
findCall and raw strings (internal/cel/rewrite.go): The scanner treats \ as an escape in all string literals. CEL raw strings (r'a\') don't process escapes, so a raw string ending in a backslash could desync the quote tracking. If it does, the graphql( call after it would not be rewritten and would silently fall back to the lowercased body. The same escape logic already exists in the paren scanner, so this is an edge case. You could either handle the r/R prefix or add a test that documents the limitation.
- Lowercased variables on fallback (
originalGraphQLBody): When the heuristic falls back to the first argument, which is the case-normalized body, variable values are lowercased too. A policy that compares an argument supplied via a variable (such as a node ID) is then case-sensitive in one path and not in the other. This only happens when the argument isn't a plain params.X path. A line in the graphql() docs would help, if there isn't one already.
ValidateRuleBytes aliases: It passes nil aliases, so a profile alias used in a when expression is not resolved. This was already true before the PR. It's only worth a comment if aliases can appear in standalone rule files.
Otherwise the code is tidy. The tests cover cycles, limits and the rewrite edge cases, and the docs and CHANGELOG are updated.
|
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Assignees
No one assigned
Milestone
No milestone
Development
Successfully merging this pull request may close these issues.
Uh oh!
There was an error while loading. Please reload this page.
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
|