Skip to content

WEB-6954: Apply memory file fixes after the daily root scan - #441

Merged
anonpran merged 12 commits into
stagingfrom
web-6954-memory-fix-agent
Nov 27, 2026
Merged

anonpran merged 12 commits into
stagingfrom
web-6954-memory-fix-agent

Conversation

@anonpran

@anonpran anonpran commented Nov 27, 2026 •

Copy link
Copy Markdown
Contributor

Summary

  • Laptop side of Fix It for memory files. After the daily root scan on macOS, the agent removes credentials the backend has confirmed from the user's memory file and reports the outcome.
  • The backend and dashboard are already in prod. Until this ships, Fix It shows disabled.

Changes

Change File
Helper that edits one file. It runs as the file's owner with an empty environment, no key and no network. One JSON request on stdin, one JSON line on stdout. scripts/coding_discovery_tools/memory_fix_helper.py
Self-test, capability, hash post, helper launch, results. scripts/coding_discovery_tools/memory_fix.py
Scan start sends capabilities: ["memory_fix"] when the self-test passes; the fix step runs after the completed event. ai_tools_discovery.py, utils.py
55 tests. tests/test_memory_fix.py

How it works

  1. Before scan start, on macOS as root, the agent pings its own helper as a scanned user. Only if it answers does the agent say it can fix.
  2. After the scan is reported complete, and only if the backend said fixes are waiting, it posts the sha256 of each user-scope memory file it reported under ~/.claude/.
  3. For each ready answer it starts the helper as the file's owner. pending files are asked about again every 5 minutes, 5 asks in all (at 0, 5, 10, 15 and 20 minutes). changed files and files left out are not asked about again in that run.
  4. The helper refuses a path outside the memory folder the agent listed, any symlink on the path, a hard link, another owner, a file over 50 KB and invalid UTF-8. It checks the whole-file sha256, replaces each value with [credential removed by Unbound] from the end backwards, writes a temp file beside the original, re-checks the original is unchanged, renames, and re-reads.
  5. Results go back with the token. A helper that answers nothing posts no result, so the backend hands the fix out again the next day.

Notes for review

  • Nothing here can fail the scan: every step is wrapped, and the fix step runs after completed.
  • No backup copy is made; it would keep the secret on disk.
  • A user whose ~/.claude is a symlink gets "refused". This fails safe and is a known limit.
  • Tested end to end locally against the backend branch: real scan, real helper process, file edited after its last scan, fixed in the same run, mode and owner kept, no temp file left.
  • Not tested: the switch from root to the user (needs sudo), and a packaged binary on a Jamf-managed Mac.
  • Tests run on Python 3.9.6 and 3.12.

Pairs with websentry-ai/ai-gateway-data#3587 and websentry-ai/setup#451. Merge both of those first.

Linear: WEB-6954

🤖 Generated with Claude Code

Unbound Review · Score 5/5 (no findings) · 366398c

  • codex (own score 5/5): The PR adds a macOS memory-file fix capability, including a user-privileged helper, post-scan polling, and result reporting. I found no actionable defects or applicable repository rule violations in the reviewed changes.
  • claude (own score 4/5): The PR adds Fix It for memory files on macOS root runs. It runs a self-test and advertises a capability at scan start; after the completed event it posts the sha256 of each user-scope ~/.claude memory file it reported, then starts a helper as the file's owner that blanks the spans the backend confirmed. The spans must fall inside what the agent's own secret rules flagged, and the file is swapped in atomically. I checked the hook points in main(),

findings: 0 P0 · 0 P1 · 0 P2 (top 5 P0/P1 inline) · engines: codex ✅ · claude ✅

rules applied: CLAUDE.md

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
…alls do not exist (WEB-6954)

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>

@vigneshsubbiah16 vigneshsubbiah16 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🛡️ Automated Security Review (consensus)

1 finding — 0 high-confidence, 1 to triage. Reviewers: Claude, Semgrep, Gitleaks.

  • [LOW] Fix tokens and users' memory paths visible on the curl command line 🟡 — scripts/coding_discovery_tools/memory_fix.py:178
    • What: _post_json sends each request body through the existing _curl_post_json. The PR's own comment at FILES_PER_POST says this body goes on curl's command line. So every user's memory file paths and hashes, and the backend's one-time fix tokens in the results post, end up in the argv of a process running as root.
    • Why: On macOS, any local user can read other processes' argv with ps. That lets one user see another user's ~/.claude memory file paths, and grab fix tokens while the post is in flight. ⚠️ How much this matters depends on whether _curl_post_json also puts the API key on argv (not visible in this diff). A token is only useful to someone who also has the API key.
    • Fix: Pass the JSON body to curl over stdin (--data-binary @-) or through a 0600 temp file, not argv. Do this at least for the new memory-fix endpoints, and ideally inside _curl_post_json itself.
    • Flagged by: Claude

Pre-existing (not introduced by this PR)

  • Semgrep python-logger-credential-disclosure at scripts/coding_discovery_tools/utils.py:2347 and :2356. These lines are outside the hunks this PR changed. The log lines print a file path and an exception, not the credential value. Low severity, listed here only for completeness.

🤖 consensus review · reviewers: Claude, Semgrep, Gitleaks · head d74fbc95 · 2026-11-27T09:34Z

… (WEB-6954)

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>

@vigneshsubbiah16 vigneshsubbiah16 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🛡️ Automated Security Review (consensus)

1 finding — 0 high-confidence, 1 to triage. Reviewers: Claude, Semgrep, Gitleaks.

  • [LOW] Spans from the backend are applied without a local check that they hold a credential 🟡 — scripts/coding_discovery_tools/memory_fix_helper.py:193
    • What: fix_file checks only that each span is a sorted, in-bounds [start, end] pair. It never checks that the text inside the span looks like a credential before replacing it with the marker.
    • Why: The helper runs as the user, and the backend can only target files the agent posted. Even so, a compromised or buggy backend that answers with a matching hash can blank out any text in a ~/.claude memory file. Claude Code loads these files into the model's context. Removing text such as "do not", or an instruction to confirm before running commands, quietly changes how the user's coding agent behaves. The file ends up showing [credential removed by Unbound], so the user is unlikely to notice.
    • Fix: Before swapping the file in, run memory_secret_rules.find_secrets on the original text, or on each span with a little context around it. Refuse with refused when a span does not overlap a value the local rules detect. Also cap the number of spans and their total length per file.
    • Flagged by: Claude

Pre-existing (not introduced by this PR)

  • [MEDIUM] API key in curl's process arguments — scripts/coding_discovery_tools/s3_uploader.py:269. _curl_post_json still passes Authorization: Bearer {api_key} as a -H argument, so any local user can read it with ps. The PR's own new comment says the process list is world-readable, yet it moves only the request body to stdin. The new fix step polls for up to 20 minutes, which adds more chances to catch the key. Fix: pass the header through stdin or a config file, e.g. -H @- or --config - (curl ≥ 7.55).

🤖 consensus review · reviewers: Claude, Semgrep, Gitleaks · head 6732f5ba · 2026-11-27T09:52Z

…WEB-6954)

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>

@vigneshsubbiah16 vigneshsubbiah16 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

✅ Security consensus: no issues found. (reviewers: Claude (lead), Semgrep, Gitleaks)

Pre-existing (not introduced by this PR)

  • [LOW] API key is still visible in the process list — scripts/coding_discovery_tools/s3_uploader.py:269
    • What: _curl_post_json passes -H "Authorization: Bearer {api_key}" as a curl command-line argument. On macOS, any local user can read other users' process arguments with ps.
    • Why it matters here: the header line itself is unchanged. But this PR edits the same argument list to move the request body to stdin "so it stays out of the process list", and the key stays exposed. The new fix polling also adds repeated root curl calls with the key on the command line, for up to 20 minutes per run.
    • Fix: keep the header off the command line. For example, write it to a 0600 temp file and pass -H @<file>, or put both the header and the body into a curl config that curl reads from stdin (-K -).
    • Flagged by: Claude
  • The two Semgrep python-logger-credential-disclosure hits at utils.py:2347 and utils.py:2356 are on lines this PR does not touch. They log a file path and an exception, not a credential value, so they look like false positives and are not raised here.

🤖 consensus review · reviewers: Claude, Semgrep, Gitleaks · head 38e1202e · 2026-11-27T10:13Z

anonpran and others added 2 commits November 27, 2026 16:23
…954)

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
… that landed in that instant (WEB-6954)

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
@anonpran

Copy link
Copy Markdown
Contributor Author

/review code

@vigneshsubbiah16 vigneshsubbiah16 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

✅ Security consensus: no issues found. (reviewers: Claude lead review, Semgrep, Gitleaks)

Pre-existing (not introduced by this PR)

  • [LOW] API key passed on the curl command line — scripts/coding_discovery_tools/s3_uploader.py:269
    • What: _curl_post_json passes Authorization: Bearer {api_key} as a curl argument (-H). On macOS, any local user can read other users' process arguments with ps.
    • Why: this PR moves the request body to stdin for exactly this reason, but the bearer key stays in the arguments. The new fix step can also poll for up to 20 minutes, so the key stays visible to local users for longer on each root run.
    • Fix: pass the header through curl's config on stdin (for example -K - with header = "Authorization: Bearer …"), or use -H @file with a 0600 temp file. That keeps the key out of the process list as well as the body.

🤖 consensus review · reviewers: Claude, Semgrep, Gitleaks · head 1924680a · 2026-11-27T11:03Z

anonpran and others added 2 commits November 27, 2026 16:41
…, ACL and extended attributes (WEB-6954)

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
…ainst a real localhost backend (WEB-6954)

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
@anonpran

Copy link
Copy Markdown
Contributor Author

/review

@vigneshsubbiah16 vigneshsubbiah16 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

✅ Security consensus: no issues found. (reviewers: claude, semgrep, gitleaks)

Pre-existing (not introduced by this PR)

  • [MEDIUM] API key still passed to curl on the command line — scripts/coding_discovery_tools/s3_uploader.py:269
    • What: _curl_post_json passes -H "Authorization: Bearer {api_key}" as a command-line argument. This PR moves the request body to stdin because the process list is readable by every local user. The bearer key on the line above it is still in that list.
    • Why: The new memory-fixes/ and memory-fixes/results/ posts use this function too. That adds more windows in which any local account on a shared Mac can read the device API key with ps.
    • Fix: Send the headers through stdin as well. For example, use -H @- or --config - with the Authorization line, or write a 0600 header file and pass -H @file.
    • Flagged by: claude

🤖 consensus review · reviewers: Claude, Semgrep, Gitleaks · head 86d22c87 · 2026-11-27T11:21Z

…6954)

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
@anonpran

Copy link
Copy Markdown
Contributor Author

/review code

@vigneshsubbiah16 vigneshsubbiah16 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

✅ Security consensus: no issues found. (reviewers: claude, semgrep, gitleaks)


🤖 consensus review · reviewers: Claude, Semgrep, Gitleaks · head ac8c7504 · 2026-11-27T13:03Z

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>

@vigneshsubbiah16 vigneshsubbiah16 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

✅ Security consensus: no issues found. (reviewers: Claude, Semgrep, Gitleaks)

Pre-existing (not introduced by this PR)

  • [LOW] Device API key passed to curl on the command line 🟡 — scripts/coding_discovery_tools/s3_uploader.py:269
    • What: _curl_post_json still puts Authorization: Bearer {api_key} in curl's command-line arguments. Any local user on macOS can read those arguments with ps.
    • Why: The new body_on_stdin option moves only the request body to stdin. The code comment gives that same reason ("the process list, which every local user can read"), but the bearer key stays visible. The new fix loop sends many root-run curl requests over a window of up to 20 minutes, so the key is exposed for longer.
    • Fix: Pass the header through stdin or a config file as well. For example, use -H @- or --config - with the header written to stdin, or a temp file with mode 0600. This removes the key from the command line.
    • Flagged by: Claude
  • The Semgrep python-logger-credential-disclosure hits at utils.py:2347 and utils.py:2356 are on lines this PR did not change. They log a file path and an exception, not a credential value. They are not raised as findings.

🤖 consensus review · reviewers: Claude, Semgrep, Gitleaks · head 3f012e5a · 2026-11-27T13:24Z

…954)

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>

@vigneshsubbiah16 vigneshsubbiah16 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

✅ Security consensus: no issues found. (reviewers: claude, semgrep, gitleaks)

Pre-existing (not introduced by this PR)

  • scripts/coding_discovery_tools/s3_uploader.py:269: _curl_post_json still passes Authorization: Bearer {api_key} as a curl command-line argument. Any local user can read the process list, so they can see the agent's API key while each POST runs. This PR moves the request body to stdin for exactly that reason but leaves the key in argv. It also adds many more of these calls: fix polls and result posts. Fix: pass the header through stdin or a 0600 temp file with -H @file / --config -.
  • Semgrep python-logger-credential-disclosure at scripts/coding_discovery_tools/utils.py:2347 and :2356: these lines are outside the diff. They log a file path and an exception message, not the credential value. This looks like a false positive, so it is listed for completeness only.

🤖 consensus review · reviewers: Claude, Semgrep, Gitleaks · head 5c40a1df · 2026-11-27T14:02Z

…-6954)

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
@anonpran

Copy link
Copy Markdown
Contributor Author

/review code

@vigneshsubbiah16 vigneshsubbiah16 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

✅ Security consensus: no issues found. (reviewers: Claude, Semgrep, Gitleaks)


🤖 consensus review · reviewers: Claude, Semgrep, Gitleaks · head 366398c9 · 2026-11-27T14:22Z

@anonpran
anonpran merged commit a7c5c2f into staging Nov 27, 2026
11 checks passed
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.

3 participants