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
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
Fix http parsing of repeated headers
Packetbeat HTTP protocol parser was not concatenating properly repeated
headers in a request or response. This caused corruption in the header
in the form of null bytes (\u0000).
adriansr committed Feb 8, 2018
commit f77a6cd022930e25d44566fac885869acb9bd44c
1 change: 1 addition & 0 deletions CHANGELOG.asciidoc
Original file line number Diff line number Diff line change
@@ -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*

4 changes: 2 additions & 2 deletions packetbeat/protos/http/http_parser.go
Original file line number Diff line number Diff line change
@@ -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 {
22 changes: 22 additions & 0 deletions packetbeat/protos/http/http_test.go
Original file line number Diff line number Diff line change
@@ -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,