Skip to content

Commit

Permalink
Fix CloudFront logs parsing where Content-Length is provided as "-" (#…
Browse files Browse the repository at this point in the history
…1076)

* Fix CloudFront logs parsing where Content-Length is provided as "-"

The "sc-content-len" field in the CloudFront logs format provides the value of
the "Content-Length" response header, as sent by the server.

This header is not a required header and in cases where it is not provided,
CloudFront instead provides the default value of "-" in the log files.

That does however not parse with the CloudFront parser as it expects the field
to always have a number in this column.

This change fixes that by instead changing the column to be parsed via the
"DATA" grok pattern instead of "NUMBER".

An extra test line was added to check this case.

* enhance: run index workflow manually because forked repo

---------

Co-authored-by: Laurence <[email protected]>
  • Loading branch information
Tenzer and LaurenceJJones authored Jul 11, 2024
1 parent 58ce31d commit 438f04c
Show file tree
Hide file tree
Showing 4 changed files with 116 additions and 9 deletions.
8 changes: 6 additions & 2 deletions .index.json
Original file line number Diff line number Diff line change
Expand Up @@ -6166,7 +6166,7 @@
"crowdsecurity/aws-cloudfront": {
"path": "parsers/s01-parse/crowdsecurity/aws-cloudfront.yaml",
"stage": "s01-parse",
"version": "0.2",
"version": "0.3",
"versions": {
"0.1": {
"digest": "795f0501182540325f30f3ca69ac7237653549989a65838d0c218fc03589ddcc",
Expand All @@ -6175,10 +6175,14 @@
"0.2": {
"digest": "62f22527304c1287f7c52b28b5fcbba9c4a7c18fdbf4299414c77b15f7bf5f8b",
"deprecated": false
},
"0.3": {
"digest": "525b1d131081c2b35bc7ca97b9dfc4c2ebf2737f328ed91ae4c7882dc2c56705",
"deprecated": false
}
},
"long_description": "IyBEZXNjcmlwdGlvbgpBIHBhcnNlciBmb3IgQVdTIENsb3VkRnJvbnQgYWNjZXNzIGxvZ3MuCgojIFVzYWdlCgpDbG91ZGZyb250IGRlbGl2ZXJzIGxvZ3MgdG8gUzMsIHNvIHlvdSBjYW4gdXNlIGNyb3dkc2VjIFtTMyBkYXRhc291cmNlXShodHRwczovL2RvY3MuY3Jvd2RzZWMubmV0L2RvY3MvbmV4dC9kYXRhX3NvdXJjZXMvczMvKSB0byByZWF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ogaHR0cF9hY2Nlc3MtbG9nCiAgICAtIHRhcmdldDogZXZ0LlN0clRpbWUKICAgICAgZXhwcmVzc2lvbjogImV2dC5QYXJzZWQueWVhciArICctJyArIGV2dC5QYXJzZWQubW9udGggKyAnLScgKyBldnQuUGFyc2VkLmRheSArICdUJyArIGV2dC5QYXJzZWQudGltZSArICdaJyIKICAgIC0gbWV0YTogc291cmNlX2lwCiAgICAgIGV4cHJlc3Npb246ICJldnQuUGFyc2VkLmNfaXAiCiAgICAtIG1ldGE6IGh0dHBfc3RhdHVzCiAgICAgIGV4cHJlc3Npb246ICJldnQuUGFyc2VkLnNjX3N0YXR1cyIKICAgIC0gbWV0YTogaHR0cF9wYXRoCiAgICAgIGV4cHJlc3Npb246IHwKICAgICAgICBldnQuUGFyc2VkLmNzX3VyaV9xdWVyeSA9PSAiLSIgPyBldnQuUGFyc2VkLmNzX3VyaV9zdGVtIDogZXZ0LlBhcnNlZC5jc191cmlfc3RlbSArICc/JyArIGV2dC5QYXJzZWQuY3NfdXJpX3F1ZXJ5CiAgICAtIG1ldGE6IGh0dHBfdmVyYgogICAgICBleHByZXNzaW9uOiAiZXZ0LlBhcnNlZC5jc19tZXRob2QiCiAgICAtIG1ldGE6IGh0dHBfdXNlcl9hZ2VudAogICAgICBleHByZXNzaW9uOiAiZXZ0LlBhcnNlZC5jc191c2VyX2FnZW50Ig==",
"description": "Parse AWS CloudFront access logs",
"author": "crowdsecurity",
"labels": null
Expand Down
3 changes: 2 additions & 1 deletion .tests/aws-cloudfront-logs/aws-cloudfront-logs.log
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
2024-03-12 15:22:28 CDG50-P2 703 1.2.3.4 GET d6rcaj0q1hys9.cloudfront.net /testseb 400 - curl/7.81.0 query_param=42 - Error 375WZmnR4hhhnlZKNn0D_LvkWhAqvWvBsUqySq8f_GOoAPP3k8R8fw== hub-cdn.crowdsec.net https 62 0.113 - TLSv1.3 TLS_AES_128_GCM_SHA256 Error HTTP/2.0 - - 51754 0.113 Error text/plain;%20charset=utf-8 20 - -
2024-03-12 15:22:28 CDG50-P2 703 1.2.3.4 GET d6rcaj0q1hys9.cloudfront.net /testseb 400 - curl/7.81.0 query_param=42 - Error 375WZmnR4hhhnlZKNn0D_LvkWhAqvWvBsUqySq8f_GOoAPP3k8R8fw== hub-cdn.crowdsec.net https 62 0.113 - TLSv1.3 TLS_AES_128_GCM_SHA256 Error HTTP/2.0 - - 51754 0.113 Error text/plain;%20charset=utf-8 20 - -
2024-03-12 15:22:28 CDG50-P2 703 1.2.3.4 GET d6rcaj0q1hys9.cloudfront.net /testseb 400 - curl/7.81.0 query_param=42 - Error 375WZmnR4hhhnlZKNn0D_LvkWhAqvWvBsUqySq8f_GOoAPP3k8R8fw== hub-cdn.crowdsec.net https 62 0.113 - TLSv1.3 TLS_AES_128_GCM_SHA256 Error HTTP/2.0 - - 51754 0.113 Error text/plain;%20charset=utf-8 - - -
Loading

0 comments on commit 438f04c

Please sign in to comment.