Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(static): avoid user-provided data in Error messages being interpreted as sprintf codes #1472

Merged
merged 1 commit into from Sep 7, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion lib/plugins/static.js
Expand Up @@ -153,7 +153,7 @@ function serveStatic(options) {
}

if (req.method !== 'GET' && req.method !== 'HEAD') {
next(new MethodNotAllowedError(req.method));
next(new MethodNotAllowedError('%s', req.method));
return;
}

Expand Down
31 changes: 31 additions & 0 deletions test/plugins/static.test.js
Expand Up @@ -355,4 +355,35 @@ describe('static resource plugin', function () {
});
});
});

it('static responds 404 for missing file', function (done) {
var p = '/public/no-such-file.json';
var tmpPath = path.join(process.cwd(), '.tmp');

SERVER.get(new RegExp('/public/.*'),
restify.plugins.serveStatic({directory: tmpPath}));

CLIENT.get(p, function (err, req, res, obj) {
assert.ok(err);
assert.equal(err.statusCode, 404);
assert.equal(err.restCode, 'ResourceNotFound');
return done();
});
});

it('GH-1382 static responds 404 for missing file with percent-codes',
function (done) {
var p = '/public/no-%22such-file.json';
var tmpPath = path.join(process.cwd(), '.tmp');

SERVER.get(new RegExp('/public/.*'),
restify.plugins.serveStatic({directory: tmpPath}));

CLIENT.get(p, function (err, req, res, obj) {
assert.ok(err);
assert.equal(err.statusCode, 404);
assert.equal(err.restCode, 'ResourceNotFound');
return done();
});
});
});