aws-samples / aws-samples/iot-lambda-sns-sqs-lambda-dynamodb

Random number as DynamoDB partition key — collision risk

Open
#1 0 comments 0 reactions 0 assignees View on GitHub
Dominant language
JavaScript
Stars
2
Forks
0
PR merge metrics
No merged PRs in 30d

Description

Location:
allfilteredeventconsumer.js

ID: Math.floor(Math.random() * Math.floor(10000000)).toString(),
Using Math.random() with a range of 0-10,000,000 for the primary key. With sufficient volume, collisions will occur and silently overwrite previous records. This is a data loss bug, not just a security issue.

Fix: Use a UUID:

const { randomUUID } = require('crypto');
ID: randomUUID(),

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.