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

v4.1.3: [security] Fix crash on redirect with formfeed in URL (CVE-2019-10775) #266

Merged
merged 2 commits into from
Apr 1, 2020
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 14 additions & 3 deletions lib/ecstatic.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,13 @@ function decodePathname(pathname) {
}


// eslint-disable-next-line no-control-regex
const nonUrlSafeCharsRgx = /[\x00-\x1F\x7F-\uFFFF]+/g;
function ensureUriEncoded(text) {
return String(text).replace(nonUrlSafeCharsRgx, encodeURIComponent);
}


// Check to see if we should try to compress a file with gzip.
function shouldCompressGzip(req) {
const headers = req.headers;
Expand Down Expand Up @@ -164,7 +171,8 @@ module.exports = function createMiddleware(_dir, _options) {
if (opts.weakCompare && clientEtag !== serverEtag
&& clientEtag !== `W/${serverEtag}` && `W/${clientEtag}` !== serverEtag) {
return false;
} else if (!opts.weakCompare && (clientEtag !== serverEtag || clientEtag.indexOf('W/') === 0)) {
}
if (!opts.weakCompare && (clientEtag !== serverEtag || clientEtag.indexOf('W/') === 0)) {
return false;
}
}
Expand Down Expand Up @@ -374,8 +382,10 @@ module.exports = function createMiddleware(_dir, _options) {
}, res, next);
} else {
// Try to serve default ./404.html
const rawUrl = (handleError ? `/${path.join(baseDir, `404.${defaultExt}`)}` : req.url);
const encodedUrl = ensureUriEncoded(rawUrl);
middleware({
url: (handleError ? `/${path.join(baseDir, `404.${defaultExt}`)}` : req.url),
url: encodedUrl,
headers: req.headers,
statusCode: 404,
}, res, next);
Expand All @@ -393,7 +403,8 @@ module.exports = function createMiddleware(_dir, _options) {
if (!pathname.match(/\/$/)) {
res.statusCode = 302;
const q = parsed.query ? `?${parsed.query}` : '';
res.setHeader('location', `${parsed.pathname}/${q}`);
const d = `${parsed.pathname}/${q}`;
res.setHeader('location', ensureUriEncoded(d));
res.end();
return;
}
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"author": "Joshua Holbrook <josh@nodejitsu.com> (http://jesusabdullah.net)",
"name": "ecstatic",
"description": "A simple static file server middleware",
"version": "4.1.2",
"version": "4.1.3",
"homepage": "https://github.com/jfhbrook/node-ecstatic",
"repository": {
"type": "git",
Expand Down