Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Prev Previous commit
v4.1.3: [security] Fix crash on redirect with formfeed in URL (CVE-20…
…19-10775)

This fixes CVE-2019-10775. I'll postpone regression tests because
the request library cannot send those requests (crashing the client
instead of ecstatic), so I'll need to find another module that can.
  • Loading branch information
mk-pmb committed Apr 1, 2020
commit d37b507fb1b3c77acb2a6a4d23ebcabf68d830b2
14 changes: 12 additions & 2 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 @@ -375,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 @@ -394,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 <[email protected]> (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