From 90cda12ed937b9d5fb5d694cd403d7684a6f2c4a Mon Sep 17 00:00:00 2001 From: James Allen Date: Wed, 11 Feb 2015 12:03:36 +0000 Subject: [PATCH] Sanitize rootResourcePath --- app/coffee/RequestParser.coffee | 6 +++++- test/unit/coffee/RequestParserTests.coffee | 9 ++++++++- 2 files changed, 13 insertions(+), 2 deletions(-) diff --git a/app/coffee/RequestParser.coffee b/app/coffee/RequestParser.coffee index d98ca82..93c843d 100644 --- a/app/coffee/RequestParser.coffee +++ b/app/coffee/RequestParser.coffee @@ -27,10 +27,12 @@ module.exports = RequestParser = response.timeout = response.timeout * 1000 # milliseconds response.resources = (@_parseResource(resource) for resource in (compile.resources or [])) - response.rootResourcePath = @_parseAttribute "rootResourcePath", + + rootResourcePath = @_parseAttribute "rootResourcePath", compile.rootResourcePath default: "main.tex" type: "string" + response.rootResourcePath = RequestParser._sanitizePath(rootResourcePath) catch error return callback error @@ -72,3 +74,5 @@ module.exports = RequestParser = throw "Default not implemented" return attribute + _sanitizePath: (path) -> + path.replace(/[^a-zA-Z0-9_\-;.,\/ ]/g, "") \ No newline at end of file diff --git a/test/unit/coffee/RequestParserTests.coffee b/test/unit/coffee/RequestParserTests.coffee index 35ad6f4..8545ff2 100644 --- a/test/unit/coffee/RequestParserTests.coffee +++ b/test/unit/coffee/RequestParserTests.coffee @@ -204,6 +204,13 @@ describe "RequestParser", -> @callback.calledWith("rootResourcePath attribute should be a string") .should.equal true - + describe "with a root resource path that needs escaping", -> + beforeEach -> + @validRequest.compile.rootResourcePath = "`rm -rf foo`.tex" + @RequestParser.parse @validRequest, @callback + @data = @callback.args[0][1] + + it "should return the escaped resource", -> + @data.rootResourcePath.should.equal "rm -rf foo.tex"