Repository navigation
Commit 64f72f2
committed
fix: tighten hoist trust boundary —
PR #888 review surfaced a real prompt-injection vector that the
previous `synthetic + prefix` trust check could not close.
The `MessageV2.TextPart.synthetic` flag is set by *several* code paths
in `session/prompt.ts`, not just by reminder injection. In particular,
the file/resource expansion paths at lines ~1729/1751/1801 attach
*user-supplied content* (MCP resource bodies, `data:` URL decoded
text, file attachments) as text parts with `synthetic: true`. A
malicious file or resource whose body began with `<system-reminder>`
would therefore have been hoisted into the system role on
non-Anthropic models — exactly the privilege escalation the prior
fix was meant to prevent. Caught by both CodeRabbit (PR #888 thread,
`prompt.ts:2082`) and cubic (`prompt.ts:2078`).
This commit narrows the trust boundary the way the reviewers
suggested: `insertReminders` now returns the explicit list of parts
it appended, and the loop hoists *only* those. `synthetic + prefix`
inference is gone.
- `insertReminders` return shape: `Promise<{ messages, trustedReminderParts }>`.
Each `userMessage.parts.push(...)` site also pushes the same part
into `trustedReminderParts` so the caller has the candidates
without having to re-derive them.
- `hoistSyntheticReminders` helper removed. The loop iterates
`reminderResult.trustedReminderParts` directly: pushes the text
into the system array, marks the part `ignored = true` so
`toModelMessages` skips it in the user message.
- `isAnthropicLikeModel` retained (still the gate for whether to
hoist or leave reminders in-place).
- Two regression tests added in `plan-layer-e2e.test.ts` that
re-read `prompt.ts` to enforce the contract: the hoist must
consume `trustedReminderParts` and must not re-introduce a
`hoistSyntheticReminders`-style scan.
Also removes the diagnostic dump from `llm.ts` (added in an earlier
WIP for #888 investigation, not for shipping). The dump path under
`~/.local/share/altimate-code/log/plan-debug/` is no longer written.
Typecheck clean. 128 affected tests pass.insertReminders returns explicit candidates1 parent 77ffd92 commit 64f72f2
2 files changed
Lines changed: 86 additions & 43 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
688 | 688 | | |
689 | 689 | | |
690 | 690 | | |
691 | | - | |
| 691 | + | |
| 692 | + | |
| 693 | + | |
| 694 | + | |
| 695 | + | |
| 696 | + | |
| 697 | + | |
692 | 698 | | |
693 | 699 | | |
694 | 700 | | |
695 | 701 | | |
696 | | - | |
697 | | - | |
698 | | - | |
699 | | - | |
700 | | - | |
701 | | - | |
702 | | - | |
| 702 | + | |
| 703 | + | |
| 704 | + | |
| 705 | + | |
| 706 | + | |
| 707 | + | |
| 708 | + | |
| 709 | + | |
703 | 710 | | |
704 | 711 | | |
705 | 712 | | |
| |||
2048 | 2055 | | |
2049 | 2056 | | |
2050 | 2057 | | |
2051 | | - | |
| 2058 | + | |
2052 | 2059 | | |
2053 | 2060 | | |
2054 | 2061 | | |
| |||
2059 | 2066 | | |
2060 | 2067 | | |
2061 | 2068 | | |
2062 | | - | |
2063 | | - | |
2064 | | - | |
2065 | | - | |
2066 | | - | |
2067 | | - | |
2068 | | - | |
2069 | | - | |
2070 | | - | |
2071 | | - | |
2072 | | - | |
2073 | | - | |
2074 | | - | |
2075 | | - | |
2076 | | - | |
2077 | | - | |
2078 | | - | |
2079 | | - | |
2080 | | - | |
2081 | | - | |
2082 | | - | |
2083 | | - | |
2084 | | - | |
2085 | | - | |
2086 | 2069 | | |
2087 | 2070 | | |
2088 | | - | |
| 2071 | + | |
| 2072 | + | |
| 2073 | + | |
| 2074 | + | |
| 2075 | + | |
| 2076 | + | |
| 2077 | + | |
| 2078 | + | |
| 2079 | + | |
| 2080 | + | |
| 2081 | + | |
| 2082 | + | |
| 2083 | + | |
| 2084 | + | |
2089 | 2085 | | |
2090 | | - | |
| 2086 | + | |
2091 | 2087 | | |
2092 | 2088 | | |
2093 | 2089 | | |
2094 | 2090 | | |
2095 | | - | |
| 2091 | + | |
2096 | 2092 | | |
2097 | 2093 | | |
2098 | 2094 | | |
2099 | 2095 | | |
2100 | 2096 | | |
2101 | 2097 | | |
2102 | | - | |
| 2098 | + | |
| 2099 | + | |
| 2100 | + | |
2103 | 2101 | | |
2104 | 2102 | | |
2105 | 2103 | | |
2106 | | - | |
| 2104 | + | |
2107 | 2105 | | |
2108 | 2106 | | |
2109 | 2107 | | |
2110 | 2108 | | |
2111 | 2109 | | |
2112 | 2110 | | |
2113 | | - | |
| 2111 | + | |
| 2112 | + | |
| 2113 | + | |
2114 | 2114 | | |
2115 | | - | |
| 2115 | + | |
2116 | 2116 | | |
2117 | 2117 | | |
2118 | 2118 | | |
| |||
2133 | 2133 | | |
2134 | 2134 | | |
2135 | 2135 | | |
| 2136 | + | |
2136 | 2137 | | |
2137 | | - | |
| 2138 | + | |
2138 | 2139 | | |
2139 | 2140 | | |
2140 | 2141 | | |
| |||
2236 | 2237 | | |
2237 | 2238 | | |
2238 | 2239 | | |
2239 | | - | |
| 2240 | + | |
| 2241 | + | |
2240 | 2242 | | |
2241 | | - | |
| 2243 | + | |
2242 | 2244 | | |
| 2245 | + | |
2243 | 2246 | | |
2244 | 2247 | | |
2245 | 2248 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
455 | 455 | | |
456 | 456 | | |
457 | 457 | | |
| 458 | + | |
| 459 | + | |
| 460 | + | |
| 461 | + | |
| 462 | + | |
| 463 | + | |
| 464 | + | |
| 465 | + | |
| 466 | + | |
| 467 | + | |
| 468 | + | |
| 469 | + | |
| 470 | + | |
| 471 | + | |
| 472 | + | |
| 473 | + | |
| 474 | + | |
| 475 | + | |
| 476 | + | |
| 477 | + | |
| 478 | + | |
| 479 | + | |
| 480 | + | |
| 481 | + | |
| 482 | + | |
| 483 | + | |
| 484 | + | |
| 485 | + | |
| 486 | + | |
| 487 | + | |
| 488 | + | |
| 489 | + | |
| 490 | + | |
| 491 | + | |
| 492 | + | |
| 493 | + | |
| 494 | + | |
| 495 | + | |
| 496 | + | |
| 497 | + | |
458 | 498 | | |
459 | 499 | | |
460 | 500 | | |
| |||
0 commit comments