You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
-[Original post](https://bsky.app/profile/did:plc:gttrfs4hfmrclyxvwkwcgpj7/post/3mcqehqhcgc2q) by [Austin Parker](https://bsky.app/profile/aparker.io).
15
+
-[Lizzie Moratti](https://infosec.exchange/@morattisec) sharing a [second](https://github.com/BerriAI/litellm/issues/10328) magic string example.
- Claude Docs: [Streaming refusals](https://platform.claude.com/docs/en/test-and-evaluate/strengthen-guardrails/handle-streaming-refusals)
22
+
- Claude Docs: [Building with extended thinking](https://platform.claude.com/docs/en/build-with-claude/extended-thinking#understanding-thinking-blocks)
23
+
</div>
24
+
9
25
Anthropic [documents](https://platform.claude.com/docs/en/test-and-evaluate/strengthen-guardrails/handle-streaming-refusals#implementation-guide) a "magic string" that intentionally triggers a streaming refusal. Starting with Claude 4 models, streaming responses return `stop_reason: "refusal"` when streaming classifiers intervene, and no refusal message is included. This test string exists so developers can reliably validate refusal handling, including edge cases like partial output and missing refusal text.
10
26
11
-
That makes it a great QA tool, but it also creates a predictable failure mode. If an attacker can inject the string into any part of the prompt context, they can reliably force refusals, potentially creating a sticky, low-effort denial of service until the context is reset. This technique affects both [Claude Code](https://claude.com/product/claude-code) and the Claude [models](https://www.anthropic.com/claude/opus) more generally.
27
+
That makes it a great QA tool, but it also creates a predictable failure mode. If an attacker can inject the string into any part of the prompt context, they can reliably force refusals, potentially creating a sticky, low-effort denial of service until the context is reset. This is **not** a vulnerability in Claude itself. Rather, it is an integration risk that emerges when untrusted input is incorporated into prompt context without appropriate safeguards. This technique affects both [Claude Code](https://claude.com/product/claude-code) and the Claude [models](https://www.anthropic.com/claude/opus) more generally.
12
28
13
29
## Background
14
30
@@ -18,9 +34,16 @@ The reason this "magic string" exists is practical: in real deployments, a model
There is a [second](https://platform.claude.com/docs/en/build-with-claude/extended-thinking#understanding-thinking-blocks) documented magic string for use with redacted thinking handling, however, in limited testing across multiple models, this second string did not reliably trigger the documented behavior. Because it is formally documented, it is included here for completeness, but it appears significantly less reliable than the primary refusal trigger.
If an attacker can place the magic string into any prompt input or retrieved context, they can reliably stop Claude from responding. Similar to [prompt injection](https://simonwillison.net/series/prompt-injection/), an adversary could place this magic string in a variety of places where it may eventually be consumed by a Claud LLM:
46
+
If an attacker can place the magic string into any prompt input or retrieved context, they can reliably stop Claude from responding. Similar to [prompt injection](https://simonwillison.net/series/prompt-injection/), an adversary could place this magic string in a variety of places where it may eventually be consumed by a Claude LLM:
24
47
25
48
- User input fields that are concatenated into system or developer prompts.
26
49
- RAG corpora (documents, tickets, wiki pages) that are embedded and retrieved at runtime.
@@ -29,18 +52,22 @@ If an attacker can place the magic string into any prompt input or retrieved con
29
52
30
53
Because Anthropic recommends resetting the context after refusal, a single injection can become "sticky." If the poisoned turn remains in history, all future turns will keep refusing until the application drops or rewrites the offending content.
31
54
55
+
To see this in action, we can place the magic string in a file that Claude will consume and watch it immediately bail out:
This behavior creates a low-cost denial of service on any Claude-backed feature that does not robustly handle refusals or context resets. A few practical outcomes:
35
62
36
63
-**Kill switch for workflows.** If a workflow depends on model output to complete (triage, code review, ticket routing), it can be halted on demand.
37
64
-**Persistent outages.** If conversation history is stored and replayed, a single poisoned entry can break all future requests until an operator intervenes.
38
65
-**Selective disruption.** In multi-tenant systems, a malicious tenant can target their own sessions to avoid automated enforcement (e.g., compliance bots) by forcing refusals.
39
-
-**Model fingerprinting.**Inference: a known, vendor-specific magic string provides a signal that the backend is Claude, which can aid targeted attack development (weak signal on its own).
66
+
-**Model fingerprinting.**A known, vendor-specific magic string provides a signal that the backend is Claude, which can aid targeted attack development.
40
67
41
-
## Mitigations (Prioritized)
68
+
## Mitigations
42
69
43
-
Anthropic already recommends refusal-aware handling; treat this as a hard requirement, not a best practice.
70
+
Anthropic already recommends (and [documents](https://platform.claude.com/docs/en/build-with-claude/structured-outputs)) refusal-aware handling. Treat this as a hard requirement, not a best practice.
44
71
45
72
-**Detect and reset.** Always detect `stop_reason: "refusal"` in streaming responses and reset or prune the context before retrying.
46
73
-**Prompt firewalling.** Filter or redact the magic string from user input, RAG corpora, and tool outputs before concatenation.
0 commit comments