Skip to content

Commit 5f294bb

Browse files
authored
Merge commit from fork
* fix: avoid redos on host and protocol getter Only effect on app.proxy enable closes GHSA-593f-38f6-jp5m * Release 2.15.4
1 parent 77cbf2e commit 5f294bb

File tree

3 files changed

+21
-4
lines changed

3 files changed

+21
-4
lines changed

History.md

+5
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,9 @@
11

2+
2.15.4 / 2025-02-11
3+
==================
4+
5+
fix: avoid redos on host and protocol getter
6+
27
2.15.3 / 2024-04-11
38
==================
49

lib/request.js

+15-3
Original file line numberDiff line numberDiff line change
@@ -257,7 +257,7 @@ module.exports = {
257257
if (!host) host = this.get('Host');
258258
}
259259
if (!host) return '';
260-
return host.split(/\s*,\s*/, 1)[0];
260+
return splitCommaSeparatedValues(host, 1)[0];
261261
},
262262

263263
/**
@@ -402,7 +402,7 @@ module.exports = {
402402
if (this.socket.encrypted) return 'https';
403403
if (!this.app.proxy) return 'http';
404404
const proto = this.get('X-Forwarded-Proto');
405-
return proto ? proto.split(/\s*,\s*/, 1)[0] : 'http';
405+
return proto ? splitCommaSeparatedValues(proto, 1)[0] : 'http';
406406
},
407407

408408
/**
@@ -434,7 +434,7 @@ module.exports = {
434434
const proxy = this.app.proxy;
435435
const val = this.get(this.app.proxyIpHeader);
436436
let ips = proxy && val
437-
? val.split(/\s*,\s*/)
437+
? splitCommaSeparatedValues(val)
438438
: [];
439439
if (this.app.maxIpsCount > 0) {
440440
ips = ips.slice(-this.app.maxIpsCount);
@@ -724,3 +724,15 @@ module.exports = {
724724
if (util.inspect.custom) {
725725
module.exports[util.inspect.custom] = module.exports.inspect;
726726
}
727+
728+
/**
729+
* Split a comma-separated value string into an array of values, with an optional limit.
730+
* All the values are trimmed of whitespace.
731+
*
732+
* @param {string} value - The comma-separated value string to split.
733+
* @param {number} [limit] - The maximum number of values to return.
734+
* @returns {string[]} An array of values from the comma-separated string.
735+
*/
736+
function splitCommaSeparatedValues(value, limit) {
737+
return value.split(',', limit).map(v => v.trim());
738+
}

package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "koa",
3-
"version": "2.15.3",
3+
"version": "2.15.4",
44
"description": "Koa web app framework",
55
"main": "lib/application.js",
66
"exports": {

0 commit comments

Comments
 (0)