Repository navigation
CM-77702: Scan images attached to Copilot prompts for secrets - #590
Merged
Merged
Conversation
Ilanlido
reviewed
Nov 15, 2026
Altruistus
force-pushed
the
CM-77702-block-secrets-in-attached-images
branch
from
November 16, 2026 08:36
7aa3375 to
b4f7600
Compare
Ilanlido
previously approved these changes
Nov 16, 2026
The UserPromptSubmit hook gets only the prompt text, but by the time it runs Copilot has saved every attached image to disk. The Copilot integration now finds them (@path mentions and pasted images in Copilot CLI; send-time copies and pastes in VS Code, saved since the session's previous prompt), and the prompt handler sends them with the text in one scan, so a secret in a screenshot blocks the prompt like a secret in its text. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
A mention whose quote was left open read to the next quote anywhere in the prompt, so the image mentions in between went unscanned. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The server decides whether to scan them, so the CLI no longer reads an image setting from the guardrail config. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…chat Every VS Code chat's attachments saved since the session's previous prompt were taken, so a prompt could be blocked by an image attached in another window, and a Copilot CLI prompt could pick up VS Code attachments. The chat is now the one whose session database records the hook's session id. The shared folder of pasted images is no longer read: agent sessions copy every sent attachment into the chat's folder, and that folder also holds images that were pasted but never sent. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Altruistus
force-pushed
the
CM-77702-block-secrets-in-attached-images
branch
from
November 16, 2026 10:04
b4f7600 to
4160741
Compare
omer-roth
reviewed
Nov 16, 2026
omer-roth
left a comment
Collaborator
There was a problem hiding this comment.
KISS / DRY / YAGNI pass: three medium findings, inline.
The file excluder, its string helpers and the console printers never see an image document, so they are back to their text-only versions. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Collecting the images already reads and checks every file, so the bytes now travel with the path to the scan instead of being read and checked again. Prompt, text and file-read scans also share one scan helper. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
omer-roth
approved these changes
Nov 16, 2026
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.
What
The Copilot
UserPromptSubmithook now also scans images attached to the prompt, so a secret in a pasted screenshot blocks the prompt (or is reported), just like a secret in the prompt text.Jira: CM-77702
Why
The hook payload carries only the prompt text. In live probes (VS Code 1.145.2, Copilot CLI 1.0.107), Copilot had already saved every attached image to disk by the time
UserPromptSubmitran, so the hook can find the images and block the turn.userPromptTransformedcan't block, so it isn't used.Where to look
ides/copilot.py→Copilot.collect_prompt_imagesgathers images from three sources, in order:@pathmentions, resolved againstcwd.[image: <name>]placeholder names a file in the temp directory.<user data>/agentSessionData/<chat id>/attachments/*/*, forCodeandCode - Insiders.The VS Code folder is named after VS Code's chat id, not the hook's
session_id, so the chat is the one whosesession.dbrecords the hook'ssession_id(sdkSessionId, read-only). Its files saved since the session's previous prompt are taken. Other chats' attachments never count, and a Copilot CLI prompt gets no VS Code attachments. VS Code's local chat (not an agent session) is not covered.scan/prompt_images.pyis the IDE-agnostic part:~/.cycode/ai-guardrails-prompt-marks.json. A first prompt looks back 600 s; session start isn't used because VS Code fires it together with the first prompt, after its attachments were saved.scan/scan_command.py: images are collected for every prompt event, after the detach decision, so a report-mode child still finds them. Collection is best-effort, and the text is always scanned. The images are always sent; the server decides whether to scan them.scan/handlers.py: one scan withprompt-content.txtplus one bytes document per image (image-<n>-<name>), built from the bytes read at collection, so each image is read once. Prompt, text and file-read scans share one scan helper. The verdict, block, timeout and fail-open behaviour are unchanged.scan/utils.py: a finding in an image reads… in image "<name>", so the developer knows which attachment to remove.Bytes support only where image documents go:
Document.content: str | byteswithtext_content,InMemoryZip.appendand batch sizing.README: the data-collected section says that attached images are sent with the prompt.
Tests
pytest tests: 1512 passed, 1 skipped (an existing Windows-only test).test_prompt_images.pyandtest_document.py, plus additions totest_copilot.py(includingsession.dbreads against a real SQLite file),test_handlers.py,test_scan_command.pyandtest_in_memory_zip.py.ruff check .andruff format --check .are clean.Release
The CLI always sends the images, so release this only after the server side that scans them is live in every region.
🤖 Generated with Claude Code