# graphql-ruby unsafe-dispatch audit kit

Tooling for finding **unsafe dispatch** and **validate-vs-execute divergence** bugs in Ruby
applications that use [graphql-ruby](https://graphql-ruby.org/).

Published by [PlatformSecurity](https://platformsecurity.com) alongside the write-up of
**CVE-2026-19478**, an unauthenticated arbitrary-method-invocation bug in GitLab (CVSS 9.4,
patched 2026-08-17) that this kit was built while investigating:

> <https://platformsecurity.com/blog/cve-2026-19478-gitlab-graphql-unsafe-reflection>

## The bug class in one paragraph

graphql-ruby resolves a field by calling a method **named after the field** on the type
wrapper and then on the application object (`public_send`). The only thing that keeps a
client from choosing that method name is the static validation rule `FieldsAreDefinedOnType`,
which runs against the parsed document before execution. Any app-level customization that
(a) lets a field definition be *fabricated from a name the client supplied*, or (b) makes the
document that **validates** differ from the document that **executes**, turns that into
client-chosen method invocation on server objects. Field and type authorization do not stop
it: the fabricated field carries no `authorize`, and the call happens on a parent object that
was already authorized.

**The invariant to test a repo against:**

> The document that static validation and every query analyzer inspect must be byte-for-byte
> the document the interpreter executes, and no field definition may ever be derived from a
> name that was not in the schema at boot.

## What's here

| File | What it does |
|---|---|
| `SKILL.md` | The method: six steps from "does this repo use graphql-ruby" to a written report. Formatted as an agent skill, but it reads fine as prose. |
| `references/patterns.md` | Ten patterns (P1–P10) with the grep signal, the gem-side mechanics, the questions that separate a finding from a false positive, and the confirmed real-world instance. |
| `references/gem-internals.md` | The resolution order, the hook table, and the arity argument. Read before writing any claim about what `public_send` can reach. |
| `references/verification.md` | Safety rules, the control/test method, out-of-band observation, evidence to capture, a report skeleton, and pre-answered review objections. |
| `scripts/scan.sh` | Read-only ripgrep sweep. Finds the extension points, grouped by pattern ID. A lead generator, not a verdict. |
| `scripts/census.rb` | Loads your app and enumerates the methods the primitive could reach: public, zero-required-argument, `!`/`?`/`=`-free, per receiver, tagged with the gem that defined each one. |
| `scripts/probe.sh` | Paired control/test prober for a live endpoint. Distinguishes "method invoked" from "validation hole but this gadget didn't fire". |
| `scripts/cve-2026-19478-check.sh` | One-bit non-destructive check for the specific GitLab CVE. |

## Quick start

```bash
# 1. sweep a checkout  (needs ripgrep)
./scripts/scan.sh /path/to/repo

# 2. enumerate what a primitive could reach  (needs the app to load)
bin/rails runner scripts/census.rb > census.json                       # Rails
CENSUS_BOOT=./config/environment.rb bundle exec ruby scripts/census.rb # anything else

# 3. prove it live against your own instance  (needs curl + jq)
./scripts/probe.sh --url http://127.0.0.1:3000/graphql \
                   --path 'project(fullPath:"scratch/p")' \
                   --method touch \
                   --trigger 'directive:gl_introduced=version:"99.0.0"'

# or, for the GitLab CVE specifically
./scripts/cve-2026-19478-check.sh https://gitlab.example.com scratch/p
```

## Three things that will save you a bad report

1. **Never report a static reading of this class.** The gap between "the validator is
   bypassed" and "a method executed" is one request, and it is the request triage will ask
   for. Always send the pair, control first.
2. **A fabricated field that returns `null` is not an invocation.** It proves the validation
   hole — which is real and reportable — but that name fell through to the fallback, meaning
   no such method on either receiver. `probe.sh` separates these on purpose.
3. **State your limits yourself.** Which guard still holds, which chain is code-supported but
   unverified, why it is or is not RCE. Under-claiming a critical finding costs nothing;
   over-claiming one gets the whole report discounted.

## Scope and safety

These scripts are for auditing code you own or are authorised to test.

`scan.sh` and `census.rb` are read-only with respect to the target application (`census.rb`
loads your app in order to reflect on it, so run it in a development environment, not
production). `probe.sh` and `cve-2026-19478-check.sh` send requests to an endpoint you
specify and, if the target is vulnerable, will **invoke a method on it** — that is what they
are measuring. Both default to the harmless `touch` canary, and `probe.sh` refuses obviously
destructive method names unless you pass `--i-know`.

Stand up a disposable instance, create your own scratch objects to act as the victim, and
restore anything you change. `references/verification.md` has the full list.

## Licence

Released for public use, as-is and without warranty. Attribution appreciated but not
required. If it finds you something, we'd like to hear about it:
<https://platformsecurity.com/demo>
