Check query input before running the mysql query

This commit is contained in:
nymkappa 2022-08-24 08:35:02 +02:00
parent 35512bef8d
commit 43cc9499b1
No known key found for this signature in database
GPG Key ID: E155910B16E8BD04

View File

@ -47,8 +47,17 @@ class ChannelsRoutes {
res.status(400).send('Missing parameter: public_key'); res.status(400).send('Missing parameter: public_key');
return; return;
} }
const index = parseInt(typeof req.query.index === 'string' ? req.query.index : '0', 10) || 0; const index = parseInt(typeof req.query.index === 'string' ? req.query.index : '0', 10) || 0;
const status: string = typeof req.query.status === 'string' ? req.query.status : ''; const status: string = typeof req.query.status === 'string' ? req.query.status : '';
if (index < -1) {
res.status(400).send('Invalid index');
}
if (['open', 'active', 'closed'].includes(status) === false) {
res.status(400).send('Invalid status');
}
const channels = await channelsApi.$getChannelsForNode(req.query.public_key, index, 10, status); const channels = await channelsApi.$getChannelsForNode(req.query.public_key, index, 10, status);
const channelsCount = await channelsApi.$getChannelsCountForNode(req.query.public_key, status); const channelsCount = await channelsApi.$getChannelsCountForNode(req.query.public_key, status);
res.header('Pragma', 'public'); res.header('Pragma', 'public');