Skip to content

CM-78368: Scan images attached to Cursor prompts for secrets - #594

Merged
Altruistus merged 2 commits into
CM-78367-block-secrets-in-images-codexfrom
CM-78368-block-secrets-in-images-cursor
Nov 17, 2026
Merged

Altruistus merged 2 commits into
CM-78367-block-secrets-in-images-codexfrom
CM-78368-block-secrets-in-images-cursor

Conversation

@Altruistus

@Altruistus Altruistus commented Nov 17, 2026 •

Copy link
Copy Markdown
Collaborator

TL;DR

A secret in a screenshot attached to a Cursor chat goes to the model unscanned, because the prompt hook only scans the prompt's text. The Cursor prompt hook now reads which images Cursor attached to the prompt and scans them with the text in one scan.

Why

The Secret in prompt guardrail should block or report a secret whether it is typed or shown in an attached image. Cursor's beforeSubmitPrompt payload never names an image: its attachments list only rules. Cursor's own record of the prompt does name them: every pasted, dropped or picked image is saved to the workspace's storage when it is attached, and the record lists it.

Reviewer notes

  • Where the images are listed, from Cursor 3.28.7's bundled code and confirmed on live prompts in Cursor 3.30.14:
    • The prompt's record is the conversation's bubble whose requestId is the hook's generation_id.
    • It is stored in the cursorDiskKV table of the global state.vscdb.
    • Its context.selectedImages[].path lists each image's file.
    • It's opened read-only and found by a key range on bubbleId:<conversation_id>:. A dry run on a real past prompt found its screenshot.
  • Cursor starts saving that record just before it runs the hook and doesn't wait for the write, so the hook polls for up to a second. If the record never shows up, only the text is scanned. On live prompts in Cursor 3.30.14, the record already listed the image when the hook started every time, and collecting took about 1 ms.
  • @-mentioned files aren't attached to the prompt, so they aren't collected here. Cursor records them under context.fileSelections, and the agent opens one with its file tool only if it decides to. With file reads forbidden, the model reported that nothing was attached. With reads allowed, beforeReadFile fired for the PNG before the model read its text. Scanning images the agent reads is a separate change to the file-read check, which currently reads them as text.
  • Gaps: cursor-agent and remote (SSH or container) windows are untested; the database may not be on the machine that runs the hook.
  • Stacked on CM-78367: Scan images attached to Codex prompts for secrets #593 (CM-78367, Codex), which is on CM-78366: Scan images attached to Claude Code, Codex and Cursor prompts for secrets #592; review only this PR's commit.

Tests: pytest tests 1548 passed, 1 skipped. New Cursor cases use a real SQLite file and cover the prompt's record, a record without images, waiting for the record, giving up, missing ids, a missing or unreadable database, malformed records, and the per-platform data folder. ruff is clean.

Jira

CM-78368

🤖 Generated with Claude Code

Cursor's beforeSubmitPrompt payload never names an image: its attachments
list only rules. Cursor's own record of the prompt does. It is the
conversation's bubble whose requestId is the hook's generation_id, in the
cursorDiskKV table of its global state database (read-only), and
context.selectedImages lists each image's file: pasted, dropped and picked
images are saved in the workspace's storage when attached, @-mentioned ones
stay where they are. Cursor starts saving the record just before it runs
the hook, so the hook waits up to a second for it. The images are sent with
the prompt text in one scan.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
An @-mentioned file is not listed with the prompt's images: Cursor keeps
it as a link that the agent may read later with its file tool. Comment
only; the code and its line numbers are unchanged.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@Altruistus
Altruistus merged commit c97ec9e into CM-78367-block-secrets-in-images-codex Nov 17, 2026
10 checks passed
@Altruistus
Altruistus deleted the CM-78368-block-secrets-in-images-cursor branch November 17, 2026 15:56
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.

2 participants