Skip to content

Commit

Permalink
Fix potential ReDOS-Attack-Vector in Headerparser (#72)
Browse files Browse the repository at this point in the history
* avoid potential catastrophic backtracking

* add changelog
  • Loading branch information
Uzlopak authored Dec 9, 2021
1 parent 811ec0d commit 7c19c1d
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 8 deletions.
6 changes: 5 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
# Changelog

Major changes since the last busboy release (0.31):
Major changes since the last busboy release (0.3.1):

# 1.0.1 - TBD

* Fix potential ReDOS-Attack-Vector in Headerparser (#72)

# 1.0.0 - 04 December, 2021

Expand Down
19 changes: 12 additions & 7 deletions deps/dicer/lib/HeaderParser.js
Original file line number Diff line number Diff line change
Expand Up @@ -79,14 +79,19 @@ HeaderParser.prototype._parseHeader = function () {
continue
}
}

const posColon = lines[i].indexOf(':')
if (
posColon === -1 ||
posColon === 0
) {
return
}
m = RE_HDR.exec(lines[i])
if (m) {
h = m[1].toLowerCase()
if (m[2]) {
if (this.header[h] === undefined) { this.header[h] = [m[2]] } else { this.header[h].push(m[2]) }
} else { this.header[h] = [''] }
if (++this.npairs === this.maxHeaderPairs) { break }
} else { return }
h = m[1].toLowerCase()
this.header[h] = this.header[h] || []
this.header[h].push((m[2] || ''))
if (++this.npairs === this.maxHeaderPairs) { break }
}
}

Expand Down
21 changes: 21 additions & 0 deletions test/dicer-headerparser.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,27 @@ describe('dicer-headerparser', () => {
},
what: 'should enforce maxHeaderSize of 32 and get only first character of second pair'
},
{
source: ['Content-Type:\r\n text/plain',
' : '
].join('\r\n') + DCRLF,
expected: { 'content-type': [' text/plain : '] },
what: 'should not break if invalid header pair (colon exists but empty key and value) is provided'
},
{
source: ['Content-Type:\r\n text/plain',
'FoobazFoobazFoobazFoobazFoobazFoobazFoobazFoobazFoobazFoobazFoobazFoobazFoobazFoobazFoobazFoobazFoobazFoobazFoobazFoobaz'
].join('\r\n') + DCRLF,
expected: { 'content-type': [' text/plain'] },
what: 'should not break if invalid header pair (no distinctive colon) is provided'
},
{
source: ['Content-Type:\r\n text/plain',
':FoobazFoobazFoobazFoobazFoobazFoobazFoobazFoobazFoobazFoobazFoobazFoobazFoobazFoobazFoobazFoobazFoobazFoobazFoobazFoobaz'
].join('\r\n') + DCRLF,
expected: { 'content-type': [' text/plain'] },
what: 'should not break if invalid header pair (no key) is provided'
},
{
source: ['Content-Type:\t text/plain',
'Content-Length:0'
Expand Down

0 comments on commit 7c19c1d

Please sign in to comment.