-
Notifications
You must be signed in to change notification settings - Fork 2.2k
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
validate sns message body #2835
base: main
Are you sure you want to change the base?
Conversation
Signed-off-by: Yijie Qin <qinyijie@amazon.com>
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 code could use strings.ToValidUTF8
to eliminate invalid UTF-8 byte sequence rather than dropping everything.
Thanks for the comment! On the other hand https://pkg.go.dev/strings#ToValidUTF8 can also return you an empty string as described here: "ToValidUTF8 returns a copy of the string s with each run of invalid UTF-8 byte sequences replaced by the replacement string, which may be empty." @simonpasquier please let me know what you think |
My opinion is dropping everything is safer option because it will be very obvious to the receiver that something is wrong. For example, in the case where message body is a JSON, replacing the whole body would choke the receiver's JSON parser - a very clear signal something is wrong; if we replace invalid character, then the JSON parsing would succeed but the receiver consumes incomplete information (imagine we replace a invalid "0", in someone's bank account). However, I do think there are cases where replacing invalid character would be the right thing, but by default I feel we should go with the safest behaviour. In the future, we can have configuration options to let users configure different behaviour upon invalid SNS message body. |
in prometheus we generally drop when there is an error rather than potentially misleading the users, I think I prefer to have the explicit error as well. |
Thanks @roidelapluie for your comments. I wonder if everybody is okay with current approach, can i get approved for this PR? Thank you so much Yijie |
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 are we replacing messages with error messages if those messages will never be sent? Or maybe I've misread the code.
Other than that this looks good (after rebase).
@@ -36,6 +36,12 @@ import ( | |||
"github.com/prometheus/alertmanager/types" | |||
) | |||
|
|||
const ( | |||
// The errors |
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 errors | |
// Error messages to replace an invalid message with. |
Add validation for message, if not a validate message, we will replace the message with error message
Separate from #2808