Skip to content

Implement spec-v2: Exception context, benchmarks, guard bypass tests, mypy fix - #1

Merged
clay-good merged 19 commits into
mainfrom
proxilion-build/spec-v2-clean
Mar 18, 2026
Merged

Implement spec-v2: Exception context, benchmarks, guard bypass tests, mypy fix#1
clay-good merged 19 commits into
mainfrom
proxilion-build/spec-v2-clean

Conversation

@clay-good

@clay-good clay-good commented Mar 15, 2026

Copy link
Copy Markdown
Owner

Summary

Implements spec-v2 steps 2-11 for the Proxilion SDK:

  • Step 2: Narrow broad exception catches in security modules
  • Step 3: Fix MemoryIntegrityChecker → MemoryIntegrityGuard in docs
  • Step 4: Add Python 3.13 classifier to pyproject.toml
  • Step 5: Add structured error context to security exceptions (7 exception classes)
  • Step 6: Add tests for structured exception context (47 tests)
  • Step 7: Wire structured exception context to raise sites
  • Step 8: Full authorization pipeline integration tests
  • Step 9: Performance benchmark suite
  • Step 10: Input guard bypass/evasion test suite
  • Step 11: Verify input guard case-insensitive evasion protection
  • Mypy fix: Fix type errors in pydantic_schema.py optional import fallback

CI Status

  • Lint: passing
  • Tests (3.10, 3.11, 3.12): passing (2599 tests, 5 skipped, 29 xfailed)
  • Typecheck: passing (fixed in latest commit)

Test plan

  • All 2599 tests pass
  • Ruff lint and format pass
  • Mypy strict mode passes (89 source files)
  • CI green on all checks

🤖 Generated with Claude Code

clay-good and others added 9 commits March 15, 2026 14:17
Step 1: Update __version__ in proxilion/__init__.py from 0.0.5 to 0.0.6
to match pyproject.toml.

Step 2: Ruff lint and format already passing (0 violations).

Step 3: Remove 13 stale `# type: ignore[import-not-found]` comments across
9 files. These were leftover from previous refactors where --ignore-missing-imports
already suppresses the underlying import errors, making the comments unused.
Also fix no-any-return error in pydantic_schema.py line 286.
All 89 source files now pass `mypy proxilion/ --ignore-missing-imports`.

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
Step 4 - CI Pipeline Hardening:
- Add Python 3.13 to test matrix
- Add --cov-fail-under=85 to pytest command
- Expand ruff lint scope to include tests/ directory
- Add pip-audit security scanning step to lint job
- Install all optional deps in typecheck job ([dev,all])

Step 5 - Secret Key Validation:
- Add _validate_secret_key() to intent_capsule.py, memory_integrity.py,
  and agent_trust.py that raises ConfigurationError if key < 16 chars
  and logs a warning for common placeholder patterns
- Also validate key in IntentGuard.__init__() when secret_key is provided
- Update test fixtures to use keys of >= 16 characters
- Update README examples to use realistic key "prx_sk_a1b2c3d4e5f6g7h8"
  with a comment noting production use requires a real key

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
…-v2 step 2)

Added documenting comments to all catch-all except Exception blocks in the five
security modules to make intent auditable:

- idor_protection.py: Document that scope loader and extractor catches are
  intentional catch-alls for user-provided callbacks; add WARNING-level logging
  to the previously silent extractor exception swallow
- cascade_protection.py: Document state listener catch-all as user-provided
  callback; downgrade log level from error to warning per intent
- behavioral_drift.py: Document drift/halt/reset callback catch-alls as
  user-provided callbacks; downgrade log levels from error to warning
- circuit_breaker.py: Document that catch-all is intentional (any exception
  from protected function counts as circuit failure)
- intent_validator.py: Document custom validator catch-all as user-provided
  callback; downgrade log level from error to warning per intent

Zero new ruff violations. Zero mypy errors. All 2354 sync tests pass.

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
…ep 3)

The features README referenced MemoryIntegrityChecker which does not exist.
The actual class exported by proxilion.security is MemoryIntegrityGuard.
Any developer copying the example code would get an ImportError.

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
The CI pipeline already tests Python 3.13 (added in spec-v1 step 4),
but pyproject.toml classifiers only listed 3.10, 3.11, and 3.12. Added
"Programming Language :: Python :: 3.13" classifier so PyPI metadata
matches the tested and supported Python versions.

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
Add optional keyword-only structured context fields to 7 security exception
classes so operators can access machine-readable metadata without parsing
string messages:

- RateLimitExceeded: user_id, limit, current_count, window_seconds, reset_at
- CircuitOpenError: already had circuit_name, failure_count, reset_timeout
- IDORViolationError: resource_id alias for object_id
- GuardViolation/InputGuardViolation/OutputGuardViolation: input_preview
- SequenceViolationError: user_id
- BudgetExceededError: budget_limit alias for limit
- IntentHijackError: tool_name, allowed_tools, user_id

All new fields are optional keyword-only arguments defaulting to None,
preserving full backward compatibility with existing raise sites.

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
Create tests/test_exceptions.py with 47 tests covering all 7 enhanced
exception classes: RateLimitExceeded, CircuitOpenError, IDORViolationError,
GuardViolation (+ InputGuardViolation, OutputGuardViolation),
SequenceViolationError, BudgetExceededError, IntentHijackError.

Each class gets tests for: default construction, structured field access,
ProxilionError inheritance, str() representation, and top-level importability
from the proxilion package. Also verifies backward-compatible aliases
(resource_id, budget_limit) and cross-cutting properties.

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
Add structured context fields to all exception raise sites:

- rate_limiter.py: Add user_id, limit, current_count to RateLimitExceeded
  raises at global, user, and tool-specific limit checks
- decorators.py: Add user_id to RateLimitExceeded and SequenceViolationError;
  Add current_spend and budget_limit to BudgetExceededError
- core.py: Add input_preview to InputGuardViolation and OutputGuardViolation
- intent_capsule.py: Add tool_name, allowed_tools, user_id to IntentHijackError;
  Modify _handle_violation() to accept tool_name parameter

These fields enable programmatic alerting and dashboards to access semantic
information about violations without parsing exception messages.

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
@clay-good clay-good changed the title Add structured error context to security exceptions (spec-v2 steps 2-5) Implement spec-v2 steps 2-7: Structured exception context Mar 17, 2026
clay-good and others added 6 commits March 17, 2026 17:45
This commit adds comprehensive end-to-end integration tests for the
Proxilion authorization pipeline in tests/test_pipeline_integration.py.

The tests cover:
- Happy path authorization flows (can/check methods)
- Input guard rejection via guard_input() method
- Rate limit enforcement and capacity exhaustion
- Policy denial for unauthorized users
- Sequence validation (REQUIRE_BEFORE and FORBID_AFTER rules)
- Audit event logging and hash chain integrity verification
- Edge cases (missing user context, default deny, sync/async)
- Multi-guard coordination patterns

Key test classes:
- TestFullPipelineHappyPath: 6 tests for successful authorization
- TestPipelineInputGuardRejection: 3 tests for input guard
- TestPipelineRateLimitRejection: 1 test for rate limiting
- TestPipelinePolicyDenial: 2 tests for policy enforcement
- TestPipelineSequenceViolation: 3 tests for sequence rules
- TestPipelineAuditIntegrity: 4 tests for audit logging
- TestPipelineEdgeCases: 4 tests for edge cases
- TestPipelineMultipleGuards: 3 tests for multi-guard patterns

Total: 26 new integration tests, all passing.

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
- Fix AuditEventData constructor parameters to match actual API
- Fix IDORProtector.validate_access parameter name (object_id not resource_id)
- Remove unused datetime imports
- All 14 benchmark tests now pass

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
Add comprehensive test suite for input guard bypass attempts including:
- Unicode homoglyph substitution (Cyrillic, Greek, full-width, math symbols)
- Whitespace injection (zero-width spaces, ZWNJ, tabs, newlines, BOM)
- Case mixing (alternating, all caps, random case)
- Delimiter bypass (pipes, dots, underscores, hyphens, slashes)
- Encoding bypass (base64, URL encoding, hex)
- Comment injection (SQL, HTML, C-style, hash)
- Character repetition and stuttering
- Leetspeak character substitution
- Word boundary evasion
- Bidirectional text overrides
- Prompt structure evasion (quotes, code blocks, JSON, XML)
- Semantic evasion (paraphrasing, synonyms, implicit override)
- Multi-language injection (Spanish, French, German)

Tests document known limitations using @pytest.mark.xfail markers.
Total: 52 tests (23 pass, 29 xfail documenting regex limitations)

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
@clay-good clay-good changed the title Implement spec-v2 steps 2-7: Structured exception context Implement spec-v2 steps 2-10: Exception context, benchmarks, guard bypass tests Mar 18, 2026
clay-good and others added 4 commits March 18, 2026 07:17
Step 11 verification confirms the input guard already has proper
case-insensitive matching:

- InjectionPattern compiles all regexes with re.IGNORECASE | re.MULTILINE
- Most patterns also have inline (?i) flag (redundant but harmless)
- All TestCaseMixingBypass tests pass without xfail markers
- Alternating case, all caps, and random case patterns are detected

No code changes required - the implementation was already correct.
Only STATE.md updated to mark step 11 complete.

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
Add type: ignore comments for optional pydantic import fallback
assignments and remove unused type: ignore on model_json_schema call.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@clay-good
clay-good marked this pull request as ready for review March 18, 2026 21:44
@clay-good clay-good changed the title Implement spec-v2 steps 2-10: Exception context, benchmarks, guard bypass tests Implement spec-v2: Exception context, benchmarks, guard bypass tests, mypy fix Mar 18, 2026
@clay-good
clay-good merged commit 66892e9 into main Mar 18, 2026
5 checks passed
clay-good added a commit that referenced this pull request Mar 25, 2026
Resolved 11 file conflicts from PR #1's squash-merge of spec-v2.
Kept PR #4 branch content (spec-v2 steps 12-18 + spec-v3 steps 1-4)
on top of main's state. Fixed formatting in contrib/google.py.

All CI checks pass: 0 ruff violations, 158 files formatted,
0 mypy errors, 2633 tests passed.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant