feat(security): add replay attack prevention and HTTPS enforcement#19
feat(security): add replay attack prevention and HTTPS enforcement#19adriannoes merged 15 commits intomainfrom
Conversation
9efad43 to
c0fbd10
Compare
- Add test_validators_edge_cases.py: None timestamp, naive TZ, non-string nonce - Add test_payloads_validation.py: McpToolResult validator edge cases - Add test_cli_edge_cases.py: verbose output, JSON root validation - Add test_run_demo.py: start_process, wait_for_ready, terminate_process All 657 tests passing with 95.05% coverage.
c0fbd10 to
57e6f2d
Compare
Code Review: PR #19 - feat(security): add replay attack prevention and HTTPS enforcement (Opus 4.5)1. Executive Summary
2. Critical Issues (Must Fix)No critical security or logic bugs found. The implementation is solid, properly handles edge cases, and includes comprehensive test coverage. 3. Improvements & Refactoring (Strongly Recommended)The following are quality improvements that would enhance the robustness and maintainability of the implementation. 3.1 [Concurrency] Potential Race Condition in
|
5. Domain-Specific Analysis5.1 Replay Attack PreventionTimestamp Validation:
Nonce Validation:
5.2 HTTPS EnforcementClient-Side Validation:
5.3 Concurrency Safety
6. Verification ResultsAutomated Tests
Static Analysis
Manual Verification
|
- Add atomic check_and_mark() method to NonceStore protocol - Replace separate is_used()/mark_used() calls with atomic operation - Add validation for empty nonce strings - Truncate nonce values in logs to prevent full exposure - Derive nonce TTL from MAX_ENVELOPE_AGE_SECONDS constant - Fix TOCTOU race condition in InMemoryNonceStore
- Replace conditional dict merge with explicit if/else in errors.py - Replace Any type annotation with ParseResult in client.py - Improve code readability and maintainability
- Add integration test for validation order (timestamp before nonce) - Replace time.sleep with time mocking in expired nonce test - Update test assertions to match new error messages - Add test for empty nonce string validation
- Add validation constants summary table - Add security features status table - Improve documentation accessibility
This PR implements timestamp validation and HTTPS enforcement to prevent replay attacks and ensure secure connections in production.
Features
1. Timestamp Validation
MAX_ENVELOPE_AGE_SECONDS(300s) andMAX_FUTURE_TOLERANCE_SECONDS(30s) constantsvalidate_envelope_timestamp()to reject envelopes outside acceptable time windows2. Optional Nonce Support
NonceStoreprotocol andInMemoryNonceStoreimplementationvalidate_envelope_nonce()for duplicate detectionrequire_nonceparameter increate_app()3. HTTPS Enforcement
require_https=Trueby default (configurable)Changes
New Files:
src/asap/transport/validators.py- Validation moduletests/transport/unit/test_validators.py- Unit tests (11 tests)Modified Files:
src/asap/models/constants.py- Timestamp constantssrc/asap/errors.py- InvalidTimestampError, InvalidNonceErrorsrc/asap/models/envelope.py- Nonce documentationsrc/asap/transport/server.py- Validation integrationsrc/asap/transport/client.py- HTTPS enforcementtests/transport/test_client.py- HTTPS tests (6 tests)tests/e2e/test_two_agents.py- Fix for HTTPS validationdocs/security.md- Replay prevention and HTTPS docsREADME.md- HTTPS examples and notesTesting
Documentation
docs/security.mdBreaking Changes
None - All changes are backward compatible. HTTPS enforcement can be disabled with
require_https=Falsefor development.Related
tests/transport/unit/)