Conversation
|
🤖 Auto-fixed version bump The version in If you need a minor or major version bump instead, please update |
Repo Guardian - PassedAll changed files in this PR are durable, permanent assets appropriate for the repository.
No ephemeral content (meeting notes, one-off scripts, status updates, or point-in-time documents) detected.
|
Add Python wrapper that calls the amplihack-xpia-defender Rust CLI binary via subprocess for XPIA validation. NO FALLBACKS. New files: - src/amplihack/security/rust_xpia.py: subprocess bridge with functions: - validate_content() - scan text for injection attacks - validate_bash_command() - validate bash commands - validate_webfetch_request() - validate URL+prompt - validate_agent_communication() - validate agent messages - health_check() - run XPIA health check - list_patterns() / get_config() / is_available() - find_binary() - locate xpia-defend on PATH or ~/.cargo/bin - tests/test_rust_xpia.py: 23 integration tests (call actual binary) Design principles: - Fail-closed: any subprocess error → RustValidationResult.blocked() - NO FALLBACKS: binary not found → RustXPIAError (never falls back to Python) - Content sent via stdin to avoid shell injection via args - JSON protocol: parse stdout, check exit code (0=valid, 1=blocked, 2=error) Refs: #2991 Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
47153ca to
3a7af7c
Compare
|
🤖 Auto-fixed version bump The version in If you need a minor or major version bump instead, please update |
🤖 PM Architect PR Triage AnalysisPR: #2992 ✅ Workflow Compliance (Steps 11-12)❌ NON-COMPLIANT - PR needs workflow completion Step 11 (Review): ❌ Incomplete
Step 12 (Feedback): ❌ Incomplete
Blocking Issues:
🏷️ ClassificationPriority:
Complexity:
🔍 Change Scope AnalysisPrimary Purpose: New feature Unrelated Changes:
Affected Files:
Recommendation: Consider splitting this PR into separate focused PRs for each concern 💡 Recommendations
📊 Statistics
🤖 Generated by PM Architect automation using Claude Agent SDK |
Repo Guardian - PassedAll changed files in this PR are durable, permanent assets appropriate for the repository.
No ephemeral content (meeting notes, one-off scripts, status updates, or point-in-time documents) detected.
|
Tests exercise the FULL production chain in subprocess isolation: 1. TestBinaryDirect (7 tests): xpia-defend CLI binary invoked directly 2. TestPreToolUseHook (7 tests): pre_tool_use.py hook with real Claude Code JSON protocol (stdin → JSON stdout → allow/deny) 3. TestSessionStartHook (1 test): session_start.py health check 4. TestRustBridgeFullChain (8 tests): Python → rust_xpia.py → binary for all validation types (content, bash, webfetch, agent, health) 5. TestAdversarialAttacks (9 tests): real attack payloads with parametrized expected outcomes matching Python parity 6. TestFailClosed (3 tests): binary missing → blocked, garbage output → blocked, exit code 2 → blocked (even if JSON says valid) All 35 tests pass. Verified Python parity for all 'allowed' results. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
…input) The Claude Code PreToolUse hook protocol sends JSON with top-level keys: tool_name, tool_input, session_id, cwd, hook_event_name, tool_use_id Both pre_tool_use.py and the new pre_tool_use_rust.py were incorrectly parsing nested toolUse.name / toolUse.input, meaning the hooks never found the tool name and silently allowed all commands. Changes: - Fix pre_tool_use.py to parse top-level tool_name/tool_input - Add pre_tool_use_rust.py: Rust-backed hook via xpia-defend binary - Uses cwd from hook input for project root detection - Fail-closed: import errors, missing binary, or exceptions → deny - Logs to ~/.claude/logs/xpia/rust_security_YYYYMMDD.log - Update 7 hook protocol tests to use correct input format Verified in real Claude Code sessions: - Safe commands (echo, wc -w) → ALLOW with risk=none - Injection content → DENY with risk=critical, threats=2 - Security log entries written with session_id Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Real Session Testing Results ✅Critical Bug Found & FixedThe Claude Code PreToolUse hook protocol sends JSON with top-level Fix Applied
Real Session EvidenceTest Results
|
Expanded test coverage for Rust XPIA defense chain: New test classes: - TestPatternCoverage: all 19 patterns with correct validators (content vs bash) - TestRustBackedHook: 14 tests for pre_tool_use_rust.py production hook - TestRustHookLogging: verify security log entries on allow and deny - TestSecurityLevels: low/medium/high/strict matrix validation - TestEdgeCases: empty, huge, unicode, special chars, multiline - TestEncodingBypasses: base64, unicode escape, mixed case - TestThreatMetadata: required fields, location bounds, severity values - TestPerformance: latency bounds (<500ms binary, <2s hook round-trip) Enhanced existing classes: - TestAdversarialAttacks: 17 content attacks, 13 bash attacks - TestFailClosed: binary missing, garbage output, exit code 2, timeout, hook denial All 135 outside-in + 23 unit = 158 total tests pass. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Catalogues all discovered false negatives and false positives as strict xfail tests, so they will automatically fail when pattern fixes land (removing the xfail marker becomes the final step of each fix). False negatives (13): reverse shells, download-execute, SUID, crontab, SSH key injection, firewall flush, history erasure, disregard training, system message exfiltration, restriction removal. False positives (11): 'Dan' as substring (RH001), 'developer mode' in safe context (RH001), 'Step 1/Step 2' instructions (CA001), negation unawareness (PO003), sysadmin role claim (RH002), package names (RH001), .env read (DE002). 16 test classes, 100 test functions, 162 test cases (135 pass + 27 xfail). Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
…, FPs Expanded probing uncovered 21 additional pattern engine bugs: Encoding/obfuscation bypasses (5): - Base64-pipe-bash, Unicode homoglyphs, URL encoding, zero-width chars, flooding Data exfiltration gaps (4): - SCP, git credential theft, Docker host escape, /proc memory dump Privilege escalation gaps (7): - sudo bash, SUID copy, setcap, LD_PRELOAD, /etc/passwd, /etc/sudoers, insmod New false positives (5): - 3-step instructions, security discussion, Dan in prose, pytest dev mode, pydantic Total: 20 test classes, 120 test functions, 183 test cases (135 pass + 48 xfail). All linked to rysweet/amplihack-xpia-defender#4. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
PR Triage ReportCategory: Security Feature SummaryThis PR adds a Python subprocess bridge to the Files Changed
Risk Factors
Positive Signals
Action Required
|
Pattern fixes in amplihack-xpia-defender PR #5 resolved 33 of 45 bugs. Updated test expectations: - Removed xfail from 33 now-passing tests (reverse shells, privesc, exfil, download-execute, false positive fixes for CA001/RH001/RH002/PO003) - Updated pattern count assertions: 19 → 31 - Updated 'reveal system prompt' to expect blocking (new PO005 pattern) - 13 xfail remain: encoding bypasses (4), DAN proper names (3), dan-utils package (1), .env read (1), security discussion (1), dan in prose (1), disregard training (1), restriction removal (1) Test suite: 170 passed + 13 xfailed = 183 test cases, 0 failures. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
- Dan proper name false positives (3): RH001 now requires attack verbs - dan-utils package false positive (1): RH001 no longer matches substrings - Dan in prose false positive (1): RH001 context-aware matching Result: 175 passed, 8 xfailed (was 170 passed, 13 xfailed) Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
- Pattern count assertions updated from 31 to 37 - Removed xfail: disregard training gap (PO001 widened) - Removed xfail: restriction removal gap (PO008 new pattern) Result: 177 passed, 6 xfailed (was 175 passed, 8 xfailed) Remaining 6 xfails require architectural changes: - 4 encoding bypasses (homoglyphs, URL encoding, zero-width, flooding) - 1 .env read false positive - 1 security discussion false positive Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
- Pattern count: 37 → 40 (3 new patterns) - Fix sysadmin test: 'I am the system administrator' is correctly flagged as role reversal (RH002), not a false positive - Remove zero-width char xfail: now passes thanks to normalize_input() - Results: 178 passed, 5 xfailed (was 177+6) Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Encoding preprocessor pipeline in xpia-defender PR #11 fixes: - Unicode homoglyph bypass (Cyrillic і/а → Latin i/a) - URL encoding bypass (%20 → space) Results: 180 passed, 3 xfailed (was 178+5) Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
- New xpia_install.py: downloads platform-specific binary from rysweet/amplihack-xpia-defender GitHub releases to ~/.amplihack/bin/ - Updated find_binary() to auto-install when binary not found - Wired ensure_xpia_binary() into copilot launcher startup - 19 unit tests covering platform detection, version tracking, download flow, and auto-install integration Supports: linux-x64, linux-arm64, macos-x64, macos-arm64, windows-x64 Uses gh CLI for downloads, idempotent with version marker file. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Fixes 5 security issues found in code review: 1. CRITICAL: Added SHA256 checksum verification — downloads SHA256SUMS.txt from release, verifies archive hash before extraction. Tampered binaries are now detected and rejected. 2. CRITICAL: Added path traversal protection for zip extraction — validates member names contain no '..' or absolute paths, resolves final path to confirm it stays within target directory. 3. HIGH: Fixed file permissions — set explicit 0o755 instead of OR-ing execute bits onto existing permissions (which could result in 0o777). 4. HIGH: Improved launcher error handling — separate ImportError from runtime errors, log at ERROR level, print clear message that security validation will block tool use until binary is available. 5. MEDIUM: Changed find_binary() default to auto_install=False — runtime validation calls no longer trigger unexpected network activity. Only explicit startup call (copilot.py) passes auto_install=True. Also: removed unused imports (os, stat), narrowed bare except to specific exception types, added 8 new tests (27 total). Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Code Review: XPIA Auto-Installer Security HardeningFindings (5 issues found and fixed)
Outside-In Testing ResultsTest Environment: feat/issue-2991-xpia-rust-bridge, 2026-03-10
Unit Tests: 27 passed (up from 19) |
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Repo Guardian - PassedAll changed files in this PR are durable, permanent assets appropriate for the repository.
No ephemeral content (meeting notes, one-off scripts, status updates, or point-in-time documents) detected.
|
Summary
Python subprocess wrapper for calling the
amplihack-xpia-defenderRust CLI binary. NO FALLBACKS — binary must be present or functions raiseRustXPIAError.New Files
src/amplihack/security/rust_xpia.py— Subprocess bridge (273 lines)tests/test_rust_xpia.py— 23 integration tests (call actual binary)API
Design
RustValidationResult.blocked()RustXPIAError(hard error)Prerequisites
xpia-defendbinary:cargo install --features cli --path <amplihack-xpia-defender>@pytest.mark.skipif)Testing
All 23 tests pass when binary is installed. Tests verify:
Refs: #2991