fix(modules/pipeline): ensure REST file API parses query parameters

Data send from the client with GET parameters are serialized in the
request body's `params` property. As express doesn't seem to parse
those, we have to do it manually to perform object property traversals.
This commit is contained in:
Pascal Precht 2018-10-18 18:37:57 +02:00
parent b654fdecd8
commit 064b2da5a4
No known key found for this signature in database
GPG Key ID: 0EE28D8D6FD85D7D
1 changed files with 6 additions and 4 deletions

View File

@ -28,12 +28,14 @@ class Pipeline {
'get', 'get',
'/embark-api/file', '/embark-api/file',
(req, res) => { (req, res) => {
if (!fs.existsSync(req.query.path) || !req.query.path.startsWith(fs.dappPath())) { const queryParams = JSON.parse(req.query.params);
if (!fs.existsSync(queryParams.path) || !queryParams.path.startsWith(fs.dappPath())) {
return res.send({error: 'Path is invalid'}); return res.send({error: 'Path is invalid'});
} }
const name = path.basename(req.query.path); const name = path.basename(queryParams.path);
const content = fs.readFileSync(req.query.path, 'utf8'); const content = fs.readFileSync(queryParams.path, 'utf8');
res.send({name, content, path: req.query.path}); res.send({name, content, path: queryParams.path});
} }
); );