Skip to content

Commit 5054af6

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 * 3.0.0-alpha.3
1 parent 71902b1 commit 5054af6

File tree

3 files changed

+22
-4
lines changed

3 files changed

+22
-4
lines changed

History.md

+6
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,10 @@
11

2+
3.0.0-alpha.3 / 2025-02-11
3+
==================
4+
5+
**fixes**
6+
- Avoid redos on host and protocol getter
7+
28
3.0.0-alpha.2 / 2024-11-04
39
==================
410

lib/request.js

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

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

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

package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "koa",
3-
"version": "3.0.0-alpha.2",
3+
"version": "3.0.0-alpha.3",
44
"publishConfig": {
55
"tag": "experimental"
66
},

0 commit comments

Comments
 (0)