T01 · Skill Instruction Hijacking
- Location
code_review/pr_analyzer.py:136- Finding
Untrusted Pull Request Content Can Hijack the LLM Review
- Content
View full analysis
Vulnerability Details
File Location:
code_review/pr_analyzer.py:136-157andcode_review/pr_analyzer.py:177-207
Vulnerability Type: Prompt injection through untrusted pull request content
Risk Level: HighVulnerable Code
python context = f""" # Pull Request Context **PR Title:** {pr.title} **PR Description:** {pr.body or "No description provided"} **Author:** {pr.user.login} **State:** {pr.state} ## Files Changed {files_str} ## Code Diff {diff_content[:10000]} # Limit to 10k chars to avoid token limits """ return contextpython prompt = f"""You are an expert code reviewer. Analyze the following pull request and provide a comprehensive code review. {context} ## Your Task Provide a structured code review with the following sections: ### 1. Overall Assessment - Brief summary of the PR's purpose - General impression (positive/negative/mixed) - Is the PR ready to merge? ### 2. Code Quality Issues - Identify any bugs or potential bugs - Logic errors - Performance concerns - Code style issues ### 3. Security Considerations - Any security vulnerabilities - Sensitive data handling - Authentication/authorization issues ### 4. Best Practices - Missing error handling - Code organization - Naming conventions - Documentation ### 5. Recommendations - Specific improvements with line-by-line suggestions where appropriate - Priority levels (Critical, High, Medium, Low) Format your response in markdown with clear headings. Be specific and actionable.""" return promptTechnical Analysis
Pull request titles, descriptions, filenames, author-controlled file contents, and diffs are untrusted data. The application directly interpolates this data into the same user message that contains the trusted review instructions.
No explicit trust boundary tells the model that instructions embedded in the pull request must be treated sol ...[truncated 1947 chars]
- Remediation
View remediation
Remediation Suggestions
- Place the immutable review policy in an Anthropic system message rather than combining it with repository content in a user message.
- Explicitly state that PR metadata, filenames, comments, documentation, strings, and diff contents are untrusted data and that any instructions found inside them must not be followed.
- Wrap each untrusted field in clear structural delimiters and label it as data. Use a serialization format that keeps instructions and content structurally separate.
- Require structured output that conforms to a strict schema, including enumerated severity values and evidence locations.
- Validate the response before displaying or scoring it. Reject malformed responses, unexpected instructions, and claims lacking references to the supplied diff.
- Do not treat an LLM-generated merge recommendation or score as an authorization decision. Keep deterministic scanners and mandatory human review independent of the model output.
- Add adversarial tests using injection strings in PR titles, descriptions, filenames, and source comments.
- Clearly warn users that repository content is externally submitted to an LLM and that generated findings may be influenced by hostile content.
