-
Notifications
You must be signed in to change notification settings - Fork 4
feat(security): harness pattern extraction — prompt injection defense #81
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
9f069ea
feat(security): implement harness pattern extraction for prompt injec…
elkaix e9127b2
fix(tests): resolve CI failures from harness pattern extraction feature
elkaix 521408a
test(agent_spec): add focused planner subagent spec assertions
elkaix f0de900
test(agent_spec): complete planner spec assertions to match other sub…
elkaix 45c6e66
test(agent_spec): add semantic invariant checks for planner recon_see…
elkaix File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,44 @@ | ||
| version: 1 | ||
| agent: | ||
| extend: ./agent.yaml | ||
| system_prompt_args: | ||
| ROLE_ADDITIONAL: | | ||
| You are now running as a subagent. All the `user` messages are sent by the main agent. | ||
| The main agent cannot see your context, it can only see your last message when you finish. | ||
|
|
||
| You are a Reconnaissance Planner. Your single objective is to analyze the request and | ||
| break it down into N distinct, non-overlapping task seeds for parallel workers. | ||
|
|
||
| CRITICAL RULES: | ||
| - Do not solve the problem. Do not write code. Do not fix anything. | ||
| - Each seed must provide a distinct starting angle (different file, subsystem, or hypothesis) | ||
| so that parallel workers exploring them will NOT duplicate effort or converge on the same solution. | ||
| - Aim for 3-5 seeds unless the task is clearly simpler or more complex. | ||
|
|
||
| Final response contract: | ||
| Your final message must contain ONLY the seeds block below — no preamble, no explanation, | ||
| no content before or after the tags: | ||
| <recon_seeds> | ||
| ["seed description 1", "seed description 2", ...] | ||
| </recon_seeds> | ||
|
|
||
| when_to_use: | | ||
| Use this agent before spawning N parallel workers on a large or open-ended task. | ||
| It partitions the problem space so workers start from distinct vantage points. | ||
|
|
||
| allowed_tools: | ||
| - "pythinker_code.tools.shell:Shell" | ||
| - "pythinker_code.tools.file:ReadFile" | ||
| - "pythinker_code.tools.file:Glob" | ||
| - "pythinker_code.tools.file:Grep" | ||
| - "pythinker_code.tools.file:SmartSearch" | ||
| exclude_tools: | ||
| - "pythinker_code.tools.agent:Agent" | ||
| - "pythinker_code.tools.ask_user:AskUserQuestion" | ||
| - "pythinker_code.tools.plan:ExitPlanMode" | ||
| - "pythinker_code.tools.plan.enter:EnterPlanMode" | ||
| - "pythinker_code.tools.file:WriteFile" | ||
| - "pythinker_code.tools.file:StrReplaceFile" | ||
| - "pythinker_code.tools.web:SearchWeb" | ||
| - "pythinker_code.tools.web:FetchURL" | ||
| subagents: |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,97 @@ | ||
| """Boundary-artifact dataclasses exchanged between coder and verifier subagents. | ||
|
|
||
| These dataclasses enforce a strict information barrier: verifiers receive ONLY the | ||
| typed fields declared here, never prose or logs from the producer. The shape of | ||
| ``to_json`` / ``from_dict`` is a contract surface consumed by subagent prompts. | ||
|
|
||
| Two pairs are defined: | ||
|
|
||
| * ``CodingArtifact`` / ``VerificationResult`` for the generic coder-to-verifier flow. | ||
| * ``VulnerabilityArtifact`` / ``AuditVerdict`` for the security-specific finder-to-audit | ||
| flow. | ||
| """ | ||
|
|
||
| from __future__ import annotations | ||
|
|
||
| import json | ||
| from dataclasses import dataclass, field | ||
| from typing import Any | ||
|
|
||
|
|
||
| @dataclass(frozen=True) | ||
| class CodingArtifact: | ||
| """Producer-side handoff from a coder subagent to a verifier subagent.""" | ||
|
|
||
| files_changed: list[str] | ||
| test_command: str | ||
| expected_behavior: str | ||
| edge_cases_claimed: list[str] = field(default_factory=list[str]) | ||
|
|
||
| def to_json(self) -> str: | ||
| return json.dumps( | ||
| { | ||
| "files_changed": self.files_changed, | ||
| "test_command": self.test_command, | ||
| "expected_behavior": self.expected_behavior, | ||
| "edge_cases_claimed": self.edge_cases_claimed, | ||
| }, | ||
| indent=2, | ||
| ) | ||
|
|
||
| @classmethod | ||
| def from_dict(cls, d: dict[str, Any]) -> CodingArtifact: | ||
| return cls( | ||
| files_changed=d["files_changed"], | ||
| test_command=d["test_command"], | ||
| expected_behavior=d["expected_behavior"], | ||
| edge_cases_claimed=d.get("edge_cases_claimed", []), | ||
| ) | ||
|
|
||
|
|
||
| @dataclass(frozen=True) | ||
| class VerificationResult: | ||
| """Verifier-side response back to the coder.""" | ||
|
|
||
| passed: bool | ||
| stdout_summary: str | ||
| stderr_summary: str | ||
| discovered_gaps: list[str] = field(default_factory=list[str]) | ||
|
elkaix marked this conversation as resolved.
|
||
|
|
||
|
|
||
| @dataclass(frozen=True) | ||
| class VulnerabilityArtifact: | ||
| """Producer-side handoff from a vulnerability finder to the audit verifier.""" | ||
|
|
||
| target_file: str | ||
| vulnerability_type: str | ||
| reproduction_command: str | ||
| expected_failure_output: str | ||
|
|
||
| def to_json(self) -> str: | ||
| return json.dumps( | ||
| { | ||
| "target_file": self.target_file, | ||
| "vulnerability_type": self.vulnerability_type, | ||
| "reproduction_command": self.reproduction_command, | ||
| "expected_failure_output": self.expected_failure_output, | ||
| }, | ||
| indent=2, | ||
| ) | ||
|
|
||
| @classmethod | ||
| def from_dict(cls, d: dict[str, Any]) -> VulnerabilityArtifact: | ||
| return cls( | ||
| target_file=d["target_file"], | ||
| vulnerability_type=d["vulnerability_type"], | ||
| reproduction_command=d["reproduction_command"], | ||
| expected_failure_output=d["expected_failure_output"], | ||
| ) | ||
|
|
||
|
|
||
| @dataclass(frozen=True) | ||
| class AuditVerdict: | ||
| """Audit-verifier verdict on a claimed vulnerability.""" | ||
|
|
||
| vulnerability_confirmed: bool | ||
| execution_logs: str | ||
| false_positive_reasoning: str = "" | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,23 @@ | ||
| """Trust-wrapping primitive for external, untrusted data entering LLM prompts.""" | ||
|
|
||
| from __future__ import annotations | ||
|
|
||
| import uuid | ||
| from dataclasses import dataclass | ||
|
|
||
|
|
||
| @dataclass(frozen=True) | ||
| class UntrustedData: | ||
| """Marks a string as originating from an external, untrusted source. | ||
|
|
||
| Call render_for_prompt() before injecting the content into any LLM prompt. | ||
| The runtime nonce prevents the model from constructing a matching opening | ||
| tag. The closing-tag escape prevents content from breaking out of the block. | ||
| """ | ||
|
|
||
| raw_content: str | ||
|
|
||
| def render_for_prompt(self) -> str: | ||
| nonce = uuid.uuid4().hex[:8] | ||
| safe_content = self.raw_content.replace("</untrusted_data>", "</untrusted_data>") | ||
| return f'<untrusted_data id="{nonce}">\n{safe_content}\n</untrusted_data>' |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.