fix: validate route ID parameters, return 400 for invalid IDs
Adds parseId helper in src/server/lib/params.ts and applies it across all route files so non-positive-integer IDs return 400 instead of silently passing NaN to services. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
9
src/server/lib/params.ts
Normal file
9
src/server/lib/params.ts
Normal file
@@ -0,0 +1,9 @@
|
||||
/**
|
||||
* Parse a route parameter as a positive integer ID.
|
||||
* Returns the number if valid, or null if the string is not a positive integer.
|
||||
*/
|
||||
export function parseId(raw: string): number | null {
|
||||
const id = Number(raw);
|
||||
if (!Number.isInteger(id) || id <= 0) return null;
|
||||
return id;
|
||||
}
|
||||
Reference in New Issue
Block a user