Skip to content

fix(graphql): enforce update auth on existing nodes linked via @hasInverse#9761

Open
kike-loco wants to merge 1 commit into
dgraph-io:mainfrom
kike-loco:fix/nested-auth-insertions
Open

fix(graphql): enforce update auth on existing nodes linked via @hasInverse#9761
kike-loco wants to merge 1 commit into
dgraph-io:mainfrom
kike-loco:fix/nested-auth-insertions

Conversation

@kike-loco

Copy link
Copy Markdown

Summary

Fixes a false accept security gap in GraphQL add mutations: when a nested insert links to an existing parent via @hasInverse, Dgraph mutates the parent's inverse predicate but previously only ran @auth add checks on newly allocated UIDs. Protected parents were never validated, allowing unauthorized users to modify admin-only nodes indirectly.

Example bypass (now blocked):

mutation {
  addFooItem(input: [{ parent: { id: "foo1" } }]) { numUids }
}

…when ProtectedFoo requires admin for both add and update.

  • Track affected existing nodes during mutation rewrite when asIDReference() adds an inverse link to an existing UID (mutation_rewriter.go)
  • After authorizeNewNodes(), run authorizeAffectedNodes() using update rules on those nodes (mutation.go)
  • Scope affected-node auth to add mutations only to avoid breaking update mutation flows

Related discussion: https://discuss.dgraph.io/t/bug-auth-rules-of-parent-not-respected-when-child-with-hasinverse-is-added/12955

Test plan

  • Unit rewrite tests: go test ./graphql/resolve -run 'TestAddChildRecordsAffectedProtectedParent|TestNestedAddRecordsDeepNewNodes' -count=1
  • Auth query rewriting: go test ./graphql/resolve -run TestAuthQueryRewriting/Add_Mutation -count=1
  • E2E integration: go test -tags=integration -run TestNestedAdd ./graphql/e2e/auth/... (requires Docker cluster with patched binary)

Made with Cursor

…verse

Nested add mutations could mutate protected parent nodes through inverse
edges without running the parent's update @auth rules. Track affected
existing UIDs during mutation rewrite and authorize them after add-node
checks, closing the false-accept bypass for hasInverse and deep nested inserts.

Co-authored-by: Cursor <cursoragent@cursor.com>
@kike-loco kike-loco requested a review from a team as a code owner June 21, 2026 08:10
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

1 participant