-
Notifications
You must be signed in to change notification settings - Fork 0
Product route: No duplicate productId check on POST #20
Copy link
Copy link
Open
Labels
bugSomething isn't workingSomething isn't working
Description
Severity: Low
Category: Input Validation
Description
In api/src/routes/product.ts, the POST / handler does not check whether a product with the same productId already exists. A client can POST a product with an existing productId, creating duplicates. The GET /:id route would then only return the first match.
Suggested Fix
Check for existing productId before inserting:
router.post('/', (req, res) => {
const newProduct: Product = req.body;
if (products.some(p => p.productId === newProduct.productId)) {
return res.status(409).json({ error: 'Product with this ID already exists' });
}
products.push(newProduct);
res.status(201).json(newProduct);
});Affected File
api/src/routes/product.ts(POST handler)
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
bugSomething isn't workingSomething isn't working