mirror of
https://github.com/Unleash/unleash.git
synced 2025-12-09 20:04:11 +01:00
Previously, we were not validating that the ID was a number, which sometimes resulted in returning our database queries (source code) to the frontend. Now, we have validation middleware.
17 lines
412 B
TypeScript
17 lines
412 B
TypeScript
import { BadDataError } from '../error';
|
|
|
|
const idNumberMiddleware = (): any => {
|
|
return async (req, res, next) => {
|
|
const { id } = req.params;
|
|
if (!Number.isInteger(Number(id))) {
|
|
res.status(400).send(
|
|
new BadDataError('ID should be an integer').toJSON(),
|
|
);
|
|
return;
|
|
}
|
|
next();
|
|
};
|
|
};
|
|
|
|
export default idNumberMiddleware;
|