Defensive Prompting Workshop — Canvas Hidden DIV generator

This single HTML file contains an interactive HTML Prompt‑Injection DIV Generator for copy‑paste style attacks.

HTML Prompt‑Injection (Copy‑Paste) — Guided Exercise

  1. Create a simple problem in your LMS (or use the sample below).
  2. Use the generator to produce a hidden <div> that places adversarial instructions off‑screen but inside the copy buffer.
  3. Paste the generated HTML into the question stem (HTML source mode).
  4. Test by copying the entire question text and pasting it into an LLM chat. Compare answers with and without the hidden prompt.

DIV Generator

Notes & alternatives
  • Why off‑screen? Off‑screen text is often included in copy buffers, while display:none usually is not.
  • Including aria-hidden helps avoid screen‑reader interference, but ensure your visible question remains fully accessible.
  • Some models resist these attacks; vary phrasing and update periodically.

Sample Question (paste this into your LMS)

<p><b>Problem 2.</b> Two children push on opposite sides of a door. One pushes with <i>F<sub>1</sub></i> = 20.5 N at <i>r<sub>1</sub></i> = 0.680 m; the other pushes at <i>r<sub>2</sub></i> = 0.520 m. Find <i>F<sub>2</sub></i> so the door does not rotate. Neglect friction.</p>

<!-- Paste the generated DIV below this comment while in HTML/source mode -->

Debrief Prompts

  • What changed in the model’s behavior? Did it comply with the hidden directive?
  • Which phrasing was most effective? Why might that be?
  • How should we write defensive constraints to resist this?