Skip to content

Commit d6e6204

Browse files
committed
deps: encodeurl@~2.0.0
1 parent 6da57c7 commit d6e6204

File tree

4 files changed

+11
-24
lines changed

4 files changed

+11
-24
lines changed

History.md

+6
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,9 @@
1+
unreleased
2+
==========
3+
4+
* deps: encodeurl@~2.0.0
5+
- Removes encoding of `\`, `|`, and `^` to align better with URL spec
6+
17
4.19.2 / 2024-03-25
28
==========
39

lib/response.js

+1-9
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,6 @@ module.exports = res
5555
*/
5656

5757
var charsetRegExp = /;\s*charset\s*=/;
58-
var schemaAndHostRegExp = /^(?:[a-zA-Z][a-zA-Z0-9+.-]*:)?\/\/[^\\\/\?]+/;
5958

6059
/**
6160
* Set status `code`.
@@ -914,14 +913,7 @@ res.location = function location(url) {
914913
loc = String(url);
915914
}
916915

917-
var m = schemaAndHostRegExp.exec(loc);
918-
var pos = m ? m[0].length + 1 : 0;
919-
920-
// Only encode after host to avoid invalid encoding which can introduce
921-
// vulnerabilities (e.g. `\\` to `%5C`).
922-
loc = loc.slice(0, pos) + encodeUrl(loc.slice(pos));
923-
924-
return this.set('Location', loc);
916+
return this.set('Location', encodeUrl(loc));
925917
};
926918

927919
/**

package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@
3737
"cookie-signature": "1.0.6",
3838
"debug": "2.6.9",
3939
"depd": "2.0.0",
40-
"encodeurl": "~1.0.2",
40+
"encodeurl": "~2.0.0",
4141
"escape-html": "~1.0.3",
4242
"etag": "~1.8.1",
4343
"finalhandler": "1.2.0",

test/res.location.js

+3-14
Original file line numberDiff line numberDiff line change
@@ -293,23 +293,12 @@ describe('res', function(){
293293
);
294294
});
295295

296-
it('should percent encode backslashes in the path', function (done) {
296+
it('should keep backslashes in the path', function (done) {
297297
var app = createRedirectServerForDomain('google.com');
298298
testRequestedRedirect(
299299
app,
300300
'https://google.com/foo\\bar\\baz',
301-
'https://google.com/foo%5Cbar%5Cbaz',
302-
'google.com',
303-
done
304-
);
305-
});
306-
307-
it('should encode backslashes in the path after the first backslash that triggered path parsing', function (done) {
308-
var app = createRedirectServerForDomain('google.com');
309-
testRequestedRedirect(
310-
app,
311-
'https://google.com\\@app\\l\\e.com',
312-
'https://google.com\\@app%5Cl%5Ce.com',
301+
'https://google.com/foo\\bar\\baz',
313302
'google.com',
314303
done
315304
);
@@ -364,7 +353,7 @@ describe('res', function(){
364353
testRequestedRedirect(
365354
app,
366355
'file:///etc\\passwd',
367-
'file:///etc%5Cpasswd',
356+
'file:///etc\\passwd',
368357
'',
369358
done
370359
);

0 commit comments

Comments
 (0)