-
Notifications
You must be signed in to change notification settings - Fork 4.9k
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
Ignore trailing spaces in CEF messages #17253
Merged
Merged
Changes from 2 commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,4 @@ | ||
CEF:0|Elastic|Vaporware|1.0.0-alpha|18|Web request|low|eventId=3457 requestMethod=POST slat=38.915 slong=-77.511 proto=TCP sourceServiceName=httpd requestContext=https://www.google.com src=6.7.8.9 spt=33876 dst=192.168.10.1 dpt=443 request=https://www.example.com/cart | ||
CEF:0|Elastic|Vaporware|1.0.0-alpha|18|Authentication|low|eventId=123 src=6.7.8.9 spt=33876 dst=1.2.3.4 dpt=443 duser=alice suser=bob destinationTranslatedAddress=10.10.10.10 fileHash=bc8bbe52f041fd17318f08a0f73762ce oldFileHash=a9796280592f86b74b27e370662d41eb | ||
CEF:0|Elastic|Vaporware|1.0.0-alpha|18|Authentication|low|spriv=user dpriv=root | ||
CEF:0|Elastic|Vaporware|1.0.0-alpha|18|Authentication|low|message=This event is padded with whitespace dst=192.168.1.2 src=192.168.3.4 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -44,6 +44,14 @@ const ( | |
malformedExtensionEscape = `CEF:0|FooBar|Web Gateway|1.2.3.45.67|200|Success|2|rt=Sep 07 2018 14:50:39 cat=Access Log dst=1.1.1.1 dhost=foo.example.com suser=redacted src=2.2.2.2 requestMethod=POST request='https://foo.example.com/bar/bingo/1' requestClientApplication='Foo-Bar/2018.1.7; =Email:[email protected]; Guid:test=' cs1= cs1Label=Foo Bar` | ||
|
||
multipleMalformedExtensionValues = `CEF:0|vendor|product|version|event_id|name|Very-High| msg=Hello World error=Failed because id==old_id user=root angle=106.7<=180` | ||
|
||
paddedMessage = `CEF:0|security|threatmanager|1.0|100|message is padded|10|spt=1232 msg=Trailing space in non-final extensions is preserved src=10.0.0.192 ` | ||
|
||
crlfMessage = "CEF:0|security|threatmanager|1.0|100|message is padded|10|spt=1232 msg=Trailing space in final extensions is not preserved\t \r\n" | ||
|
||
tabMessage = "CEF:0|security|threatmanager|1.0|100|message is padded|10|spt=1232 msg=Tabs\tand\rcontrol\ncharacters are preserved\t src=127.0.0.1" | ||
|
||
tabNoSepMessage = "CEF:0|security|threatmanager|1.0|100|message has tabs|10|spt=1232 msg=Tab is not a separator\tsrc=127.0.0.1" | ||
) | ||
|
||
var testMessages = []string{ | ||
|
@@ -60,6 +68,9 @@ var testMessages = []string{ | |
escapesInExtension, | ||
malformedExtensionEscape, | ||
multipleMalformedExtensionValues, | ||
paddedMessage, | ||
crlfMessage, | ||
tabMessage, | ||
} | ||
|
||
func TestGenerateFuzzCorpus(t *testing.T) { | ||
|
@@ -322,6 +333,47 @@ func TestEventUnpack(t *testing.T) { | |
err := e.Unpack("CEF:0|||||||a=") | ||
assert.NoError(t, err) | ||
}) | ||
|
||
t.Run("padded", func(t *testing.T) { | ||
var e Event | ||
err := e.Unpack(paddedMessage) | ||
assert.NoError(t, err) | ||
assert.Equal(t, map[string]*Field{ | ||
"src": IPField("10.0.0.192"), | ||
"spt": IntegerField(1232), | ||
"msg": StringField("Trailing space in non-final extensions is preserved "), | ||
}, e.Extensions) | ||
}) | ||
|
||
t.Run("padded with extra whitespace chars", func(t *testing.T) { | ||
var e Event | ||
err := e.Unpack(crlfMessage) | ||
assert.NoError(t, err) | ||
assert.Equal(t, map[string]*Field{ | ||
"spt": IntegerField(1232), | ||
"msg": StringField("Trailing space in final extensions is not preserved"), | ||
}, e.Extensions) | ||
}) | ||
|
||
t.Run("internal whitespace chars", func(t *testing.T) { | ||
var e Event | ||
err := e.Unpack(tabMessage) | ||
assert.NoError(t, err) | ||
assert.Equal(t, map[string]*Field{ | ||
"spt": IntegerField(1232), | ||
"src": IPField("127.0.0.1"), | ||
"msg": StringField("Tabs\tand\rcontrol\ncharacters are preserved\t"), | ||
}, e.Extensions) | ||
}) | ||
|
||
t.Run("No tab as separator", func(t *testing.T) { | ||
var e Event | ||
err := e.Unpack(tabNoSepMessage) | ||
assert.Error(t, err) | ||
assert.Equal(t, map[string]*Field{ | ||
"spt": IntegerField(1232), | ||
}, e.Extensions) | ||
}) | ||
} | ||
|
||
func TestEventUnpackWithFullExtensionNames(t *testing.T) { | ||
|
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I was surprised that
%/extension_eof
worked for each individual extension, rather than just the final one. I'm definitely no Ragel expert.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No, I guess I didn't explain myself properly. extension_eof worked as expected. It's just that it captures a value until the last point saved by
@extension_value_mark
while extension_key saves the previous value up to the start of the separator. This made no difference before, but now it helps to capture trailing spaces in non-final extensions and to drop it in the final extension.I had to move it to a different place here to adjust for the case where a msg is padded and EOF is never reached by extension_value due to it not accepting trailing spaces.