Skip to content

🤖 fix: scan the decoded strings of backup files for secrets - #8100

Open
ThomasK33 wants to merge 8 commits into
mainfrom
backup-scan-json-strings
Open

ThomasK33 wants to merge 8 commits into
mainfrom
backup-scan-json-strings

Conversation

@ThomasK33

@ThomasK33 ThomasK33 commented Nov 10, 2026 •

Copy link
Copy Markdown
Member

Summary

The settings-backup secret scan now reads the decoded strings of every file it publishes, as well as the raw text. Before this change, a token that follows a JSON escape ("line one\nghp_…") passed the scan, and a push published it. That included a skill's .md or .txt file that holds JSON text: Xum publishes those without review.

Background

scanBackupFilesForSecrets matched each secret pattern against a file's text as written. In a JSON string, the escapes \n, \t, \r and \uXXXX end in a word character. The \b that starts each pattern then finds no boundary before a token that follows one. Main had this gap for every JSON file in a backup (preferences.json, manifests, shelf metadata). I found it while triaging a verifier finding on #8036, which closed the same gap for plugin rows only.

The first version of this PR decoded only .json and .jsonc paths. A verifier showed that this left a hole: a skill's .md or .txt file with JSON text and an escaped token still reached the remote with no approval. The file name does not say how a reader reads the text, so this version has no extension filter.

Implementation

  • The scan runs every pattern on the raw text and on each decoded string token of every collected file, keys and values at any depth. The tokens come from jsonc.createScanner. Text that is not JSON reads as it is, and only a double-quoted string can match. The change can only add matches.
  • It is a scanner and not jsonc.parse. parse keeps only the last of a duplicate key and drops __proto__, so a token in an earlier duplicate's value would escape. A scanner also reads a file that does not parse.
  • A file with no backslash skips the decoded scan. Without a backslash, each decoded string is the raw text between two quotes (or up to a line break or the end of the file). Those are non-word characters, so the raw check has already seen every match with the same word boundaries. The skip changes no result. It saves time, because the scan runs synchronously in the main process.
  • The plugin-row check from 🤖 fix: check backed-up plugin rows with the installer's own rules #8036 (jsonValueHidesSecret) keeps its behavior: a row that hides a token behind an escape is still left out of the plugin list. Its comments now say that the file scan also finds a JSON-escaped token, so the row check is a second layer. A percent escape stays the one case that only the row check covers, and a test pins that. I did not narrow the row check to percent escapes. That would change "left out" into "the push waits for review", which is a product change for 🤖 fix: check backed-up plugin rows with the installer's own rules #8036.

Validation

  • These tests fail on main and pass here:
    • a token after each of \n, \t, \r, \u0020 and \u000a,
    • one token for every \b-anchored pattern,
    • an object key at any depth,
    • a duplicate key's earlier value,
    • a .jsonc file with comments and a trailing comma,
    • a file that does not parse,
    • a preferences.json that holds an escaped token,
    • JSON text with an escaped token in skills/…/*.md, skills/…/*.txt, memory/global/*.txt and AGENTS.md,
    • a real push to a bare repository: a skill's .md file with JSON text and an escaped token stops with SECRET_DETECTED, nothing reaches the remote, and the push goes through only with the exact approval digest.
  • One test guards the other half of the scan: a .jsonc file whose token sits only in a comment is still flagged, because only the raw check reads comments.
  • A mutant of each part fails named tests:
    • decoding limited to .json and .jsonc paths again: the four non-JSON-name tests and the push test fail,
    • the raw check dropped: the comment-only test fails,
    • the decoded check dropped: 26 of 31 tests fail,
    • the scanner loop, the string-literal check and the call site: 13 to 28 tests fail.
  • The no-backslash skip has one equivalent mutant: the skip removed. It passes the same 31 tests and the push test, and the code marks it mutation-equivalent. A skip that always applies, or one that applies only when a backslash is present, fails 26 of 31 tests and the push test. I checked the skip a second way, with random texts:
    • 200,000 texts without a backslash got the same result from the new scan, from the scan without the skip, and from main's raw-only scan,
    • on 200,000 texts with a backslash, the decoded scan found 950 texts that the raw check misses, and the new scan found the same 950,
    • a skip that I inverted on purpose produced mismatches, so the check can see a difference.
  • Cost, measured against main's scan on the same files in one run, median of 7 interleaved runs. The host was loaded (load average about 45 on 96 cores), so absolute times vary by 2 to 4 times between runs. Compare the columns, not runs.
Input Main Decoded scan, no skip With the skip
The 7 test-fixture files 0.0 ms 0.0 ms 0.0 ms
Realistic payload, 3.6 MiB (400 skills, 100 memory files, 2 JSON): no file holds a backslash 2.6 ms 99 ms 2.4 ms
Same payload: 11% of files hold a backslash (62 of 588 installed skill files do) 3.5 ms 91 ms 8.8 ms
Same payload: 28% of files hold a backslash (23 of 83 files in this repo's docs and skills do) 2.6 ms 84 ms 24 ms
Same payload: every file holds a backslash 2.4 ms 79 ms 79 ms
One 8 MiB file of prose 3.9 ms 84 ms 4.3 ms
One 8 MiB file in the worst shape (a quote and a newline, repeated: 4 million string tokens) 6.1 ms 570 ms 2.9 ms
The same worst shape with one backslash at the start 4.4 ms 777 ms 704 ms

Risks

  • Correctness risk is low. The change only adds matches, and the skip changes no result. A file that holds an escaped token now waits for the user's secret approval, as any flagged file does.
  • Cost: the scan is synchronous, and a file that holds a backslash still pays for the decoded scan. The crafted worst case is a payload at the 64 MiB total cap: 8 files of 8 MiB in the worst shape, each with one backslash. It took 6.0 s in the latest run (median of 3, longest 8.5 s) and 15.9 s in an earlier run on a busier host, against 0.1 s on main. The skip does not lower this number, because one backslash per file defeats it. Only files that the user wrote can reach it. A realistic payload costs tens of milliseconds. I did not optimize further.
  • Not covered:
    • JSON text nested inside a JSON string ("{\"a\":\"x\\nghp_…\"}") decodes once, so a token behind its inner escape still passes.
    • A single-quoted string is not a JSON string, so a token behind an escape in one still passes.
    • A percent escape is not decoded by the file scan. Only the plugin-row check covers it.

Generated with xum • Model: anthropic:claude-opus-5-5 • Thinking: high • Cost: $257.92

…ecret scan

The scan runs \b patterns on raw file text. In a JSON string, \n, \t, \r and
\uXXXX end in a word character, so no boundary precedes a token after them.
The publish-time secret scan matched the \b patterns against raw text only. In a
JSON or JSONC string, \n, \t, \r and \uXXXX end in a word character, so a token
written after one had no boundary before it and a push published it. Also check
every string token of a .json or .jsonc file, keys included, decoded.
Trivia tokens are not string literals, so the check reads the same tokens either way.
# Conflicts:
#	src/node/services/backup/payload.ts
…decodes JSON strings

The scan's raw-text check still passes a token behind a JSON or percent escape, but the scan
now also reads each decoded string of a .json file, so a JSON escape no longer slips past the
scan as a whole. The row check keeps leaving such a plugin out of the list (a push does not
stop over a name the installer took), and the percent escape stays the one the scan cannot
see. Reword the two comments, and let the tests assert the scan holds the file too.
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Nov 10, 2026 •

Copy link
Copy Markdown
Codex Review Summary: ✅ Completed

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-11-10T17:25:51.792336Z c8c57e3 Manual request
🔒 Security Review ✅ Completed 2026-11-10T17:26:45.731197Z c8c57e3 Manual request
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@github-actions

github-actions Bot commented Nov 10, 2026 •

Copy link
Copy Markdown
Contributor

🟢 e2e stories (Haiku): 14 passed

22 agent steps · 7 replayed from cache · 15 model calls · 47.1k tokens (23% cached)
Spend: $0.09 of the $1.00 cap (proxy ledger)

All 14 tests in 9 files
Test Agent Time
🟢 chatRestart.e2e.ts · 1 passed 1 step · 1 call 5.6s
🟢 a chat survives a restart of the server 1 step · 1 call 5.6s
🟢 compaction.e2e.ts · 1 passed 1 step · 1 call 4.5s
🟢 /compact replaces the old chat with a summary 1 step · 1 call 4.5s
🟢 pluginTrustRestart.e2e.ts · 1 passed 4 steps · 2 calls 10.1s
🟢 a trusted plugin hook stays trusted after the server restarts 4 steps · 2 calls 10.1s
🟢 settingsRoundTrip.e2e.ts · 1 passed 2 steps · 1 call 9.3s
🟢 a chat survives trips through Settings 2 steps · 1 call 9.3s
🟢 sidebarPerWorkspace.e2e.ts · 1 passed 4 steps · 1 call 4.7s
🟢 a new workspace starts with its right sidebar collapsed while another keeps it open 4 steps · 1 call 4.7s
🟢 smoke.e2e.ts · 1 passed 2 steps · 1 call 2.7s
🟢 the agent opens the playground workspace 2 steps · 1 call 2.7s
🟢 streamErrors.e2e.ts · 1 passed 1 step · 1 call 6.7s
🟢 stream errors show in the chat, and the chat recovers 1 step · 1 call 6.7s
🟢 todoNudge.e2e.ts · 1 passed 1 step · 1 call 3.2s
🟢 the agent finishes open TODO items after the turn-end nudge 1 step · 1 call 3.2s
🟢 touchAlignment.e2e.ts · 6 passed 6 steps · 6 calls 24.2s
🟢 the Settings close button is level with the title on a touch screen 390px wide 1 step · 1 call 4.0s
🟢 the Settings close button is level with the title on a touch screen 768px wide 1 step · 1 call 4.4s
🟢 Backup settings checkboxes are small and level with their labels on a touch phone 1 step · 1 call 4.9s
🟢 the heartbeat checkbox is small and level with its label on a touch phone 1 step · 1 call 3.7s
🟢 a reply's model and time stay on one line on a touch phone 1 step · 1 call 3.5s
🟢 the workspace actions menu stays on the title row on a touch phone 1 step · 1 call 3.6s

e2e 0.20.0 · 1m 14s · web · run artifacts

🟢 e2e Electron stories (Haiku): 3 passed

3 agent steps · 3 model calls · 7.9k tokens (22% cached)
Spend: $0.02 of the $1.00 cap (proxy ledger)

All 3 tests in 3 files
Test Agent Time
🟢 electron/deepLink.e2e.ts · 1 passed 1 step · 1 call 6.5s
🟢 a deep link of a second launch starts a chat in the running app 1 step · 1 call 6.5s
🟢 electron/menuBar.e2e.ts · 1 passed 1 step · 1 call 5.9s
🟢 the workspace menu bar is the desktop title bar 1 step · 1 call 5.9s
🟢 electron/smoke.e2e.ts · 1 passed 1 step · 1 call 5.9s
🟢 Xum Electron opens the playground workspace 1 step · 1 call 5.9s

e2e 0.20.0 · 20.5s · electron · run artifacts

🟢 e2e agent repros (Haiku): no tests selected

Spend: $0.00 of the $1.00 cap (proxy ledger)

e2e 0.20.0 · 5.8s · 2 targets (web, phone) · run artifacts

@ThomasK33

Copy link
Copy Markdown
Member Author

@codex security review

Head: 46ef1e2

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. Delightful!

Reviewed commit: 46ef1e2fae

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

@chatgpt-codex-connector

Copy link
Copy Markdown

🛡️ Codex Security Review · Automatically triggered

Security review completed. No security issues were found in this pull request.

Reviewed commit: 46ef1e2fae

View security finding report

Only the user who started this review can view the report in Codex.

ℹ️ About Codex security reviews in GitHub

This is an experimental Codex feature. Security reviews are triggered when:

  • You comment "@codex security review"
  • A regular code review gets triggered (for example, "@codex review" or when a PR is opened), and you’re opted in so security review runs alongside code review

Once complete, Codex will leave suggestions, or a comment if no findings are found.

…aches a push unreviewed

A .md or .txt file in a skill is published without review, and the decoded-string scan ran
only for .json and .jsonc paths. Also pin that a JSONC comment is still read by the raw check.
…d .jsonc

A skill's .md or .txt file is published without review and can hold JSON text, so the file
name does not say how a reader reads it. Text that is not JSON reads as it is, and only a
quoted string can match, so this only adds matches.
Without a backslash each decoded string is the raw text between two quotes, and the raw check
has already seen it with the same word boundaries, so the skip changes no result. The scan is
synchronous, and a file with no backslash needs none of it.
@ThomasK33 ThomasK33 changed the title 🤖 fix: scan the decoded strings of JSON backup files for secrets 🤖 fix: scan the decoded strings of backup files for secrets Nov 10, 2026
@ThomasK33

Copy link
Copy Markdown
Member Author

@codex security review

Head: c8c57e3

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: c8c57e3d8d

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment on lines +182 to +184
const scanner = jsonc.createScanner(text);
for (let token = scanner.scan(); token !== jsonc.SyntaxKind.EOF; token = scanner.scan()) {
if (token === jsonc.SyntaxKind.StringLiteral && matchesSecretPattern(scanner.getTokenValue())) {

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 Badge Scan strings hidden after comment-like text

When a non-JSON backup file contains an unquoted URL before embedded JSON on the same line—for example, https://host {"response":"x\\nghp_..."}—jsonc-parser treats the // and everything following it as line-comment trivia, so this scanner never emits the embedded StringLiteral; the raw regex also misses the token because the raw escape ends in the word character n. Since this function now scans auto-published Markdown/text files, a skill or API log with this common layout can still push a credential without SECRET_DETECTED; scan quoted strings without allowing unrelated JSONC comment syntax to mask the remainder of arbitrary files.

Useful? React with 👍 / 👎.

@chatgpt-codex-connector

Copy link
Copy Markdown

🛡️ Codex Security Review · Automatically triggered

Security review completed. No security issues were found in this pull request.

Reviewed commit: c8c57e3d8d

View security finding report

Only the user who started this review can view the report in Codex.

ℹ️ About Codex security reviews in GitHub

This is an experimental Codex feature. Security reviews are triggered when:

  • You comment "@codex security review"
  • A regular code review gets triggered (for example, "@codex review" or when a PR is opened), and you’re opted in so security review runs alongside code review

Once complete, Codex will leave suggestions, or a comment if no findings are found.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant