Sanitize rootResourcePath
This commit is contained in:
@@ -27,10 +27,12 @@ module.exports = RequestParser =
|
|||||||
response.timeout = response.timeout * 1000 # milliseconds
|
response.timeout = response.timeout * 1000 # milliseconds
|
||||||
|
|
||||||
response.resources = (@_parseResource(resource) for resource in (compile.resources or []))
|
response.resources = (@_parseResource(resource) for resource in (compile.resources or []))
|
||||||
response.rootResourcePath = @_parseAttribute "rootResourcePath",
|
|
||||||
|
rootResourcePath = @_parseAttribute "rootResourcePath",
|
||||||
compile.rootResourcePath
|
compile.rootResourcePath
|
||||||
default: "main.tex"
|
default: "main.tex"
|
||||||
type: "string"
|
type: "string"
|
||||||
|
response.rootResourcePath = RequestParser._sanitizePath(rootResourcePath)
|
||||||
catch error
|
catch error
|
||||||
return callback error
|
return callback error
|
||||||
|
|
||||||
@@ -72,3 +74,5 @@ module.exports = RequestParser =
|
|||||||
throw "Default not implemented"
|
throw "Default not implemented"
|
||||||
return attribute
|
return attribute
|
||||||
|
|
||||||
|
_sanitizePath: (path) ->
|
||||||
|
path.replace(/[^a-zA-Z0-9_\-;.,\/ ]/g, "")
|
||||||
@@ -204,6 +204,13 @@ describe "RequestParser", ->
|
|||||||
@callback.calledWith("rootResourcePath attribute should be a string")
|
@callback.calledWith("rootResourcePath attribute should be a string")
|
||||||
.should.equal true
|
.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"
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user