Skip to content

Commit

Permalink
fix: Fix path traversal vulnerability
Browse files Browse the repository at this point in the history
  • Loading branch information
meltyshev committed Aug 3, 2022
1 parent fbe24c0 commit ac1df52
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 7 deletions.
8 changes: 2 additions & 6 deletions server/api/controllers/attachments/download-thumbnail.js
Expand Up @@ -14,10 +14,6 @@ module.exports = {
regex: /^[0-9]+$/,
required: true,
},
filename: {
type: 'string',
required: true,
},
},

exits: {
Expand Down Expand Up @@ -54,14 +50,14 @@ module.exports = {
sails.config.custom.attachmentsPath,
attachment.dirname,
'thumbnails',
inputs.filename,
'cover-256.jpg',
);

if (!fs.existsSync(filePath)) {
throw Errors.ATTACHMENT_NOT_FOUND;
}

this.res.type(attachment.filename);
this.res.type('image/jpeg');
this.res.set('Cache-Control', 'private, max-age=900'); // TODO: move to config

return exits.success(fs.createReadStream(filePath));
Expand Down
2 changes: 1 addition & 1 deletion server/config/routes.js
Expand Up @@ -80,7 +80,7 @@ module.exports.routes = {
skipAssets: false,
},

'GET /attachments/:id/download/thumbnails/:filename': {
'GET /attachments/:id/download/thumbnails/cover-256.jpg': {
action: 'attachments/download-thumbnail',
skipAssets: false,
},
Expand Down

0 comments on commit ac1df52

Please sign in to comment.