T01 · Skill Instruction Hijacking
- Location
index.js:23- Finding
Untrusted Input Enables Prompt Instruction Hijacking and Validation Bypass
- Content
View full analysis
Vulnerability Details
File Location:
index.js, lines 23–40
Vulnerability Type: Prompt injection and ineffective structural validation
Risk Level: MediumVulnerable Code
javascript function formatPrompt(question, context = "") { return ` You are a reasoning engine solving a hard logic problem. Question: ${question} Context: ${context} You MUST follow this format: --- REASONING --- (Your step-by-step logic here) --- FINAL ANSWER --- (Your concise final answer here) `; } function validateOutput(text) { if (!text || typeof text !== 'string') return false; const hasReasoning = text.includes("--- REASONING ---"); const hasAnswer = text.includes("--- FINAL ANSWER ---"); return hasReasoning && hasAnswer; }Technical Analysis
The
questionandcontextparameters are inserted directly into an instruction-bearing prompt without a robust trust boundary, escaping strategy, or explicit isolation as untrusted data. An attacker controlling either parameter can inject instructions that conflict with the wrapper's intended behavior, include forged structural markers, or ask the model to ignore the surrounding prompt.The corresponding validator does not enforce the actual output grammar. It only checks whether both marker strings occur somewhere in the response. It does not verify marker order, uniqueness, section boundaries, nonempty content, or the absence of arbitrary text before or after the expected sections. Consequently, malicious or malformed output can pass validation merely by containing both strings.
Attack Path
- An attacker supplies a crafted
questionorcontextcontaining instructions such as a request to ignore the wrapper, follow a different task, or emit attacker-selected content. formatPrompt()interpolates this content directly alongside trusted instructions.- The downstream language model interprets the injected ...[truncated 805 chars]
- An attacker supplies a crafted
- Remediation
View remediation
Remediation Suggestions
- Treat
questionandcontextas untrusted data and place them inside clearly delimited data sections that cannot be confused with trusted instructions. - Reject, escape, or encode reserved structural markers occurring in caller-controlled values.
- Keep authoritative instructions separate from untrusted content and explicitly state that content inside the data boundaries must not be interpreted as instructions.
- Prefer a structured model-output mechanism, such as schema-constrained JSON, when supported by the downstream model API.
- Replace substring checks with a strict parser that verifies marker order, uniqueness, permitted surrounding text, and nonempty section contents.
- Apply maximum input and output lengths to limit abuse.
- Do not rely on prompt formatting or output validation as a security boundary for sensitive tool execution. Independently authorize any downstream action.
- Add tests covering embedded markers, reversed markers, duplicate sections, trailing malicious content, empty sections, and instruction-injection payloads.
- Treat
