Skip to content

feat(gate-7): a guard the caller decides is not a per-object guard - #751

Merged
rubenvdlinde merged 4 commits into
mainfrom
feat/gate7-request-sourced-object-guard
Sep 11, 2026
Merged

rubenvdlinde merged 4 commits into
mainfrom
feat/gate7-request-sourced-object-guard

Conversation

@rubenvdlinde

@rubenvdlinde rubenvdlinde commented Sep 11, 2026 •

Copy link
Copy Markdown
Contributor

What

gate-7 no-admin-idor gains a rule: request-sourced-object-guard. A guard whose comparison value the caller supplies, and which therefore cannot refuse anybody, no longer counts as a per-object guard.

It ships warn-only.

Why

dossiq InspectionChecklistController::submitResult() is routed, carries #[NoAdminRequired], and writes an inspectionResult against a case id the caller chooses. Its guard:

$params = $this->request->getParams();
if ($this->groupManager->isAdmin($user->getUID()) === false) {
    $assignedUid = $params['assignedInspector'] ?? '';
    if ($assignedUid !== '' && $assignedUid !== $user->getUID()) {
        throw new OCSForbiddenException('Not authorized ...');
    }
}

There is no input for which that throws. Omit assignedInspector and the !== '' conjunct is false. Send your own uid and the second conjunct is false. assignedInspector is not even a property of the inspectionResult schema, so nothing server-side was going to be compared against it.

gate-7 reported PASS on it every run from 2026-08-11 to today. It cleared at the coarsest layer: _GUARD_BODY_RE matched OCSForbiddenException, and _guard_body_is_credible agreed the body consults identity. It does. $user->getUID() is right there. Pattern 7 would have cleared it too, because _has_ownership_comparison_guard asks only whether one side is an identity, never where the other side came from.

ConductionNL/dossiq#799. Fixed in ConductionNL/dossiq#2451.

The rule, and why it is spelled so narrowly

"Compared against request input" alone is unusable. Both of these are request-sourced and both are correct:

if ($userId !== $user->getUID()) { throw; }   // $userId IS the lookup key
$doc = $this->mapper->find($id);              // $id is caller-supplied,
if ($doc->getOwner() !== $uid) { throw; }     // $doc is STORED STATE

So three things had to be true together.

Taint stops at a call. A value that came out of a lookup is stored state, whatever caller-supplied id was used to fetch it. Without that stop the second shape above reddens fleet-wide.

Request-sourcedness is asked before identity-ness. _is_identity_expression reads any $...Uid name as an identity, so in dossiq's own condition both sides qualify. Classifying by identity first picked $user->getUID() as the other side, found it not request-sourced, and cleared the very defect the rule exists for.

The compared value must decide nothing. It reaches no call, steers no lookup, lands in no payload. $userId above fails this immediately, which is how the correct shape stays green.

Why it reports before the clearing patterns

Every other pattern answers "is this endpoint guarded somewhere?". This one answers "does this method contain a per-object check that cannot refuse?", and the two are independent. dossiq's method proved it: once the comparison was demoted, four separate patterns still cleared it. A same-class helper, a collaborator, Pattern 2b's OpenRegister delegation, and Pattern 6's session hand-off. Spelled as "report unless something else clears it", the rule reported nothing and the gate stayed as blind as before.

A comparison that can never refuse is dead authorization code even when a real guard sits beside it. That is gate-9 orphan-auth's premise. It is worse than an absent guard, because the next author opens the file and reads "already guarded".

A documented @no-admin-idor-exempt still wins, because it is read first.

Warn-only, and what that bought

All 21 core apps set enable-hydra-gates: true and resolve this package at @main, so a blocking rule is blocking everywhere the minute it merges. Gates 112 and 113 failed 14 of 21 that way.

Measured before merge, 20 core apps, 761 lib/Controller files, baseline and the checker as it stands in this PR, side by side:

app controller files baseline this PR new rule
launchpad 47 0 1 1
openregister 144 0 0 0
every other core app 570 0 0 0
total 761 0 1 1

dossiq is separate: 0 before, 1 after, and the 1 is the real defect.

An earlier draft of this rule scored three, and reading those three is what narrowed it. The intermediate numbers are recorded here because the narrowing is the interesting part, not the final count.

openregister OrganisationController::join() and ::leave() scored 2 and both were correct code. They fired on a prong that is now gone: "a presence test lets absence skip the branch" started as an independent tell, and those two are exactly that shape. Omitting userId does skip the refusal, and the callee resolves an absent target to the session user with $targetUserId ?? $currentUser->getUID(). A value the callee receives is a parameter, not a decoration. Requiring "decides nothing" removed both and kept dossiq, and openregister is back to 0 in the table above.

launchpad AcknowledgementController::acknowledge() is the one that remains, and it is a false positive. The comparison really does decide nothing, because the write already takes $this->userId from the session. The rule is right about the comparison and wrong about the risk. It cannot tell the two apart without knowing which object the write targets. The runner's warning text names this shape so a triager recognises it in one read.

Set HYDRA_GATE_IDOR_REQUEST_SOURCED_BLOCKING=1 in a repo to make it block there once that repo's population is worked down.

Verification

python3 scripts/lib/test_check_no_admin_idor.py : 191 passed, was 181. Ten new cases, three positive and seven negative.

Mutation-checked, three ways, each restoring byte-identical:

mutation reddens
rule disabled the 3 positives, nothing else
"decides nothing" requirement dropped the openregister arm, plus 2 more negatives
taint propagated through calls the stored-state arm

New acceptance bundle request-sourced-guard, driven through the real wrapper. Planted scores 2 under this checker and 0 under the previous one, so the fixture proves the fix rather than passing alongside it. Clean scores 0. prefs() and join() sit unflagged in the planted arm, so an over-broad rule cannot score here either.

bash scripts/lib/test_gate_acceptance_matrix.sh : 260 passed, 0 failed, 88 of 95 gates fixtured.

bash scripts/lib/check_gate_numbers_unique.sh : 95 gates, every number claimed once.

gate-7 still emits exactly one verdict line, checked by _assert_one_verdict_per_gate. The advisory is an elif rather than an extra line, because _warn and _pass both append to _EMITTED_GATES and the coverage summary counts that list without deduplicating.

Next

Merge, then watch the three findings across the fleet. When launchpad's is cleaned up or waived and openregister stays at zero, flip HYDRA_GATE_IDOR_REQUEST_SOURCED_BLOCKING=1 per repo, starting with dossiq.

🤖 Generated with Claude Code

gate-7 accepted any identity comparison as a per-object guard without asking
where the compared value came from. dossiq `InspectionChecklistController::
submitResult()` is routed, `#[NoAdminRequired]`, writes an `inspectionResult`
against a caller-chosen case id, and reads the permitted inspector out of
`$this->request->getParams()`. There is no input for which it refuses. gate-7
reported PASS on it every run from 2026-08-11 until today.

The new rule demotes a refusal branch when every identity comparison in its
condition puts a caller-supplied value on the other side AND that value is
used nowhere else in the method. Demotion is spelled as blanking, the same way
`.github#365` blanked authentication, so every later pattern still gets its
say: a method that also delegates to a real collaborator guard, or reaches
OpenRegister's RBAC, still clears.

Request-sourcedness is asked BEFORE identity-ness, and that order is the rule.
`_is_identity_expression` reads any `$...Uid` name as an identity, so in
dossiq's own condition both sides qualify. Classifying by identity first picked
`$user->getUID()` as the other side, found it not request-sourced, and cleared
the very defect this exists for.

Taint does not propagate through a `->` or `::` call. A value that came out of
a lookup is stored state, whatever caller-supplied id was used to fetch it.
Without that stop the canonical correct guard reddens fleet-wide.

The finding is reported before every clearing pattern, not after. dossiq's
method proved why: once the comparison was demoted, four separate patterns
still cleared it, so an "unless something else clears it" spelling reported
nothing and the gate stayed as blind as before. A comparison that can never
refuse is dead authorization code even when a real guard sits beside it, and it
is worse than an absent one, because the next author reads "already guarded".

WARN-ONLY, per the rule that a new gate ships as a warning. All 21 core apps
resolve this package at @main, so a blocking rule is blocking everywhere the
minute it merges. Measured across the 20 other core apps, 761 lib/Controller
files: three findings. dossiq's real one, and two in openregister
`OrganisationController` that are correct code. Set
HYDRA_GATE_IDOR_REQUEST_SOURCED_BLOCKING=1 per repo to block there.

That measurement bought the narrowing. "Decides nothing" started as one of two
alternative tells, alongside "a presence test lets absence skip the branch".
openregister's `join()` and `leave()` are exactly the second shape and exactly
correct: omitting `userId` does skip the refusal, and the callee resolves an
absent target to the session user. A value the callee receives is a parameter,
not a decoration, so "decides nothing" is now required.

Evidence: 10 new unit cases, 3 positive and 7 negative, all mutation-checked.
Disabling the rule reddens the 3 positives and nothing else. Dropping the
"decides nothing" requirement reddens the openregister arm and two more.
Propagating taint through calls reddens the stored-state arm. A new acceptance
bundle runs the real wrapper: planted scores 2 under this checker and 0 under
the previous one, clean scores 0, and `prefs()` and `join()` sit unflagged in
both arms so an over-broad rule cannot score here. Full matrix: 260 passed, 0
failed, and gate-7 still emits exactly one verdict line.
…ization

Work in progress, committed by the parent session to preserve it across a
session restart. The agent continues from here.
The warn-only block still quoted the pre-narrowing measurement. Requiring
"decides nothing" removed both openregister findings, so the fleet population
is one line: launchpad `AcknowledgementController::acknowledge()`, and that one
is a false positive of the shape the triage text already names.

Re-measured against the checker as it now stands, 20 core apps, 761
lib/Controller files: launchpad 1, openregister 0, everything else 0. dossiq is
counted separately at 1, and that one is real.

Comment-only. `bash -n` clean.
…that proved it

CI caught this and my local run had not: `test_gate_discarded_counts_and_empty_deltas.sh`
refuses any new `_warn` call site unless the gate is named in
`_ADVISORY_ALLOWED_GATES` with its reason. That is exactly the guard it should
be, and gate-7's demotion was undeclared.

Gate-7 is now listed, and the entry records that the demotion is PARTIAL: only
`request-sourced-object-guard` is advisory. Gate-7's own `no-auth-guard-in-body`
findings still fail in the same run, because the runner splits the two
populations into separate logs. So this is the ship condition for a widening,
not a demotion of the gate.

The positive control had to move with it. It planted a second `_warn` on
GATE-7 specifically, to prove the allowlist can refuse. With gate-7 allowlisted
that plant produced a set the allowlist accepts, so the arm proved nothing and
said so. It now plants on gate-8, which is blocking and has no business ever
being advisory, and its failure message tells the next reader to repoint it
rather than delete it.

Both arms were watched failing before being fixed: the allowlist arm reddened
on the undeclared demotion, and the control arm reddened the moment it became
vacuous.

Verified: the suite reports 37 assertions, 0 failures. ShellCheck clean on both
changed scripts.
@rubenvdlinde
rubenvdlinde merged commit 5c1f46f into main Sep 11, 2026
40 checks passed
rubenvdlinde added a commit to ConductionNL/dossiq that referenced this pull request Sep 11, 2026
…2465)

InspectionChecklistController::submitResult() is routed, #[NoAdminRequired], and
writes an inspectionResult against a case id the caller chooses. Its guard read
the permitted inspector out of the request body, so the value it compared the
caller against was supplied by the caller it was meant to constrain. It failed
open two ways: omit assignedInspector and the !== '' conjunct short-circuits,
or name yourself and the comparison passes. assignedInspector is not a property
of the inspectionResult schema, so nothing server-side was ever compared to it.

The guard now asks CaseAccessGuard::hasCaseMutationAccess(), which loads the
case through OpenRegister and compares the acting uid against the stored
assignee. Admins bypass; an absent OpenRegister or an unresolvable case denies.
The decision is taken before the payload is read, so no field the caller sends
or omits can reach it.

Fixed with it, on the same surface:
- AdviceController::createForCase() had no per-case check at all, while its own
  sibling getForCase() already had one. It now requires mutation access.
- InspectionChecklistService wrote caseRef/checklistRef where the schema
  requires case/checklist, so every submission was rejected and none stored.

The spec was silent on who may submit, so the rule is now a requirement with
scenarios in openspec/specs/inspection-checklists/spec.md.

Evidence. Unit: both halves of the bypass pinned as separate cases, and
mutation-checked by restoring the original guard, which turned all five refusal
assertions red while acceptance stayed green; restored byte-identical. E2E with
two real non-admin accounts, one written into the case's stored assignee and one
named nowhere: all five pass on the merge head, 378 passed / 21 skipped / 0
failed / none left unrun across the suite. Accounts are provisioned over basic
auth, because the admin session captured at the start of the run outlives
Nextcloud's thirty-minute password-confirmation window by the time this spec
runs. gate-7 PASS under the newly merged request-sourced-object-guard rule
(ConductionNL/.github#751), which flags the pre-fix file.

Found and filed separately: LhsController::override() has no per-case guard (#2467).

Closes #799
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant