Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix http parsing of repeated headers #6325

Merged
merged 1 commit into from
Feb 8, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
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
1 change: 1 addition & 0 deletions CHANGELOG.asciidoc
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,7 @@ https://github.com/elastic/beats/compare/v6.0.0-beta2...master[Check the HEAD di
- Fix http status phrase parsing not allow spaces. {pull}5312[5312]
- Fix http parse to allow to parse get request with space in the URI. {pull}5495[5495]
- Fix mysql SQL parser to trim `\r` from Windows Server `SELECT\r\n\t1`. {pull}5572[5572]
- Fix corruption when parsing repeated headers in an HTTP request or response. {pull}6325[6325]

*Winlogbeat*

Expand Down
4 changes: 2 additions & 2 deletions packetbeat/protos/http/http_parser.go
Original file line number Diff line number Diff line change
Expand Up @@ -356,8 +356,8 @@ func (parser *parser) parseHeader(m *message, data []byte) (bool, bool, int) {
if val, ok := m.headers[string(headerName)]; ok {
composed := make([]byte, len(val)+len(headerVal)+2)
off := copy(composed, val)
off = copy(composed[off:], []byte(", "))
copy(composed[off:], headerVal)
copy(composed[off:], []byte(", "))
copy(composed[off+2:], headerVal)

m.headers[string(headerName)] = composed
} else {
Expand Down
22 changes: 22 additions & 0 deletions packetbeat/protos/http/http_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1168,6 +1168,28 @@ func Test_gap_in_body_http1dot0(t *testing.T) {
assert.Equal(t, false, complete)
}

func TestHttpParser_composedHeaders(t *testing.T) {
data := "HTTP/1.1 200 OK\r\n" +
"Content-Length: 0\r\n" +
"Date: Tue, 14 Aug 2012 22:31:45 GMT\r\n" +
"Set-Cookie: aCookie=yummy\r\n" +
"Set-Cookie: anotherCookie=why%20not\r\n" +
"\r\n"
http := httpModForTests(nil)
http.parserConfig.sendHeaders = true
http.parserConfig.sendAllHeaders = true
message, ok, complete := testParse(http, data)

assert.True(t, ok)
assert.True(t, complete)
assert.False(t, message.isRequest)
assert.Equal(t, 200, int(message.statusCode))
assert.Equal(t, "OK", string(message.statusPhrase))
header, ok := message.headers["set-cookie"]
assert.True(t, ok)
assert.Equal(t, "aCookie=yummy, anotherCookie=why%20not", string(header))
}

func testCreateTCPTuple() *common.TCPTuple {
t := &common.TCPTuple{
IPLength: 4,
Expand Down