Skip to content

fix(cloudfront): replace random.randint with uuid4 for CallerReference generation#10282

Open
tomohiro86 wants to merge 1 commit intoaws:developfrom
tomohiro86:fix/cloudfront-caller-reference-uuid
Open

fix(cloudfront): replace random.randint with uuid4 for CallerReference generation#10282
tomohiro86 wants to merge 1 commit intoaws:developfrom
tomohiro86:fix/cloudfront-caller-reference-uuid

Conversation

@tomohiro86
Copy link
Copy Markdown

Summary

  • unique_string() in awscli/customizations/cloudfront.py was generating CallerReference values using random.randint(1, 1000000) combined with a Unix timestamp (1-second granularity)
  • Two invocations within the same second had a 1-in-1,000,000 chance of producing an identical CallerReference, causing CloudFront to silently treat the second request as a duplicate
  • Replace with uuid.uuid4() which provides 122 bits of cryptographic randomness, eliminating both the collision risk and the unnecessary timestamp dependency

Fixes #10281

Test plan

  • Verify create-invalidation --paths generates a unique CallerReference on each invocation
  • Verify create-distribution generates a unique CallerReference on each invocation
  • Run existing unit tests: pytest tests/unit/customizations/test_cloudfront.py

…e generation

unique_string() was using random.randint(1, 1000000) combined with a
Unix timestamp to generate CallerReference values for create-invalidation
and create-distribution. Because the timestamp has 1-second granularity,
concurrent invocations within the same second had a 1-in-1,000,000 chance
of producing identical values, causing CloudFront to silently treat the
second request as a duplicate.

Replace with uuid.uuid4() which provides 122 bits of cryptographic
randomness, eliminating both the timestamp dependency and collision risk.

Fixes aws#10281
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.

cloudfront: unique_string() uses non-cryptographic random, risking CallerReference collision

1 participant