Repository navigation
fix(connect): close JSONC comment-guard TOCTOU in connect/disconnect - #1353
Merged
Merged
Conversation
Deploying mcpproxy-docs with
|
| Latest commit: |
47a67e9
|
| Status: | ✅ Deploy successful! |
| Preview URL: | https://8ab2e537.mcpproxy-docs.pages.dev |
| Branch Preview URL: | https://claude-busy-northcutt-92e1b1.mcpproxy-docs.pages.dev |
Contributor
📦 Build ArtifactsWorkflow Run: View Run Available Artifacts
How to DownloadOption 1: GitHub Web UI (easiest)
Option 2: GitHub CLI gh run download 35981547996 --repo smart-mcp-proxy/mcpproxy-go
|
|
Codecov Report✅ All modified and coverable lines are covered by tests. 📢 Thoughts on this report? Let us know! |
Dumbris
force-pushed
the
claude/busy-northcutt-92e1b1
branch
from
September 24, 2026 04:19
f5b02b1 to
a76b8c0
Compare
guardJsoncComments and readOrCreateJSON each did their own independent s.read(cfgPath), so a file that was comment-free when the guard read it but gained comments before the parse's later read would pass the guard on stale bytes and get silently rewritten as plain JSON, stripping the comments the guard exists to protect (#922). disconnectJSON had the identical shape. Fold the check into a pure guardJsoncCommentsBytes(cfgPath, raw) run against bytes the caller already read, so the guard and the parse/write now always see the same snapshot. The old read-it-yourself guardJsoncComments is kept only for the read-only preview path, which never writes. Flagged as a pre-existing, out-of-scope finding in cross-model review of PR #1340. Verified with call-counting regression tests (fail against the pre-fix code, pass against the fix) and two rounds of independent cross-model review (codex gpt-5.6-sol, then zcode/GLM), the second of which caught a suffix-check-ordering regression and a test coverage gap in the first fix, both corrected here. Co-Authored-By: Claude Sonnet 5 <[email protected]>
- ConnectWithPrecondition's doc comment still described the JSONC comment-guard double-read as a pre-existing, out-of-scope limitation; this PR actually closes it via guardJsoncCommentsBytes, so update the comment to say so instead of contradicting the fix it sits next to. - Fix TestConnectJSON_CommentGuardSharesOneReadWithParse's subtest name, which still said "2 total reads, not 3" while its assertion checks for 4 (the count PR #1340's extra refuseIfServersSectionRaced checks raised it to). Co-Authored-By: Claude Sonnet 5 <[email protected]>
TestConnectJSON_CommentGuardSharesOneReadWithParse called connectJSON directly with a stale (resolved *existingEntry) argument that PR #1352's single-pre-write-read refactor removed; connectJSON now takes the shared preWriteResult and no longer performs any read of its own. Route both subtests through ConnectWithPrecondition instead, which is the only remaining caller that resolves a preWriteResult from a config path. Read counts are unchanged (4 for the comment-free path, 1 for the refusal path) because ConnectWithPrecondition's own connectRefusal check stats rather than reads the file. Co-Authored-By: Claude Sonnet 5 <[email protected]>
zcode's read-only review of the #1352/#1353 rebase resolution (round 1) found a genuine stale comment introduced by the conflict resolution itself: guardJsoncComments' doc claimed it is "used only by the read-only preview path (preview.go)", but preview.go actually calls the read-free guardJsoncCommentsBytes(cfgPath, pre.raw) — a switch #1352 made — so the reading wrapper has zero production callers. Fix the doc to say so, note it is kept only for its own direct test coverage and as a documented trap against future write-path use, and correct a second, minor inaccuracy that listed connectTOML among guardJsoncCommentsBytes' callers (a .toml path can never match the .jsonc suffix it checks, so it never calls the guard). Also corrects the matching false claim repeated in TestGuardJsoncComments_SkipsReadForNonJsoncPath's doc comment. Co-Authored-By: Claude Sonnet 5 <[email protected]>
…cComments doc zcode round-2 re-review caught one remaining issue in the previous fix: the doc said guardJsoncComments is kept because "guardJsoncCommentsBytes's own tests exercise directly" — grammatically misattributing the coverage to the wrong function. No test calls guardJsoncCommentsBytes directly; the only direct caller is guardJsoncComments' own test, TestGuardJsoncComments_SkipsReadForNonJsoncPath. Name it explicitly instead. Co-Authored-By: Claude Sonnet 5 <[email protected]>
Dumbris
force-pushed
the
claude/busy-northcutt-92e1b1
branch
from
September 24, 2026 09:29
ab925b2 to
47a67e9
Compare
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
guardJsoncCommentsandreadOrCreateJSONeach performed their own independents.read(cfgPath). A file that was comment-free when the guard read it but gained comments before the parse's later read would pass the guard on stale bytes and get silently rewritten as plain JSON — stripping the comments the guard exists to protect (connect opencode fails: OpenCode bootstraps opencode.jsonc, mcpproxy only recognizes opencode.json #922).disconnectJSONhad the identical shape (not previously reported).guardJsoncCommentsBytes(cfgPath, raw []byte)run against bytes the caller already read, so the guard and the parse/write always see the same snapshot. The old, self-readingguardJsoncCommentsis kept only for the read-only preview path, which never writes and so has nothing to race.Test plan
internal/connect/opencode_jsonc_test.goprove the fix via read-call counting (TestConnectJSON_CommentGuardSharesOneReadWithParse,TestDisconnectJSON_CommentGuardSharesOneRead) — each verified locally to fail against the pre-fix code and pass against the fix.TestGuardJsoncComments_SkipsReadForNonJsoncPathguards a suffix-check-ordering regression caught in second-round review.TestConnect_OpenCode_AllowsTrailingCommaJSON,TestPreview_ConnectRefusal_CommentedJsonc,TestPreview_ConnectRefusal_CommentFreeJsoncIsConnectablestill pass.go build(personal + server edition),go vet,gofmt,go test -race ./internal/connect/....golangci-lint(bare and--build-tags server) clean.gpt-5.6-sol(round 1, clean), then zcode/GLM (round 2, caught a suffix-check-ordering regression and a test coverage gap in round 1's fix — both corrected here and re-verified).🤖 Generated with Claude Code