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:
+5
-5
@@ -37,10 +37,10 @@ async function get(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'));
|
||||
|
||||
if (req.query.type && typeof req.query.type !== 'string') return next(new HttpError(400, 'type must be a string'));
|
||||
@@ -63,13 +63,13 @@ async function stopTask(req, res, next) {
|
||||
async function getLogs(req, res, next) {
|
||||
assert.strictEqual(typeof req.resources.task, 'object');
|
||||
|
||||
const lines = 'lines' in req.query ? parseInt(req.query.lines, 10) : 10; // we ignore last-event-id
|
||||
const lines = typeof req.query.lines === 'string' ? parseInt(req.query.lines, 10) : 10; // we ignore last-event-id
|
||||
if (isNaN(lines)) return next(new HttpError(400, 'lines must be a number'));
|
||||
|
||||
const options = {
|
||||
lines: lines,
|
||||
follow: false,
|
||||
format: req.query.format || 'json'
|
||||
format: typeof req.query.format === 'string' ? req.query.format : 'json'
|
||||
};
|
||||
|
||||
const [error, logStream] = await safe(tasks.getLogs(req.resources.task, options));
|
||||
@@ -89,7 +89,7 @@ async function getLogs(req, res, next) {
|
||||
async function getLogStream(req, res, next) {
|
||||
assert.strictEqual(typeof req.resources.task, 'object');
|
||||
|
||||
const lines = 'lines' in req.query ? parseInt(req.query.lines, 10) : 10; // we ignore last-event-id
|
||||
const lines = typeof req.query.lines === 'string' ? parseInt(req.query.lines, 10) : 10; // we ignore last-event-id
|
||||
if (isNaN(lines)) return next(new HttpError(400, 'lines must be a valid number'));
|
||||
|
||||
function sse(id, data) { return 'id: ' + id + '\ndata: ' + data + '\n\n'; }
|
||||
|
||||
Reference in New Issue
Block a user