Skip to content
Myr

res.sendfile() responding with 403 on malicious path

Before adoption: this commit came in with the history the project adopted, so no landing records it.

authored by Tj Holowaychuk · committed by Tj Holowaychuk · parent 949803d · Browse files · 3 files+6 added−6 removed
This commit

State

Before adoption: this commit came in with the history the project adopted, so no landing records it.

Diff stats

3 files+6 added−6 removed

  • tests:+4 added−1 removed
  • other:+2 added−5 removed

3 files+6 added−6 removed

modified:docs/guide.md-5 removed
450 unmodified lines
451Used by `res.download()` to transfer an arbitrary file. 452453 res.sendfile('path/to/my.file');454455This is _not_ a substitution for Connect's _staticProvider_ middleware, it does not456support HTTP caching, and does not perform any security checks. This method is utilized457by _res.download()_ to transfer static files, and allows you do to so from outside of458the public directory, so suitable security checks should be applied.459455This method accepts a callback which when given will be called on an exception, as well as when the transfer has completed. When a callback is not given, and the file has __not__ been streamed, _next(err)_ will be called on an exception.456457 res.sendfile(path, function(err, path){458 if (err) {
291 unmodified lines
modified:lib/express/response.js+2 added
132 unmodified lines
133http.ServerResponse.prototype.sendfile = function(path, fn){134 var self = this,135 streamThreshold = this.app.set('stream threshold') || 32 * 1024;136137 if (~path.indexOf('..')) this.send(403);138139 function error(err) {140 delete self.headers['Content-Disposition'];141 if (fn) {142 fn(err, path);
199 unmodified lines
modified:test/response.test.js+4 added-1 removed
195 unmodified lines
196 });197 });198 199 app.use(express.errorHandler());200 200201 assert.response(app,202 { url: '/../express.test.js' },203 { body: 'Forbidden', status: 403 });204 assert.response(app,205 { url: '/user.json' },206 { body: '{"name":"tj"}', status: 200, headers: { 'Content-Type': 'application/json' }});207 assert.response(app,208 { url: '/hello.haml' },
98 unmodified lines