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: Allow non-padded base64 data to be decoded by decode_base64_field #27311

Merged
merged 2 commits into from
Aug 23, 2021
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 @@ -513,6 +513,7 @@ https://github.com/elastic/beats/compare/v7.0.0-alpha2...master[Check the HEAD d
- Add cgroups V2 support {pull}27242[27242]
- update ECS field definitions to ECS 1.11.0. {pull}27107[27107]
- The disk queue is now GA. {pull}27515[27515]
- Allow non-padded base64 data to be decoded by decode_base64_field {pull}27311[27311], {issue}27021[27021]

*Auditbeat*

Expand Down
3 changes: 2 additions & 1 deletion libbeat/processors/actions/decode_base64_field.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ package actions
import (
"encoding/base64"
"fmt"
"strings"

"github.com/pkg/errors"

Expand Down Expand Up @@ -110,7 +111,7 @@ func (f *decodeBase64Field) decodeField(event *beat.Event) error {
return fmt.Errorf("invalid type for `from`, expecting a string received %T", value)
}

decodedData, err := base64.StdEncoding.DecodeString(base64String)
decodedData, err := base64.RawStdEncoding.DecodeString(strings.TrimRight(base64String, "="))
if err != nil {
return fmt.Errorf("error trying to decode %s: %v", base64String, err)
}
Expand Down
34 changes: 34 additions & 0 deletions libbeat/processors/actions/decode_base64_field_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,40 @@ func TestDecodeBase64Run(t *testing.T) {
},
error: false,
},
{
description: "simple field padded base64 decode from and to equals",
config: base64Config{
Field: fromTo{
From: "field1", To: "field1",
},
IgnoreMissing: false,
FailOnError: true,
},
Input: common.MapStr{
"field1": "Y29ycmVjdCBwYWRkZWQgZGF0YQ==",
},
Output: common.MapStr{
"field1": "correct padded data",
},
error: false,
},
{
description: "simple field unpadded base64 decode from and to equals",
config: base64Config{
Field: fromTo{
From: "field1", To: "field1",
},
IgnoreMissing: false,
FailOnError: true,
},
Input: common.MapStr{
"field1": "dW5wYWRkZWQgZGF0YQ",
},
Output: common.MapStr{
"field1": "unpadded data",
},
error: false,
},
{
description: "simple field bad data - fail on error",
config: base64Config{
Expand Down