-
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
x-pack/filebeat/input/httpjson: add hash template function #31630
Conversation
Pinging @elastic/security-external-integrations (Team:Security-External Integrations) |
@@ -62,13 +62,15 @@ func (t *valueTpl) Unpack(in string) error { | |||
"mul": mul, | |||
"div": div, | |||
"hmac": hmacStringHex, | |||
"hash": hashStringHex, | |||
"base64Encode": base64Encode, | |||
"base64EncodeNoPad": base64EncodeNoPad, | |||
"base64Decode": base64Decode, | |||
"base64DecodeNoPad": base64DecodeNoPad, | |||
"join": join, | |||
"sprintf": fmt.Sprintf, |
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 noticed this exists; it is already provided by the text/template packages global template functions via printf
.
n += len(d) | ||
} | ||
if n == 0 { | ||
return nil |
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.
Why is there special handling for empty values? I would have expected that these result in the hash value for 0 length input / empty string (like the same values listed in the test vectors for 0 len values).
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.
The current behaviour for hmac treats "" specially (I think this is wrong, but I was keeping that behaviour). I can drop that if you want.
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 think we should remove the special handling for hash
.
I just looked at the hmac implementation and don't know why the special handling was added there. @marc-gr would there be a reason to handle empty values with special behavior?
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.
The only reason I can remember of is since this will be used from templates an empty value would come as <no value>
, but now that I try to think about anything else I am leaning more towards a bad outcome of trying to be too defensive. I'd rather change the way we deal with it in the other functions.
This pull request is now in conflicts. Could you fix it? 🙏
|
Taking the opportunity to remove nolint directives for gosec linting that is in the process of being removed. |
n += len(d) | ||
} | ||
if n == 0 { | ||
return nil |
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.
The only reason I can remember of is since this will be used from templates an empty value would come as <no value>
, but now that I try to think about anything else I am leaning more towards a bad outcome of trying to be too defensive. I'd rather change the way we deal with it in the other functions.
This pull request is now in conflicts. Could you fix it? 🙏
|
What does this PR do?
This adds template helper functions for hashing a set of strings, output as hex or base64.
Why is it important?
This feature is needed for authentication with some APIs.
Checklist
I have made corresponding change to the default configuration filesCHANGELOG.next.asciidoc
orCHANGELOG-developer.next.asciidoc
.Author's Checklist
How to test this PR locally
Related issues
Use cases
Screenshots
Logs