Skip to content

CM-78366: Scan images attached to Claude Code, Codex and Cursor prompts for secrets - #592

Merged
Altruistus merged 6 commits into
mainfrom
CM-78366-block-secrets-in-images-claude-code
Nov 18, 2026
Merged

Altruistus merged 6 commits into
mainfrom
CM-78366-block-secrets-in-images-claude-code

Conversation

@Altruistus

@Altruistus Altruistus commented Nov 17, 2026 •

Copy link
Copy Markdown
Collaborator

TL;DR

A secret in a screenshot attached to a Claude Code, Codex or Cursor prompt goes to the model unscanned, because each prompt hook only scans the prompt's text. Each hook now finds the images attached to the prompt and scans them with the text in one scan, the same way the GitHub Copilot hook already does. Start with ides/claude_code.py, ides/codex.py and ides/cursor.py; the shared helpers are in scan/prompt_images.py.

Why

The Secret in prompt guardrail should block or report a secret whether it is typed or shown in an attached image. None of the three agents puts the images in the hook payload, so each hook finds them where its agent keeps them when the hook runs. The server decides whether to read images, so the client always sends them.

Reviewer notes

Each agent was checked live with a probe hook that blocked every prompt, so nothing reached a model unless the probe let it through.

  • Claude Code (2.1.326): it saves every attached image before the hook runs, as <$CLAUDE_CODE_TMPDIR or /tmp>/claude-<uid>/<project>/<session_id>/images/<N>.<ext>.
    • The prompt takes the files its [Image #N] chips name. It also takes the files saved since the session's previous prompt (the Copilot hook's prompt marks; a first prompt looks back 600 s), which covers VS Code and the desktop app, whose prompts have no chips. @path mentions are added on top.
    • Pastes, two images in one prompt, and mentions were all found in the terminal; the chip-less path was found headless.
    • Gaps: no image file is written when prompt history is off, or for Remote Control. On Windows, which has no uid, any claude* folder of the temp directory is read; this is unverified.
  • Codex (0.169.0): the hook prompt keeps each image's [Image #N] chip, even for an image-only prompt, but names no file. The terminal UI saves a clipboard paste as codex-clipboard-<random>.png in the temp directory.
    • Each distinct chip takes one paste made since the session's last prompt that went through, newest first, within the last hour. Codex writes a prompt into the transcript only once its hook lets it through, so a blocked prompt sent again finds its paste again. Before any prompt goes through, the window reaches back 10 minutes from the session's start.
    • Without a transcript, no paste is taken. Codex sends a second prompt, with no transcript, to title a new thread, and it quotes the user's prompt chips and all.
    • Gaps: a dragged image, an @-popup pick and --image leave no paste. Each still gets a chip, so it can take a paste that a blocked prompt or another session made since the last prompt that went through. The VS Code extension sends images as data URLs. On WSL, a paste is saved as Windows' tmp*.png.
  • Cursor (3.30.14): the payload names no image, but Cursor's own record of the prompt does. That record is the bubble whose requestId is the hook's generation_id, in cursorDiskKV of the global state.vscdb, opened read-only. It lists context.selectedImages[].path.
    • Live, the record already listed the image when the hook started, every time. The hook waits up to 1 s for it as a margin.
    • An @-mentioned file is a link that the agent may read later, not an attachment, so it isn't collected here. Images the agent reads are a separate change to the file-read check, which reads them as text today.
    • Gaps: cursor-agent and remote windows are untested.
  • @path mention parsing moves unchanged from the Copilot integration to prompt_images.py.
  • Release only after the server side that scans attached images is live in every region. It already is, for Copilot.

Tests: pytest tests 1554 passed, 1 skipped. Each agent has its own cases: Claude Code's chips and windows, Codex's paste window against realistic transcripts, and Cursor's record in a real SQLite file. ruff check and ruff format --check are clean.

Jira

CM-78366 (Claude Code), CM-78367 (Codex), CM-78368 (Cursor)

🤖 Generated with Claude Code

Ilanlido
Ilanlido previously approved these changes Nov 17, 2026
@Altruistus Altruistus changed the title CM-78366: Scan images attached to Claude Code prompts for secrets CM-78366: Scan images attached to Claude Code, Codex and Cursor prompts for secrets Nov 17, 2026
Altruistus and others added 5 commits November 18, 2026 09:32
Claude Code saves each image attached to a prompt (pasted, dragged in, or
attached in VS Code or the desktop app) as <number>.<ext> in the session's
images folder of its temp directory before the prompt hook runs. The hook
now sends the images the prompt's [Image #N] chips name and those saved
since the session's previous prompt, plus @path mentions, with the prompt
text in one scan.

The @path mention parser moves from the Copilot integration to
prompt_images so both integrations share it.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
hasattr(os, 'getuid') can be true where calling it fails (a faked os
module on Windows), so decide by the platform instead.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
… through

A Codex chip doesn't say whether its image was pasted, dragged in or
picked from the @ popup, and a dragged or picked image leaves no paste.
Its chip took the newest unsent paste of the last hour instead: one a
blocked prompt or another session had left, which could block a prompt
for an image it never had.

A prompt now takes only pastes made since the session's last prompt
that went through. Codex writes a prompt into the transcript as a user
message only once its hook lets it through; a blocked prompt leaves only
turn bookkeeping, so a blocked prompt sent again still finds its paste.
Before any prompt goes through, the window reaches back ten minutes from
the session's start, which Codex writes when the first prompt is
submitted. The one-hour cap stays.

Checked against a live Codex 0.169.0 session: a drag after a prompt that
went through, and one after another session's paste, now take nothing,
while pastes, resends after a block and a new session's first paste are
found as before.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The transcript grows with every turn, images included, and the prompt
hook read all of it on every prompt to find the last prompt that went
through, which is usually near the end. It now reads from the end with
the reverse line reader the Claude Code integration already had (moved
to a shared helper) and stops there.

Read backwards, a user message is a prompt once a turn's start shows up
before it, and the session's context once the session's start does. A
session where no prompt has gone through yet is still read back to its
start, which is short. A message with no readable time no longer hides
behind a time of 0: any readable time counts.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@Altruistus
Altruistus force-pushed the CM-78366-block-secrets-in-images-claude-code branch from 977bae6 to 8b1bfc4 Compare November 18, 2026 08:34
…window

Review follow-ups, with no change in behavior:
- VS Code and Cursor share one per-platform user data directory helper
  and one read-only SQLite query helper (ides/_vscode_utils.py), so the
  rule never to lock the app's database lives in one place.
- The [Image #N] placeholder parsing used by Claude Code and Codex moves
  to prompt_images.image_chips, returning the numbers as written so
  Codex still counts #1 and #1 as two.
- Claude Code and Copilot collect through
  prompt_images.collect_since_prompt_mark, which keeps the order of
  reading the mark, selecting the images and moving the mark.
- Codex's paste window is two named steps: the last prompt that went
  through, then the session's start as the fallback.
- The Claude Code docstring says why chips are followed even though the
  time window finds re-saved images: they are the prompt's own reference
  to its files, so a named image is found even if it wasn't saved again.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@Altruistus
Altruistus requested a review from omer-roth November 18, 2026 10:59
@Altruistus
Altruistus merged commit 6beb0f5 into main Nov 18, 2026
25 checks passed
@Altruistus
Altruistus deleted the CM-78366-block-secrets-in-images-claude-code branch November 18, 2026 11:37
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