fix(core): never echo JSON parser text from the account store reader - #184
Merged
Merged
Conversation
There was a problem hiding this comment.
All reported issues were addressed across 5 files
Architecture diagram
sequenceDiagram
participant User as User or Host Process
participant OpenCode as OpenCode Runtime
participant Accounts as Account Store Reader
participant JSON as Redacted JSON Parser
participant FS as Local Account Files
participant Logger as Plugin Logger
participant Dump as Dump Body Parser
participant HTTP as Request or Response Body
Note over User,Logger: Account loading flow
User->>OpenCode: Load account configuration
OpenCode->>Accounts: loadAccounts()
Accounts->>FS: Read anthropic-auth.json
FS-->>Accounts: Config JSON or file error
Accounts->>JSON: Parse config text
JSON-->>Accounts: Parsed config
Accounts->>FS: Read anthropic-auth-state.json
FS-->>Accounts: OAuth state JSON or file error
Accounts->>JSON: Parse state text
JSON-->>Accounts: Parsed OAuth tokens
alt Valid JSON in both stores
Accounts-->>OpenCode: Account configuration and auth state
OpenCode-->>User: Accounts available
else Missing account file
FS-->>Accounts: ENOENT
Accounts-->>OpenCode: File absent
OpenCode-->>User: Continue with no stored account
else Malformed JSON near a secret-bearing token
JSON->>JSON: Catch SyntaxError
JSON-->>Accounts: CHANGED: SyntaxError("invalid JSON") without cause
Accounts-->>OpenCode: Corruption error with file path and fix-or-remove hint
OpenCode->>Logger: Log corruption error without parser text or token
Logger-->>User: Safe diagnostic
end
Note over User,HTTP: Request or response dump flow
OpenCode->>Dump: Capture body for dump or diff summary
Dump->>HTTP: Read body text
HTTP-->>Dump: JSON or non-JSON body
Dump->>JSON: Parse body text
alt Valid JSON object
JSON-->>Dump: Parsed object
Dump-->>OpenCode: Redacted or summarized body data
else Invalid JSON
JSON->>JSON: Catch SyntaxError
JSON-->>Dump: CHANGED: Fixed "invalid JSON" error without original text
Dump-->>OpenCode: Treat body as unparsable
OpenCode->>Logger: Log dump failure without parser text or secret
end
Reply with feedback, questions, or to request a fix.
Re-trigger cubic
Bun 1.3.14 can include an unquoted token identifier in JSON.parse SyntaxError text. The account config and state files can hold Claustrum handles and OAuth access or refresh tokens; redact parser text before the reader surfaces corruption.
iceteaSA
force-pushed
the
fix/json-parse-secret-echo
branch
from
September 2, 2026 18:35
9d3739e to
dfb6bc0
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.
Bun 1.3.14's
JSON.parsequotes an unquoted token adjacent to a syntax error verbatim:(Unterminated-string and expected-brace cases stay clean; the trigger is a hand-edit that leaves a bare token.)
readJsonIfPresentinpackages/core/src/accounts.tsinterpolated that message into the thrownaccount store at <path> is corrupt or unreadable (<parser text>)error. It reads bothanthropic-auth.json(may hold a Claustrum handle) andanthropic-auth-state.json(OAuth access and refresh tokens), and the plugin logs that error. So a bad hand-edit next to a token wrote the token intoopencode-anthropic-auth.log.dump.tsparseBodyhad the same shape for request/response bodies.Fix
parseJsonRedacted(packages/core/src/json.ts): catchesSyntaxErrorand rethrows a fixed-messageSyntaxError('invalid JSON')with nocause. Used by the account-store reader and the dump body parser. The account-store error keeps the path and the "fix or remove it" hint.Audited the other
JSON.parsesites in core (lock/owner files, sticky routing state, quota feed leases, cachekeep registry, dump metadata): none parse secret-bearing content with an interpolated message; left as is.Proof
Regression writes a state file containing a bare
sk-ant-oat…CANARY…token beside a syntax error and a config file with a bare handle-shaped value: the loader throws, the message and cause contain neither canary, and the message still names the path. Mutation (restore directJSON.parseinreadJsonIfPresent): the regression fails. Root 1368/0, typecheck, format, biome clean.Found via the same class of bug in cortexkit/claustrum#28.
Need help on this PR? Tag
@codesmith-botwith what you need. Autofix is disabled.Summary by cubic
Prevents malformed account-store and dump JSON from echoing secret-like tokens from Bun’s
JSON.parseerrors. Previously, the account-store reader could include bare token identifiers in corruption logs; it now reports fixedinvalid JSONtext while retaining the file path and recovery hint.parseJsonRedactedhandling for account config, account state, and dump bodies.Written for commit dfb6bc0. Summary will update on new commits.