Repository navigation
Commit e291918
authored
fix(gateway): keep cold transcript reads inside the sessions root (#391)
## Requirement or Bug
Keep cold transcript file reads inside the sessions root, and pin that
the config route rejects prototype-poisoning bodies. Both are open
code-scanning alerts on `main`.
## Bug Reproduction Steps
1. Give the session index an entry whose `workspaceId` is `../outside`,
and put a `state.json` with an agent at
`<home>/outside/<session>/state.json`.
2. Call `readColdRoster(<session>)`. It returns the agent from the file
outside `<home>/sessions`.
The new test `cold reads stay inside the sessions root when the index
names an escaping workspace` does this. It fails before the fix and
passes after.
## Root Cause
`TranscriptService.readColdRoster` and `readColdSnapshot` built their
paths with `join(homeDir, 'sessions', workspaceId, sessionId, ...)`.
Only the agent id was checked. The session id and workspace id come from
the session index, so the path is safe only while the index is. The
gateway already has `resolveStoragePath`, which rejects segments that
leave the root, and `readWireRecords` already uses it. This is a fix at
the root.
## Code Changes
```diff
readColdRoster(sessionId)
- readFile(join(homeDir, 'sessions', workspaceId, sessionId, 'state.json'))
+ readFile(resolveStoragePath(homeDir, 'sessions', workspaceId, sessionId, 'state.json'))
escape -> caught like any unreadable state file -> []
readColdSnapshot(sessionId, agentId)
- wirePath = join(homeDir, 'sessions', workspaceId, sessionId, 'agents', agentId, 'wire.jsonl')
+ wirePath = resolveStoragePath(homeDir, 'sessions', workspaceId, sessionId, 'agents', agentId, 'wire.jsonl')
escape -> throws "Storage path escapes its root"
```
Config route: Fastify's default JSON parser already rejects `__proto__`
and `constructor.prototype` keys, so `convertKeysSnakeToCamel` never
sees them. A plain `constructor` key only becomes an own property. No
code change; a new test pins the rejection.
## Behavior Changes and Affected Users
| Behavior | Before | After | Who relies on the old behavior | Escape
hatch |
|---|---|---|---|---|
| Cold roster with a session-index entry whose ids leave the sessions
root | Reads the file outside the root | Returns an empty roster |
Nobody; the index only holds ids the engine created | n/a |
| Cold snapshot with such an entry | Reads the wire file outside the
root | Throws "Storage path escapes its root" | Nobody | n/a |
| Config POST with `__proto__` or `constructor.prototype` keys |
Rejected by the JSON parser | Unchanged (now covered by a test) | n/a |
n/a |
Affected module: `packages/agent-gateway` transcript service. Tests:
`test/services/transcript.test.ts` (new escape test, red before the
fix), `test/config.test.ts` (new parser pin). Gateway suite 75 files /
1437 passed; gateway typecheck, `pnpm run lint` (0 errors) and
`check-no-comments` pass. [skip changeset] Users cannot see this change:
the session index only holds ids the engine created.
## Checklist
- [x] I have read the
[CONTRIBUTING](https://github.com/PyModel/pythinker-code/blob/main/CONTRIBUTING.md)
document.
- [ ] I have linked a related issue (external PRs: issue must have a
maintainer's `/approve`).
- [x] I have added tests that prove my feature works.
- [x] The behavior-change table above is complete, and every removed
behavior or flipped default is named in the changeset and either has an
escape hatch or was explicitly approved by a maintainer in this PR.
- [x] Ran `gen-changesets` skill, or this PR needs no changeset.
- [x] Ran `gen-docs` skill, or this PR needs no doc update.1 parent 21388e4 commit e291918
3 files changed
Lines changed: 58 additions & 2 deletions
File tree
- packages/agent-gateway
- src/services/transcript
- test
- services
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
47 | 47 | | |
48 | 48 | | |
49 | 49 | | |
| 50 | + | |
50 | 51 | | |
51 | 52 | | |
52 | 53 | | |
| |||
528 | 529 | | |
529 | 530 | | |
530 | 531 | | |
531 | | - | |
| 532 | + | |
532 | 533 | | |
533 | 534 | | |
534 | 535 | | |
| |||
549 | 550 | | |
550 | 551 | | |
551 | 552 | | |
552 | | - | |
| 553 | + | |
553 | 554 | | |
554 | 555 | | |
555 | 556 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
87 | 87 | | |
88 | 88 | | |
89 | 89 | | |
| 90 | + | |
| 91 | + | |
| 92 | + | |
| 93 | + | |
| 94 | + | |
| 95 | + | |
| 96 | + | |
| 97 | + | |
| 98 | + | |
| 99 | + | |
| 100 | + | |
| 101 | + | |
| 102 | + | |
| 103 | + | |
| 104 | + | |
| 105 | + | |
| 106 | + | |
| 107 | + | |
90 | 108 | | |
91 | 109 | | |
92 | 110 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
2793 | 2793 | | |
2794 | 2794 | | |
2795 | 2795 | | |
| 2796 | + | |
| 2797 | + | |
| 2798 | + | |
| 2799 | + | |
| 2800 | + | |
| 2801 | + | |
| 2802 | + | |
| 2803 | + | |
| 2804 | + | |
| 2805 | + | |
| 2806 | + | |
| 2807 | + | |
| 2808 | + | |
| 2809 | + | |
| 2810 | + | |
| 2811 | + | |
| 2812 | + | |
| 2813 | + | |
| 2814 | + | |
| 2815 | + | |
| 2816 | + | |
| 2817 | + | |
| 2818 | + | |
| 2819 | + | |
| 2820 | + | |
| 2821 | + | |
| 2822 | + | |
| 2823 | + | |
| 2824 | + | |
| 2825 | + | |
| 2826 | + | |
| 2827 | + | |
| 2828 | + | |
| 2829 | + | |
| 2830 | + | |
| 2831 | + | |
| 2832 | + | |
2796 | 2833 | | |
2797 | 2834 | | |
2798 | 2835 | | |
| |||
0 commit comments