Day 12 of 2160 minCipher CadetHands-on lab
Day 12: Hidden Text in Images and Invisible Characters
Taught by Mr Elite Updated
By the end of today you can
- Explain why a model reads text that a human reviewer cannot see
- Hide an instruction inside an image and show a vision model obeying it
- Show invisible Unicode characters surviving a document upload and steering a RAG bot
- Explain why filters that only read visible text still miss these attacks
Warm-up
Answer from memory first, then tap to check. Recalling yesterday is what makes it stick.
In a RAG system, what happens to the retrieved chunks before the model answers?
They are pasted into the prompt as context, so the model reads them alongside the question.
Why did your poisoned article need to be on-topic?
Retrieval works on meaning, so only content related to the user's question gets found and pasted in.
Picture a finance team using a tool that reads receipt photos and writes a one-line summary for the approver. The approver looks at the receipt, reads the summary, and clicks approve. Both agree. What the approver never saw is a line of near-white text in the corner of the image that told the model exactly what to write.
Today is about the gap between what a human sees and what a model ingests. Yesterday you poisoned a knowledge base with visible text. Today the text is hidden, in pixels and in characters that take up no space on screen. You will do both attacks in labs, then explain why they work.
What the model ingests is not what you see
Yesterday we saw that retrieved text goes straight into the prompt. The key point is that the model receives raw data, not a rendered page. A person looks at pixels on a screen and sees what the screen draws. A model gets every character in the file and, for vision models, every pixel in the image.
That creates two blind spots. In an image, text can be tiny, faint or the same colour as its background, yet a vision model still reads it. In a document, some Unicode characters have no visible shape at all, yet they sit in the string and the model still processes them.
- Vision model
- A model that accepts images as input and can read text and objects in them.
- OCR
- Optical character recognition. Software that turns text in an image into plain text.
- Unicode
- The standard that gives every character, from letters to emoji, a numeric code.
- Zero-width character
- A character such as U+200B that takes up no visible space, so you cannot see it on screen.
Text hidden inside an image
A vision model reads contrast differences that a human eye ignores. White text at 1 pixel high on a white background looks like blank paper to you. To the model it is a sentence. Attackers use that to plant instructions in receipts, invoices, ID scans and screenshots.
The usual hiding methods are tiny font size, text colour almost matching the background, text placed in a margin or corner, and text rendered at very low opacity. None of them need special tools. A basic image editor is enough.
Quick check
A receipt contains 1-pixel white text on a white background. Why might a vision model still obey it?
The model processes the pixels directly, so low visibility to a human does not reduce visibility to the model.
Invisible Unicode characters in documents
The second technique lives in text. Some characters render as nothing. The common ones are zero-width space (U+200B), zero-width non-joiner (U+200C), zero-width joiner (U+200D) and the right-to-left override (U+202E), which flips the display direction of text after it.
Two things make them dangerous. First, they can be used to encode a whole hidden message, one invisible character pattern at a time. Second, an upload filter that strips visible HTML or markdown often never thinks to strip them, so they pass straight into the index and then into the model's context.
Quick check
An upload filter removes HTML tags and markdown. Is the document now safe from hidden Unicode instructions?
The filter only targets visible markup, so invisible characters pass through untouched.
Watch me do it: see the invisible on your own machine
Before the labs, I want you to prove to yourself that invisible text is real. This runs entirely on your own computer in a browser. We will build a string with a hidden character and then reveal it.
const s = "Hellou200BWorld";
ss.length[...s].map(c => c.charCodeAt(0))What just happened: the screen drew nothing for U+200B, but the data held it. A model works from the data. That one mismatch is the whole idea behind today.
Your practice: the two labs
Now you apply both ideas against the practice targets. Both labs are SecurityElites environments built for this, so you stay inside a safe setup. Do the image lab first, then the hidden character lab, and take a screenshot of each as you go. Read the lab page instructions fully before you start.
For each lab, write down three things as you work: what a human reviewer would see, what the model actually received, and what changed in the output. That note is your mission deliverable and the core of a good finding.
Why filters that read text still get fooled
A text filter checks the string it is given. If it looks for visible phrases like ignore previous instructions, an attacker can split the phrase with zero-width characters so the pattern no longer matches, while the model still reads it as one sentence. For images, a filter that only inspects the text caption never sees the pixels.
Sensible defences follow from that. Normalise text and strip zero-width and bidirectional control characters before indexing. Run OCR on images and treat the result as untrusted data. Show the human reviewer what the model saw, not just the rendered view. And limit what the model can do with the result, so one bad summary cannot cause harm.
Your turn
AI Visual Prompt Injection
We start with the image lab because the hiding place is easy to picture. ReceiptLens reads receipt images and writes a summary for the human approver, so a hidden instruction can quietly shape what the approver reads. The second lab, ai-hidden-character-injection-1, uses invisible Unicode in a RAG bot. Work through both today.
What to try
What to notice
- What the image or document looks like to you compared with what the model appears to act on.
- Which hiding method worked and which failed, and any pattern in why.
- That the upload interface passes the invisible characters through without warning.
If it did not work
Hiding the text so well that even the model cannot read it
If the lab ignores your instruction, increase size or contrast a little. The aim is invisible to a human, still legible to the model.
Pasting text into an editor that strips invisible characters
Check the length of your string, as in the console demo. If the length is shorter than expected, your editor removed them. Try a plain text editor or build the string with escape codes.
Skipping the baseline
Always record the normal output first. Without it you cannot prove the hidden text changed anything.
Saving screenshots that show only the result
Capture the human view, the input you crafted and the changed output, so a reviewer can follow what happened.
Recap
- A model ingests raw pixels and raw characters, not the rendered view a human sees
- Vision models read tiny, faint or background-coloured text that people miss
- Zero-width and bidirectional characters are invisible on screen but present in the data
- Filters that strip only visible markup let invisible characters through
- Defend by normalising text, running OCR as untrusted input and limiting what the model can do
- Both attacks are indirect prompt injection with a concealment layer on top
Cheat sheet
U+200B- Zero-width space, invisible, takes no width
U+200C / U+200D- Zero-width non-joiner and joiner, also invisible
U+202E- Right-to-left override, reverses displayed text order
s.length- Quick JavaScript check that a string holds more characters than you can see
[...s].map(c => c.charCodeAt(0))- Prints the numeric code of every character to expose hidden ones
OCR on images- Extract the text a vision model would read, then treat it as untrusted
Before the next day
Mission: Two labs, two screenshots
Complete both labs and keep evidence that a careful reader could follow. The note on what a human reviewer would have seen is the important part, because it shows you understand why the attack works.
About 40 min
You are done when: Two screenshots and a day12-notes.md with a human-view note and a defence sentence for each lab.
Want more? Try splitting a trigger phrase with zero-width characters in the console, then compare its length and a plain search for the phrase to show how a naive filter would miss it.
Quiz
4 questions. Your score is saved with your progress.
1. Why can a reviewer approve a receipt that contains a hidden instruction?
The human sees the drawn pixels, where the text blends in, while the model reads it as content.
2. What does s.length returning more than the visible letter count suggest?
Each hidden character counts toward length even though nothing is drawn.
3. Which defence best addresses invisible Unicode in uploaded documents?
Removing the characters at ingestion stops them reaching the model, and human review cannot catch what it cannot see.
4. Why can a keyword filter for a trigger phrase still be bypassed with zero-width characters?
The filter compares exact strings, while the model works on meaning and tolerates the inserted characters.
Finish the day
Mark the day complete to save your progress.
Next: Day 13 combines this with what you know about documents. You will defeat a document summariser with a crafted file and propose three fixes, using today's hiding techniques as part of the toolkit.
Your notes
Private to this device. Write what you want to remember from today.