Repository navigation
fix(attention): refuse an acknowledgement whose caller id is not a user id (TASK-176) - #1986
Merged
Merged
Conversation
…er id (TASK-176) The guard `getOpenQueue` carries on its recipient was missing on the acknowledgement path, and what that omission actually does had to be measured rather than assumed. Probe on bbab5c3, acking another recipient's open item: caller=undefined -> {success:false,'Attention item not found'} row open caller=null -> {success:false,'Attention item not found'} row open caller='' -> THREW CastError row open caller='not-an-id' -> THREW CastError row open caller=<the owner id> -> {success:true} row resolved So the cross-recipient acknowledgement this was proposed for is NOT reproducible: the undefined and null filters are refused and the other person's row keeps its open status. What is real is the CastError out of the update for an id that is not an ObjectId — a client-side fact reported as a 500 'Failed to acknowledge attention'. The new guard refuses both shapes in the 400 lane, beside the item-id refusal that was already there. One existing unit arm used `'sam'` as the recipient placeholder in a mocked update; the guard now stops it before the update, and that arm's subject is the `$or` selector rather than the spelling of the id, so its fixture moved to a real ObjectId (the two neighbouring arms already used one). Test: backend/__tests__/service/attentionAcknowledgeRecipientGuard.test.js — four unusable caller ids refused with every planted row still open, plus the owner's own acknowledgement as the positive control.
…oreign id, owner control (TASK-176) connector-ops' 04:11Z correction executed the same probe and reached the same conclusion, and revised the arms: drop `undefined` and `null` (they pass against unguarded code, so an arm asserting them witnesses nothing), assert a typed refusal for `''`, and add the 12-character form. Adopted, with one addition measured here: `'507f191e810c'` does not throw — it casts to 353037663139316538313063, its own ASCII bytes read as the 12-byte form, so it is a valid ObjectId belonging to nobody. That is why the guard checks the canonical 24-hex shape rather than leaning on the cast. Arms now: three unusable caller ids each refused as `Invalid recipient` with all three planted rows still open; a valid id belonging to somebody else refused with the owner's own acknowledgement as the positive control (and a second acknowledgement refused, because the selector requires status 'open'); a malformed item id refused as `Invalid attention item` with the row untouched.
…ually rests on (TASK-176)
Vera's review of `5c068c37` found two survivors in the arms, and they reproduce
exactly as reported: with the trailing `$` dropped (`{24}$` -> `{24}`) a
25-character id passes the guard and the cast throws — straight back to the 500
this change exists to remove; with the leading `^` dropped, anything *preceding*
24 hex characters does the same. Neither is reachable from a real credential
(`getAuthenticatedUserId` returns `req.userId || req.user?.id || req.user?._id ||
null`), but the guard's whole value is refusal-instead-of-throw, and that value
was unwitnessed against the two edits most likely to be made when somebody copies
or tidies the regex.
Measured in that order, not asserted: this ledger run against the gated head had
M5/M6 surviving (`killed=False failed=0`); against this commit all six mutations
die inside the arm they name. `M4` (guard moved below the update) is included
because WHERE the guard sits is part of the guarantee — a refusal after the write
is not a refusal.
The two new caller shapes are 24 hex characters plus something:
'507f191e810c19729de860ea0' 25 chars — kills the end-anchor edit
'x507f191e810c19729de860ea' prefixed — kills the start-anchor edit
One existing assertion had to scale with the list: the planted rows' statuses
were asserted as a literal ['open','open','open'], which would have kept passing
for the wrong reason at five callers. It is now `callers.map(() => 'open')`.
Test-only: `backend/services/attentionItemService.ts` is byte-identical to
`5c068c37`. Not touched, and named as a residual rather than smuggled in:
`getOpenQueue:466` carries the identical regex with the identical gap.
5 neighbouring suites / 58 tests / 0 failed; `tsc:check` clean; lint multiset for
the changed file identical to the gated head (9 pre-existing findings, added NONE).
samxu01
pushed a commit
that referenced
this pull request
Sep 28, 2026
…d, and spell out that test-only is code-touching (rule 32) Vera's HOLD was that the earned note described the `at`/`ms` divergence as "a defect neither reviewer could see". It was hers: 75185 carries the measurement (`at=04:00:00.000Z`, `ms` 31 ms behind it, every consumer taking `.at` while `formatCursor` falls back to `ms`) and the prescription `ms: mark`. The note now names all three findings and who earned each, which is what the file's authority rests on — an earned clause that names an unidentifiable defect teaches a reader the pattern is decorative. Rider extended, at her request and one citation short of it: a **test**-only move counts as code-touching, because the arms are much of what a clearance is about. She cited #1986 `5c068c37`->`0cfd8c0f` and #1977 `f121340e`->`2c55b4d1`; the first checks out (two commits inside the guard's own test file), the second is `docs/agents/daemon-seat-state-surfaces.md` +67-0 then +90-0 — a docs move, which the rule already calls a re-stamp. Only the verified pair is cited. Docs prose: no automated witness. `docReferences.test.js` scans code dirs, and no test reads this file (grep for it finds two comments that mention it, neither an assertion).
lilyshen0722
added a commit
to thantiklermcirony/commonly
that referenced
this pull request
Oct 9, 2026
…r it (rule 32) (Team-Commonly#1991) * docs(review-checklist): a clearance is spent when the head moves under it (rule 32) * docs(review-checklist): name the three findings rule 32's rider earned, and spell out that test-only is code-touching (rule 32) Vera's HOLD was that the earned note described the `at`/`ms` divergence as "a defect neither reviewer could see". It was hers: 75185 carries the measurement (`at=04:00:00.000Z`, `ms` 31 ms behind it, every consumer taking `.at` while `formatCursor` falls back to `ms`) and the prescription `ms: mark`. The note now names all three findings and who earned each, which is what the file's authority rests on — an earned clause that names an unidentifiable defect teaches a reader the pattern is decorative. Rider extended, at her request and one citation short of it: a **test**-only move counts as code-touching, because the arms are much of what a clearance is about. She cited Team-Commonly#1986 `5c068c37`->`0cfd8c0f` and Team-Commonly#1977 `f121340e`->`2c55b4d1`; the first checks out (two commits inside the guard's own test file), the second is `docs/agents/daemon-seat-state-surfaces.md` +67-0 then +90-0 — a docs move, which the rule already calls a re-stamp. Only the verified pair is cited. Docs prose: no automated witness. `docReferences.test.js` scans code dirs, and no test reads this file (grep for it finds two comments that mention it, neither an assertion). * docs(review-checklist): the mutation label in rule 32's earned note is the author's find, not a reviewer's Vera's second HOLD on the same sentence, and the mirror of the first: I had attributed the mislabeled mutation to her. It was mine. Her 75177 asks for the pair of arms (carry and reset) and says nothing about a label; my own 75186 reports the label defect unprompted, and it surfaced from the ledger's named-arm check on the author's side. Verified both messages at the source before changing it, because the previous clause failed for exactly this reason. The three attributions are now Wren / the author's own ledger / Vera, which is a better argument for the rider than two of three belonging to one reviewer: a reviewer, the builder's instrument, and the clearance itself. * docs(review-checklist): state rule 32's TASK-177 findings once, where the count is (sprint-impl review) The rider named the same two findings twice and the two counts disagreed: the first list held "two further findings" and the second, introduced by "all three folded", added the `at`/`ms` divergence that the first never mentioned. A reader was told two, then three, then handed a list whose third item was new. The fold carries one list — Wren's paging defect, the mutation label the author's own ledger caught, and Vera's `at`/`ms` divergence — and then the count, so "three" has an antecedent. `two further findings` also had nothing to be further than, since the paragraph never says what the clearance's own finding was; it is now `two other findings`. The rider's length and the burial of the clause a presser needs (a stamp names the head it was taken against) are noted and left alone: that is a question about the file's shape, not about this sentence, and moving it would change the text the existing clearance was taken against. Found by sprint-impl reading the head, not by any witness in this file: docs prose has none. `verify-numbered-rules.js` still reports 40 rules, 1..40 with no gap and 17 citations resolving.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
TASK-176, backend half. The CLI half is #1985.
The premise, measured
The row asked for this guard because
acknowledgeAttentionwas said to be exploitable: "mongoose drops anundefinedkey, which would ack another recipient's item by id". That is not what happens, and it matters that the correction is written down rather than the fix being explained by it. Probe onbbab5c31— each caller shape against a row owned by another recipient:So there is no cross-recipient acknowledgement to fix:
undefinedandnullare refused and the other person's row keeps itsopenstatus. What is real is the last two lines: a caller id that is not an ObjectId throws out of the update, and the route (routes/activity.ts:265-274) turns that into a500 Failed to acknowledge attention. A malformed id is a client-side fact, and the item-id guard three lines above already answers that shape with a refusal.The change
— the same guard
getOpenQueuecarries on its recipient (attentionItemService.ts:466), placed beside the existing item-id refusal, with the measurement in the comment so the next reader is not told a story the code cannot reproduce. Reachability today is latent (the single production caller passes a real id fromauth), so the value here is the 400-vs-500 boundary and the invariant, not a closed exploit.One existing arm moved its fixture
backend/__tests__/unit/services/attentionItemService.test.js:428calledacknowledgeMention('sam', <item>).'sam'is not an ObjectId, so the guard now refuses it before the mocked update and the arm'smockUpdateOne.mock.calls.at(-1)wasundefined. That arm's subject is the$orselector ("never decisions or approvals"), not the spelling of the recipient, so it now uses a real ObjectId — which the two neighbouring acknowledgement arms in the same file already did. No other arm in the repo passes a non-id recipient (grepacrossbackend/__tests__).Verification
backend/__tests__/service/attentionAcknowledgeRecipientGuard.test.js:'','not-an-id', and the 12-character'507f191e810c') each refused by name (Invalid recipient), with three separately planted rows all stillopen— one row per caller so a passing case cannot mask a failing one;Attention item not found, with the owner's own acknowledgement as the positive control (and a second acknowledgement on the resolved row refused, because the selector requiresstatus: 'open');Invalid attention itembefore any update, with the row open.undefinedandnullare deliberately not arms: they are refused by unguarded code too (see the probe above), so an arm asserting them witnesses nothing. Their behaviour is in the file header as the reason the row's premise was withdrawn, not dressed up as a fix.One more measurement, because the third caller rests on it rather than on the cast:
'507f191e810c'does not throw — it casts to353037663139316538313063, its own ASCII bytes read as the 12-byte form, i.e. a valid ObjectId belonging to nobody. The guard checks the canonical 24-hex shape rather than leaning on the cast, which is what makes that row of the table a refusal instead of a silent miss.The two survivors Vera found, reproduced and then closed
Her review of
5c068c37found the arms did not witness the regex's anchors, and both reproduce exactly as reported. Measured in this order — the ledger run against the gated head, then against this commit:5c068c37{24}$→{24})/^[a-f→/[a-f)The two survivors are the guard's own value left unwitnessed: with
$gone,<24 hex>0passes and the cast throws; with^gone,x<24 hex>does the same — both straight back to the 500 this PR removes. Neither is reachable from a real credential (getAuthenticatedUserIdreturnsreq.userId || req.user?.id || req.user?._id || null), so this is hardening of a hardening change, not a closed door.Two caller shapes close it, appended to the array the arm already loops over (so
toHaveLength(callers.length)scales by itself):M4is in the table because WHERE the guard sits is part of the guarantee: a refusal after the write is not a refusal, and the arm kills that move. One existing assertion had to scale with the list — the planted rows' statuses were asserted as the literal['open','open','open'], which would have kept passing for the wrong reason at five callers; it is nowcallers.map(() => 'open').Not touched, named rather than smuggled in:
getOpenQueue:466carries the identical regex with the identical anchor gap. Same class, pre-existing, out of this row's scope.Mutation ledger: 6 mutations, NO SURVIVORS, each killed by its named arm (
/tmp/kai-176be-ledger.py, baseline(1, 3)asserted on every run, and the mutated file verified byte-clean against the committed head at the end). The first run of that ledger reported both kills withnamed_arm_hit=False— a bug in the ledger, not the suite: it tested arm membership withname in names(list equality) against jestfullNames that carry their describe prefix. Fixed and re-run; both hits are real.The mutation removing the recipient guard fails the suite with the same
CastErrorthe probe recorded, which is the defect stated above, restated by the code.Regression across the neighbouring suites (5 suites / 59 tests, 0 failed):
attentionQueue.counts,unit/services/attentionItemService,unit/routes/activity.read,unit/services/activityService.recap, plus the new file.npm run tsc:checkexits 0. Lint diff onservices/attentionItemService.tsagainstorigin/main: base 15 findings, mine 15, added NONE, removed NONE (warnings included; the restore was checksum-verified).Backend only, so no package version bump. Gate: Vera.
Also in the row, not this PR
#1985 now backs off on the
/api/activitylimiter (60/min, keyed oncf-connecting-ip, so shared by every session on a host and by the operator's own browser) and reports the server'scodefield instead of a bareHTTP 429.