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

validate sns message body #2835

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

qinxx108
Copy link
Contributor

Add validation for message, if not a validate message, we will replace the message with error message
Separate from #2808

Signed-off-by: Yijie Qin <qinyijie@amazon.com>
Copy link
Member

@simonpasquier simonpasquier left a 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.

@qinxx108
Copy link
Contributor Author

qinxx108 commented Apr 8, 2022

The code could use strings.ToValidUTF8 to eliminate invalid UTF-8 byte sequence rather than dropping everything.

Thanks for the comment!
I wonder which will be better in case of user experience. The subject is replaced by some "error" alerting your subject is invalid VS the subject is changed without your notice

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

@alvinlin123
Copy link
Contributor

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.

@roidelapluie
Copy link
Member

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.

@qinxx108
Copy link
Contributor Author

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

Copy link
Contributor

@LeviHarrison LeviHarrison left a 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
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
// The errors
// Error messages to replace an invalid message with.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants