Skip to content
This repository has been archived by the owner on Jun 1, 2023. It is now read-only.

Commit

Permalink
feat: verifyQuery
Browse files Browse the repository at this point in the history
  • Loading branch information
joao-conde committed Dec 3, 2021
1 parent b6144ec commit 09d320a
Showing 1 changed file with 7 additions and 3 deletions.
10 changes: 7 additions & 3 deletions lib/util/base.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,13 @@ const verifyKey = req => {
* @param {any} req The request to retrieve the query params.
*/
const verifyQuery = req => {
if (!req.query.brand) return;
if (config.conf.WHITELIST.includes(req.query.brand)) return;
throw new Error(`Invalid '${req.query.brand}' brand`);
const WHITELIST = config.conf.WHITELIST;
Object.keys(req.query).forEach(key => {
const param = req.query[key];
if (key in WHITELIST && !WHITELIST[key].includes(param)) {
throw new Error(`Restricted value '${param}' for param '${key}'`);
}
});
};

module.exports = {
Expand Down

0 comments on commit 09d320a

Please sign in to comment.