From 1e7e2b69373c2126450928664182f1cacc709b2c Mon Sep 17 00:00:00 2001 From: Piotr Mankowski Date: Mon, 16 Oct 2023 19:12:09 +0000 Subject: [PATCH] Sec fix --- src/routes/fhir.ts | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/src/routes/fhir.ts b/src/routes/fhir.ts index 7ab4928..23e41cf 100644 --- a/src/routes/fhir.ts +++ b/src/routes/fhir.ts @@ -25,14 +25,18 @@ router.get('/:resource/:id?/:operation?', async (req, res) => { return res.status(400).json({ message: `Invalid resource type ${req.params.resource}` }) } - if (req.params.id) { + if (req.params.id && /^[a-zA-Z0-9\-_]+$/.test(req.params.id)) { uri = uri.segment(encodeURIComponent(req.params.id)) + } else { + return res.status(400).json({ message: `Invalid resource id ${req.params.id}` }) } for (const param in req.query) { let value = req.query[param] - if(value) { + if(value && /^[a-zA-Z0-9\-_]+$/.test(value.toString())) { uri.addQuery(param, encodeURIComponent(value.toString())) + } else { + return res.status(400).json({ message: `Invalid query parameter ${param}=${value}` }) } }