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

x-pack/filebeat/input/http_endpoint: ensure all responses are HTML-escaped #39329

Merged
merged 1 commit into from
May 5, 2024
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.next.asciidoc
Original file line number Diff line number Diff line change
Expand Up @@ -256,6 +256,7 @@ https://github.com/elastic/beats/compare/v8.8.1\...main[Check the HEAD diff]
- Add debugging breadcrumb to logs when writing request trace log. {pull}38636[38636]
- added benchmark input {pull}37437[37437]
- added benchmark input and discard output {pull}37437[37437]
- Ensure all responses sent by HTTP Endpoint are HTML-escaped. {pull}39329[39329]

*Auditbeat*

Expand Down
10 changes: 9 additions & 1 deletion x-pack/filebeat/input/http_endpoint/input.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,12 @@
package http_endpoint

import (
"bytes"
"context"
"crypto/tls"
"encoding/base32"
"encoding/binary"
"encoding/json"
"errors"
"fmt"
"net"
Expand Down Expand Up @@ -322,7 +324,7 @@ func newHandler(ctx context.Context, c config, prg *program, pub stateless.Publi
program: prg,
messageField: c.Prefix,
responseCode: c.ResponseCode,
responseBody: c.ResponseBody,
responseBody: htmlEscape(c.ResponseBody),
includeHeaders: canonicalizeHeaders(c.IncludeHeaders),
preserveOriginalEvent: c.PreserveOriginalEvent,
crc: newCRC(c.CRCProvider, c.CRCSecret),
Expand Down Expand Up @@ -350,6 +352,12 @@ func newHandler(ctx context.Context, c config, prg *program, pub stateless.Publi
return h
}

func htmlEscape(s string) string {
var buf bytes.Buffer
json.HTMLEscape(&buf, []byte(s))
return buf.String()
}

// newID returns an ID derived from the current time.
func newID() string {
var data [8]byte
Expand Down
Loading