diff --git a/services/clsi/app/js/StaticServerForbidSymlinks.js b/services/clsi/app/js/StaticServerForbidSymlinks.js index 645053dc51..219408eb11 100644 --- a/services/clsi/app/js/StaticServerForbidSymlinks.js +++ b/services/clsi/app/js/StaticServerForbidSymlinks.js @@ -25,9 +25,13 @@ module.exports = ForbidSymlinks = function (staticFn, root, options) { let file, projectId, result const path = req.url // check that the path is of the form /project_id_or_name/path/to/file.log - if ((result = path.match(/^\/?([a-zA-Z0-9_-]+)\/(.*)/))) { + if ((result = path.match(/^\/([a-zA-Z0-9_-]+)\/(.*)$/s))) { projectId = result[1] file = result[2] + if (path !== `/${projectId}/${file}`) { + logger.warn({ path }, 'unrecognized file request') + return res.sendStatus(404) + } } else { logger.warn({ path }, 'unrecognized file request') return res.sendStatus(404) diff --git a/services/clsi/test/unit/js/StaticServerForbidSymlinksTests.js b/services/clsi/test/unit/js/StaticServerForbidSymlinksTests.js index dd67506bfc..0a3806a1e6 100644 --- a/services/clsi/test/unit/js/StaticServerForbidSymlinksTests.js +++ b/services/clsi/test/unit/js/StaticServerForbidSymlinksTests.js @@ -94,6 +94,23 @@ describe('StaticServerForbidSymlinks', function () { }) }) + describe('with a new line', function () { + beforeEach(function () { + this.req.url = '/12345/output.pdf\nother file' + this.fs.realpath = sinon.stub().yields() + }) + + it('should process the correct file', function (done) { + this.res.sendStatus = () => { + this.fs.realpath.should.have.been.calledWith( + `${this.settings.path.compilesDir}/12345/output.pdf\nother file` + ) + done() + } + this.StaticServerForbidSymlinks(this.req, this.res) + }) + }) + describe('with a symlink file', function () { beforeEach(function () { return (this.fs.realpath = sinon