Fix crash when req.query handling
https://expressjs.com/en/5x/api.html#req.query "As req.query’s shape is based on user-controlled input, all properties and values in this object are untrusted and should be validated before trusting" In essence, req.query.xx can be an array OR an array of strings.
This commit is contained in:
@@ -32,10 +32,10 @@ async function load(req, res, next) {
|
||||
}
|
||||
|
||||
async function list(req, res, next) {
|
||||
const page = typeof req.query.page !== 'undefined' ? parseInt(req.query.page) : 1;
|
||||
const page = typeof req.query.page === 'string' ? parseInt(req.query.page) : 1;
|
||||
if (!page || page < 0) return next(new HttpError(400, 'page query param has to be a postive number'));
|
||||
|
||||
const perPage = typeof req.query.per_page !== 'undefined'? parseInt(req.query.per_page) : 25;
|
||||
const perPage = typeof req.query.per_page === 'string'? parseInt(req.query.per_page) : 25;
|
||||
if (!perPage || perPage < 0) return next(new HttpError(400, 'per_page query param has to be a postive number'));
|
||||
|
||||
const [error, result] = await safe(archives.list(page, perPage));
|
||||
@@ -54,7 +54,9 @@ async function getIcon(req, res, next) {
|
||||
assert.strictEqual(typeof req.params.id, 'string');
|
||||
assert.strictEqual(typeof req.resources.archive, 'object');
|
||||
|
||||
const [error, icon] = await safe(archives.getIcon(req.params.id, { original: req.query.original }));
|
||||
const original = typeof req.query.original === 'string' ? (req.query.original === '1' || req.query.original === 'true') : false;
|
||||
|
||||
const [error, icon] = await safe(archives.getIcon(req.params.id, { original }));
|
||||
if (error) return next(BoxError.toHttpError(error));
|
||||
|
||||
res.send(icon);
|
||||
|
||||
Reference in New Issue
Block a user