fix: prevent cross-session image leakage and cross-instance nonce replay#40
Open
nirholas wants to merge 1 commit into
Open
fix: prevent cross-session image leakage and cross-instance nonce replay#40nirholas wants to merge 1 commit into
nirholas wants to merge 1 commit into
Conversation
Three bugs fixed: 1. Cross-session image leakage (agent.py + tools.py) IMAGE_STORAGE was a module-level dict written by every session. When two concurrent invocations ran, the first response to extract IMAGE_STORAGE could receive images belonging to the other session, then clear() left the second response empty. Images are now stored and extracted from per-session SessionStorage exclusively; the global fallback dicts are removed. 2. Cross-instance nonce replay (both seller Lambdas) processedPayments was an in-process Map. AWS Lambda scales horizontally, so a second Lambda instance had no knowledge of nonces seen by the first. An attacker could submit the same EIP-712 signature to a fresh instance and receive content without paying. Nonces are now written atomically to DynamoDB (ConditionExpression: attribute_not_exists) before verification passes, shared across all instances. Falls back to the in-process Map when NONCE_TABLE_NAME is absent so local dev is unaffected. 3. Stale signature replay (both seller Lambdas) The seller never checked whether a payment signature was recent. Signatures older than MAX_PAYMENT_AGE_SEC (300 s) are now rejected with payment_expired before they reach the facilitator. Also adds startup configuration validation in agent.py (validate_config()) so misconfigured deployments fail immediately with a clear error instead of at request time.
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Three bugs fixed:
Cross-session image leakage (agent.py + tools.py) IMAGE_STORAGE was a module-level dict written by every session. When two concurrent invocations ran, the first response to extract IMAGE_STORAGE could receive images belonging to the other session, then clear() left the second response empty. Images are now stored and extracted from per-session SessionStorage exclusively; the global fallback dicts are removed.
Cross-instance nonce replay (both seller Lambdas) processedPayments was an in-process Map. AWS Lambda scales horizontally, so a second Lambda instance had no knowledge of nonces seen by the first. An attacker could submit the same EIP-712 signature to a fresh instance and receive content without paying. Nonces are now written atomically to DynamoDB (ConditionExpression: attribute_not_exists) before verification passes, shared across all instances. Falls back to the in-process Map when NONCE_TABLE_NAME is absent so local dev is unaffected.
Stale signature replay (both seller Lambdas) The seller never checked whether a payment signature was recent. Signatures older than MAX_PAYMENT_AGE_SEC (300 s) are now rejected with payment_expired before they reach the facilitator.
Also adds startup configuration validation in agent.py (validate_config()) so misconfigured deployments fail immediately with a clear error instead of at request time.
Issue #, if available:
Description of changes:
By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice.