# Live verification and reporting

## Safety rules — read before sending anything

1. **Own instance only.** Stand up the app locally (`docker compose up`, `bin/rails s`,
   `bundle exec rackup`, whatever the repo's README says) and test there. A finding in this
   class writes and destroys records; a production or shared instance is not a lab.
2. **Never touch data you did not create.** Make your own scratch tenant/project/user as the
   "victim". Record every object you create and every state you change.
3. **Canary before payload.** Prove the *write* with the most boring method that persists —
   `touch` (bumps `updated_at`, nothing else) — before you go near `destroy`, `block` or a
   state machine. If `touch` does not move the timestamp, you have not proven a write and
   nothing downstream is safe to claim.
4. **Do not run the amplified form.** `{ collection { nodes { destroy } } }` against a live
   dataset is not a proof, it is an outage. Prove it once against one scratch object, then
   *print* the amplified document without executing it and say so in the report.
5. **Restore what you change**, and list in the report anything you could not restore.
6. Confirm the target is in scope for whatever authorization you are working under before
   the first request. If the repo is a third-party open-source project rather than something
   you or your employer run, there is no live target to test — reproduce against your own
   local checkout and report to the project's security contact
   (`SECURITY.md`, `security@`, or a GitHub/GitLab private advisory).

## Step 1 — find the endpoint

Do not assume `/graphql`. In an unfamiliar app:

```bash
# where the schema executes — the surrounding code also shows how `context:` is built
rg -n '\w*Schema\.(execute|multiplex)\(' --type ruby
# how it is mounted (Rails routes, Rack map/run, Sinatra/Hanami verbs)
rg -n -i '(post|get|match|map|mount|run)\s+["\x27/][^\n]*graphql'
# and confirm from the outside
curl -s -o /dev/null -w '%{http_code}\n' -X POST http://127.0.0.1:PORT/graphql \
  -H 'Content-Type: application/json' -d '{"query":"{__typename}"}'
```

Expect **more than one** entry point in a mature app: an HTTP controller, a websocket/
ActionCable channel, an internal service wrapper, a background job. Each builds `context`
separately, so each has its own answer to "who can trigger this" — and the weakest one sets
the reporter position you report.

## Step 2 — the control/test method

Every claim is a **pair** of requests differing in exactly one thing: the trigger.
`scripts/probe.sh` automates this and classifies the outcome; by hand it is:

```bash
GQL=http://127.0.0.1:PORT/graphql            # from step 1
q() { curl -s -XPOST "$GQL" -H 'Content-Type: application/json' \
        -d "$(jq -Rn --arg q "$1" '{query:$q}')"; }

# CONTROL — no trigger. MUST be rejected.
q '{ widget(id:"scratch") { id touch } }'
# => {"errors":[{"message":"Field 'touch' doesn't exist on type 'Widget'", ...}]}

# TEST — identical document plus the trigger.
q '{ __typename widget(id:"scratch") @introduced(version:"99.0.0") { id touch } }'
# => {"data":{"widget":{"id":"scratch","touch":true}}}
```

If the control does **not** produce the ordinary `Field 'x' doesn't exist on type 'Y'`
rejection, stop — you are measuring the wrong thing (the field may genuinely exist, or your
document is malformed).

Adapt the trigger to the app: a directive, a header, a query param, a context key set by
middleware, or a `validate: false` code path.

**Distinguish two positive results.** A fabricated field whose name matches no method on
either receiver still *resolves* — it returns `fallback_value`, i.e. `null`. That proves the
validation hole (report it) but proves **no invocation**. Only a non-null return shows a
method ran.

## Step 3 — observe the side effect out of band

An in-band `true` only proves the method returned a truthy value. Observe the effect through
a **different** channel, whatever the app provides:

- **REST/HTTP** — re-read the object through the app's own API as a privileged user.
- **Database** — query the row directly (`psql`, `sqlite3`, `rails db`, `Sequel`), which is
  the most portable and the least deniable.
- **A console** — `bin/rails runner`, `irb -r./config/environment`, `bundle exec ruby -e`.
- **Logs / filesystem / a listener** — for effects that leave the process (a delivered
  webhook, a sent mail, a spawned job). Netcat on a local port beats trusting a log line.
- **The app's own UI**, screenshotted before and after.

Per effect type:

- `touch` → read the timestamp column before and after.
- `destroy` → re-fetch as a privileged user afterwards → expect not-found.
- state machine → read the state column directly, before and after.
- credential mint/rotate → prove the old credential now fails and/or the new one works.
- authorization widening → the read that returned 403 now returns 200.

## Evidence to capture

Most programs will close a write-up with no artifacts as N/A, and some forfeit
first-reporter status for duplicates on that basis. Capture:

- The exact request (headers included — **especially** the absence of `Authorization`) and
  the exact response, for both control and test.
- The out-of-band before/after observation, timestamped.
- Version/commit of the target (`git rev-parse HEAD`, the app's version endpoint).
- A re-runnable script that sets up its own scratch fixture, proves the primitive
  non-destructively, and cleans up on exit (`trap cleanup EXIT INT TERM`).
- Screen capture or terminal recording if the program asks for it.

## Establishing anonymity precisely

If you are claiming unauthenticated reach, say it in a way that is checkable: no
`Authorization` header, no API-key header, no session cookie, no CSRF token, on **every**
request in the chain including any setup you attribute to the attacker. Keep privileged
credentials strictly to fixture setup and out-of-band observation, and label those lines as
such in the script so a reviewer can see the attacker path never used them.

State the reporter position exactly, in the app's own vocabulary: anonymous /
authenticated-but-unrelated / lowest-privilege-role-with-access. "Unauthenticated" and
"authenticated but not a member" are very different severities, and guessing high is the
fastest way to have the whole report discounted.

## Report skeleton

```markdown
# <one line: what an attacker does, and to whom>

| | |
|---|---|
| Asset / component |  |
| Version / commit  |  |
| Class             | CWE-470 Unsafe Reflection · CWE-862 Missing Authorization · CWE-306 |
| Severity          | CVSS vector + the one sentence that justifies each metric |
| Reporter position | anonymous / authenticated-no-membership / guest — be exact |
| Preconditions     | feature flags, licence tier, non-default config — "none" if none |

## Summary
The root cause in two mechanisms, with the code quoted. Name the invariant that is broken.

## The primitive
One indented paragraph stating exactly what the attacker gains, and immediately after it,
what the primitive still cannot do.

## Reproduction
Numbered, each with its negative control, each with the out-of-band observation.

## Impact
Named receiver × named method × measured outcome. Confidentiality, integrity and
availability each with at least one demonstrated instance if you have one.

## Scope limits and what still holds
The guards that survive. The chains that are code-supported but unverified — label them.

## Same root cause — do not file separately
The other consequences of the same defect (recursion DoS, 500s, cost-control bypass, log
blinding, multiplex bleed). One mitigation ⇒ one report under most programs' duplicate rules.

## Fix
Ordered, with which options close which half.

## Instance state changed during verification
Every object created, mutated or destroyed, and whether it was restored.
```

## Fix recommendations that actually close it

Ranked. Give all of them; say which closes which half.

1. **Do not let a client trigger the split at all** — gate the directive/header behind a
   feature flag or a trusted-client check. It is usually a deploy-coordination mechanism that
   no external caller needs.
2. **Validate and analyze the same document that executes.** This is the only option that
   closes the whole class — it takes back `FieldsAreDefinedOnType`, `FragmentsAreFinite`,
   `DirectivesAreDefined`, the cost controls and the query log in one move. A fix that only
   hardens the synthesized field leaves the recursion DoS, the 500s and the log blinding live.
3. **Make any synthesized field genuinely inert.** It must not be able to reach the
   application object at all. `method: :itself` is **not** sufficient. Give it a
   `resolver_method` defined on the type that unconditionally returns `nil`, or a `hash_key:`
   into a frozen empty hash. Note explicitly that changing only the *return type* is not a
   fix — the type is doing double duty (exfiltration width **and**, via `connection?`,
   argument suppression) and that is a fragile place to rest a security property.
4. **Hold per-query state per query**, not on the trace object, since one trace serves a whole
   multiplex.

## Common review objections, pre-answered

- *"`public_send` only calls public methods."* False as a security boundary — see
  `gem-internals.md` on `Delegator` + ActiveSupport `delegate`. The real guard is arity.
- *"Type authorization protects it."* Type authorization bounds the **receiver set**; it does
  nothing about which method is called on a receiver you were already given.
- *"The return type is only Boolean, so nothing leaks."* Correct for *return-value*
  exfiltration and irrelevant to **side effects**. A `destroy` that returns `true` has already
  happened. Also note the three-state coercion is a usable attribute oracle.
- *"It needs authentication."* Check author/committer/snippet paths before conceding this;
  they routinely expose user objects to anonymous callers.
- *"The page size bounds the amplification."* Not when the same defect also bypasses
  `max_page_size`, `max_depth` and `max_complexity`.
