Detecting and Mitigating Prompt Injection via Control Characters in ChatGPT

dropbox · Tech · 2023 · source Agentic: no · promotional bias: low · source-backed · extracted with prompt 0.5.6 (schema v2)

Generated from extraction.json — do not edit by hand. Every claim cites verbatim source evidence; stated means the quote directly asserts the claim, implied means it supports it indirectly.

Problem

Domain: LLM prompt-injection security

Dropbox needed to harden LLM-powered product and research infrastructure against user-controlled prompt inputs that could bypass server-side prompt templates and model instructions.

Constraints:

Architecture

Dropbox ran black-box OpenAI Chat API experiments against GPT-3.5 and GPT-4 prompt templates. The team prepended or inserted encoded control characters such as carriage returns and backspaces into user-controlled questions, observed instruction betrayal, context forgetting, and hallucinations at scale, then recommended model- and application-specific input sanitization strategies rather than relying only on prompt wording.

Diagram confidence: explicit (topology described by the source).

flowchart LR
  user-controlled-input["User-controlled input"] --> prompt-template["Prompt template"]
  control-character-test-script["Control-character test script"] --> user-controlled-input["User-controlled input"]
  prompt-template --> openai-chat-api["OpenAI Chat API"]
  openai-chat-api --> model-response["Model response"]
  model-response --> experiment-log["Experiment log"]
  control-character-test-script --> experiment-log["Experiment log"]
  experiment-log --> sanitization-strategy["Sanitization strategy"]
  sanitization-strategy --> user-controlled-input["User-controlled input"]
Drag to pan · scroll or use +/− to zoom · reconstructed from the source's described component topology

Components

Component Role Interacts with
User-controlled input Question or content field that may carry encoded control characters. Prompt template
Prompt template Server-side instruction wrapper with context, IDK response, word limit, and no-new-instructions rule. OpenAI Chat API
OpenAI Chat API Model endpoint tested with GPT-3.5 and GPT-4 chat models. Model response
Control-character test script Adds backspace/carriage-return sequences at different magnitudes and offsets. User-controlled input, Experiment log
Model response Observed answer checked for context following, instruction betrayal, or hallucination. Experiment log
Experiment log Evidence base for sanitization guidance and model-specific risk assessment. Sanitization strategy
Sanitization strategy Application/model-specific input handling to block malicious control sequences while preserving valid modes where needed. User-controlled input

Data flow

Dropbox's security workflow builds a controlled prompt template with context, IDK response, max-word limit, and no-new-instructions guard. A test script submits user-controlled questions to OpenAI chat completions with increasing encoded control-character offsets. Observed responses are compared to expected context-constrained answers, and results inform sanitization guidance for production LLM services.

“Two of the models we have been testing at Dropbox are OpenAI's GPT-3.5 and GPT-4 (ChatGPT).”article, stated
“Using the OpenAI Chat API, we scripted some repeatable blackbox experiments to learn more about how the GPT-3.5 model interprets them.”article, stated

Why this architecture

Dropbox treated prompt injection as an empirical security-testing problem because control-character behavior was undocumented and model-specific. Repeatable API experiments let the team observe where prompt-template controls failed and translate those observations into sanitization guidance.

“This behavior is also not well documented and appears to be a previously unknown and novel technique for achieving prompt injection.”article, stated
“For engineers looking to build LLM-powered services, your risk tolerance, application design, and model of choice will dictate the required sanitization measures.”article, stated

Models used: GPT-3.5 · GPT-4 · gpt-3.5-turbo · gpt-4-32k

Scale

Alternatives considered (roads not taken)

Rely on prompt-template wording and delimiters

Rejected because: The control-character technique was agnostic to instruction wording and formatting suggestions.

“the prompt injection technique demonstrated here was agnostic to instruction wording changes and formatting suggestions within the template.”article, stated

Use the same sanitization policy for all models

Rejected because: Dropbox observed model-specific susceptibility and recommends testing based on model and application risk.

“it appears that not all LLMs are equally susceptible to these control character prompt injection techniques.”article, stated

Strip all escape/control sequences unconditionally

Rejected because: Some products may legitimately need source-code or binary-format content that includes escape/control sequences.

“there may be valid use cases for prompt input containing escape character control sequences.”article, stated

Patterns

guardrails-io-filtering (security)

Dropbox recommends sanitizing input according to application risk and model behavior to block abusive control-character prompt input.

“the best approach to mitigation involves sanitizing input appropriately for the input and chosen model.”article, stated

eval-driven-development (security-testing)

The team scripted repeatable black-box experiments against model APIs to test whether prompt controls held.

“we scripted some repeatable blackbox experiments to learn more about how the GPT-3.5 model interprets them.”article, stated

safety-policy-enforcement (security)

The work hardened internal infrastructure and server-side prompt controls for secure LLM product use.

“the Dropbox Security team has been advising on measures to harden internal Dropbox infrastructure for secure usage”article, stated

Tradeoffs

Sanitize input by model and application

Chose Risk-tuned sanitization over One universal control-character rule.

Rationale: Model susceptibility varies and some applications need to process control sequences legitimately.

“your risk tolerance, application design, and model of choice will dictate the required sanitization measures.”article, stated

Test black-box model behavior

Chose Repeatable API experiments over Assuming documentation covered control-character semantics.

Rationale: The effect was undocumented, so experiments were needed to discover actual model behavior.

“The effect of control characters is not discussed in detail within any of the model documentation from OpenAI.”article, stated

Balance security with valid control-sequence use cases

Chose Support modes for full character ranges where justified over Always stripping every escape sequence.

Rationale: Source-code and binary-format analysis may require preserving characters that are dangerous in ordinary prompt paths.

“We must balance the benefit of models utilizing control sequences with how this feature can be abused.”article, stated

Gotchas (what bit them)

Prompt templates can fail even when they explicitly forbid new instructions.

Root cause: Large numbers of encoded control characters changed how models interpreted the prompt context.

Resolution: Validate and sanitize user-controlled input before it enters the prompt template.

“user-controlled input can circumvent system instructions designed to constrain the question and information context.”article, stated

Control-character effects are model- and encoding-dependent.

Root cause: Different encodings and context-window sizes produced different failure thresholds.

Resolution: Run model-specific experiments and tune sanitization to the chosen model/application.

“There are at least two encodings of prompt control characters which can trigger this effect when sent en masse”article, stated

Security filters can break legitimate content if applied blindly.

Root cause: Some applications need to analyze source code or binary-like formats containing escape/control sequences.

Resolution: Consider product modes that support full character ranges while isolating or sanitizing risky prompt paths.

“when evaluating source code or other binary formats. Therefore, it would be wise to consider supporting modes of functionality within AI-powered products that support the full range of characters that the models accept.”article, stated

Evaluation

Dropbox used scripted black-box experiments with prompt offsets and increasing counts of encoded control characters, checking whether GPT-3.5 and GPT-4 followed context/instruction constraints or hallucinated/out-of-context answers.

Metrics: Control-character count/offset required for instruction betrayal · Context-following vs context-forgetting · Out-of-context answer production · Hallucination behavior · Model-specific susceptibility across GPT-3.5 and GPT-4

“As increasing numbers of backspaces are prepended to each question, you will see how GPT-3.5 eventually betrays its instructions and ignores its context.”article, stated
“GPT-3.5 hallucinates at offset -3500, where it believes the question is about a cubic polynomial.”article, stated

Outcomes

The study used OpenAI Chat API experiments in June 2023, including GPT-3.5 4096-token behavior and GPT-4 32K-context behavior.

3 supporting quotes
“We have demonstrated how control characters can be used to achieve prompt injection on templates designed to utilize a user-derived context and question”article, stated
“malformed inputs can be used to execute abuse or induce models to provide false or misleading information to users.”article, stated
“This post is a first step towards developing comprehensive prompt engineering and sanitization strategies”article, stated