Repository navigation
fix(offload): keep the sweep ask-dump file name inside its directory - #951
Merged
Merged
Conversation
CodeQL go/path-injection flagged the dump file name, which is built from the session id. session.Scoped already limits real ids to a safe set. The dump now cleans the name itself and checks it is one local element. Assisted-By: Claude Opus 5.5 <[email protected]> Signed-off-by: DAVID AMID <[email protected]>
amiddavid
commented
Nov 8, 2026
amiddavid
left a comment
Collaborator
Author
There was a problem hiding this comment.
| Reviewer | Kind | Started by | Context | Review | Round | Head | Verdict |
|---|---|---|---|---|---|---|---|
| Reviewer 2 (glm, user of @amiddavid) | GLM rits/zai-org/glm-5-3 via Claude Code 2.1.319 | offload-review skill, @amiddavid's session | fresh | 2 of 2 | 1 of 2 | df92f1cddbf7 |
approve |
Verdict: approve
Findings
None. I could not break the fix. Details of what I tried are under "What I checked".
Non-blocking
sweep_askdump.go:146— thefilepath.IsLocal/filepath.Baseguard can never fire afteraskDumpSafe: the name always starts withask-, holds no separator, and so is always one local element. The code already says "defence in depth", so this is stated intent, not a defect. Keep it.sweep_askdump_test.go:180— the test asserts containment and count, not the mangled name itself. It would pass a sanitize that, say, hashed the whole id. The in-repo convention (see the gate test at line 51) prefers asserting the property, so this is fine as is.sweep_askdump.go:113— the comment "for every real id this returns the id unchanged" is correct today:safeExplicitallows exactly[a-zA-Z0-9._:-], the derived hash is hex, and tenant ids come fromnewID()(hex). It rests on the tenant half staying hex; the code stays safe even if it does not.
What I checked
- Read the full diff (2 files, +44/−1) and both files in full.
- The sanitize is airtight for path escape.
askDumpSafekeeps only[a-zA-Z0-9._:-]. The name isask-<safe>-<seq>.json: it always starts withask-, never equals.or.., and holds no/or\. After the map,filepath.IsLocalis always true, so the write stays insidedir. Invalid UTF-8 bytes map throughstrings.MaptoRuneError, which the allow-list rejects, so they become_. - The charset claim in the comment is true.
session.safeExplicit(session/session.go:42) allows exactly letters, digits and. _ : -, rejects all-dots ids, and caps length at 128.Scopedoutput is that id, or a 16-char hex hash, optionally prefixedtenant:; tenant ids come fromnewID()(hex). So no real proxy id changes. - No overwrite from collapsed ids. Two hostile ids can sanitize to the same prefix, but
sweepAskDumpSeqis a process-global atomic, so<seq>differs per dump and file names never collide. - The test catches the named mutation. With the raw session
x/../../escape, the joined pathparent/dump/ask-x/../../escape-001.jsoncannot resolve (ask-xdoes not exist),os.WriteFilefails, and the dump dir holds 0 files — thelen(in) != 1assertion at sweep_askdump_test.go:190 fails. So reverting the fix fails the test. - Fail-open holds. Every new failure path (unsafe name, over-long name →
ENAMETOOLONG) logs one warning and returns; the adjudication is untouched, matching the file's stated contract. - Both call sites (extract_sweep.go:635, 817) go through the one
writeSweepAskDump, so the guard covers every exit. - Repo rules. No data-dependence change: the dump stores the same bytes as before, only the file name changed, so docs/data-dependence.md needs no edit. No behavior change for users: real ids sanitize to themselves, and the dump is an operator opt-in bench instrument. No other session-derived file names exist in the repo (grepped).
amiddavid
commented
Nov 8, 2026
amiddavid
left a comment
Collaborator
Author
There was a problem hiding this comment.
| Reviewer | Kind | Started by | Context | Review | Round | Head | Verdict |
|---|---|---|---|---|---|---|---|
| Reviewer 1 (glm, user of @amiddavid) | GLM rits/zai-org/glm-5-3 via Claude Code 2.1.319 | offload-review skill, @amiddavid's session | fresh | 1 of 2 | 1 of 2 | df92f1cddbf7 |
approve |
Verdict: approve
Findings
None. The fix is correct and I could not break it.
Non-blocking
components/offload/sweep_askdump_test.go:191— the test does not assert the written file name. A sanitizer that mangles real ids (drops an allowed character) would still pass it. Add one line: the file must beask-x_.._.._escape-001.json. That also pins the identity property — for every idsession.Scopedallows, the name is unchanged.components/offload/sweep_askdump.go:146— thefilepath.IsLocal/Baseguard can never fire whileaskDumpSaferuns: the sanitized name holds no separator. The comment says it is defence in depth, so this is fine. It guards a future edit that removes the sanitizer.- Pre-existing, not this PR:
CG_SWEEP_ASK_DUMPis missing from the env-switch table indocs/data-dependence.md(the row forCONTEXT_GURU_DUMP/CONTEXT_GURU_CAPTURE, line 342). The ask-dump writes full conversation text to disk and belongs in that list. It came in with #508. Give it its own issue, per the repo rule that amaindefect gets its own PR.
What I checked
- The full diff:
askDumpSafe, the name construction, the new guard, and the new test. - The charset claim.
session.safeExplicit(session/session.go:42) allows letters, digits and. _ : -, max 128 bytes.askDumpSafekeeps exactly that set. So no reachable id changes its file name. - The tenant prefix.
Scopedonly trims spaces from the tenant, but the hosted proxy passestn.ID, whichnewIDmakes from hex (tenant/tenant.go:1496). No separator can enter there. - Both hosts. The proxy and the bifrost adapter both resolve the session through
Scoped/Resolve. The dump no longer depends on that, which is the point of the fix. - Fail open. The unsafe-name path logs one warning and skips the write. The dump is a diagnostic; skipping it cannot fail a request. The write error path is unchanged and still fail-open.
- The test's mutation claim. With
d.Sessionraw, the name isask-x/../../escape-001.json.filepath.Joincleans that to<parent>/escape-001.json, so a file lands in the parent and the test fails. With the fix, one file lands inside the dump directory. Both assertions hold. - Behavior change. None for any id
Scopedcan produce. The dump stays off by default. No human-permission rule is triggered. - Data dependence. The PR statement is right: the dump already holds conversation text; only the file name changed.
docs/data-dependence.mdneeds no change from this PR. - Unicode and length.
strings.Mapturns an invalid byte or a multi-byte rune into one_, so no separator can be synthesized. A reachable id is at most ~150 bytes, under the 255-byte file-name limit. A longer id failsWriteFile, which warns and returns.
amiddavid
added a commit
that referenced
this pull request
Nov 8, 2026
Round 1 of #960, non-blocking points: - The CodeQL check run must come from GitHub's code-scanning app (github-advanced-security), so a job renamed to CodeQL cannot pass the check with no scan behind it. - A passing check run can still carry an alert. The script now also reads the open code-scanning alerts on the PR's merge ref, and a failed read stops it with an error. - The messages say what to do: the PR must target main to be scanned, and a run still in progress means wait. Tested with a stub gh: a clean PR is READY; an open alert gives NOT READY with the alert; a failed alert read gives an ERROR. On real PRs: #951 and #960 pass the scan check; #943 fails it. Assisted-By: Claude Opus 5.5 <[email protected]> Signed-off-by: DAVID AMID <[email protected]>
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.
Summary
go/path-injection,components/offload/sweep_askdump.go:134).CG_SWEEP_ASK_DUMP).What we found
session.Scopedalready allows only letters, digits and. _ : -. So no real id can leave the directory today.What changed
askDumpSafeturns any other character into_.Behavior change: none for any id that
session.Scopedallows. The name is the same. Only an id outside that set (not reachable today) now gets_in the name.How it was tested
TestAskDumpFileStaysInsideTheDirectory. It fails before the fix (fileescape-001.jsonlands in the parent directory) and passes after.go vetandgo test -race ./components/offload/pass on the box.Data dependence
No change. The dump already holds conversation text, off by default. This PR changes only the file name.
🤖 Generated with Claude Code