Skip to content

fix: prevent cross-session image leakage and cross-instance nonce replay#40

Open
nirholas wants to merge 1 commit into
aws-samples:mainfrom
nirholas:fix/session-isolation-and-nonce-replay
Open

fix: prevent cross-session image leakage and cross-instance nonce replay#40
nirholas wants to merge 1 commit into
aws-samples:mainfrom
nirholas:fix/session-isolation-and-nonce-replay

Conversation

@nirholas

Copy link
Copy Markdown

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.

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.

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.
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.

2 participants