-
Notifications
You must be signed in to change notification settings - Fork 369
Verify SNS host for both Subscribe() and Unsubscribe()
#3763
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
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -125,6 +125,19 @@ func (payload *Payload) Subscribe() (ConfirmSubscriptionResponse, error) { | |
| return response, errors.New("Payload does not have a SubscribeURL!") | ||
| } | ||
|
|
||
| subscribeURL, err := url.Parse(payload.SubscribeURL) | ||
| if err != nil { | ||
| return response, err | ||
| } | ||
|
|
||
| if subscribeURL.Scheme != "https" { | ||
| return response, fmt.Errorf("url should be using https") | ||
| } | ||
|
|
||
| if !hostPattern.Match([]byte(subscribeURL.Host)) { | ||
| return response, fmt.Errorf("subscribe url is located on an invalid domain") | ||
| } | ||
|
|
||
| resp, err := http.Get(payload.SubscribeURL) | ||
| if err != nil { | ||
| return response, err | ||
|
|
@@ -147,6 +160,23 @@ func (payload *Payload) Subscribe() (ConfirmSubscriptionResponse, error) { | |
| // Unsubscribe will use the UnsubscribeURL in a payload to confirm a subscription and return a UnsubscribeResponse | ||
| func (payload *Payload) Unsubscribe() (UnsubscribeResponse, error) { | ||
| var response UnsubscribeResponse | ||
| if payload.UnsubscribeURL == "" { | ||
| return response, errors.New("payload does not have an UnsubscribeURL") | ||
| } | ||
|
Comment on lines
+163
to
+165
|
||
|
|
||
| unsubscribeURL, err := url.Parse(payload.UnsubscribeURL) | ||
| if err != nil { | ||
| return response, err | ||
| } | ||
|
|
||
| if unsubscribeURL.Scheme != "https" { | ||
| return response, fmt.Errorf("url should be using https") | ||
| } | ||
|
|
||
| if !hostPattern.Match([]byte(unsubscribeURL.Host)) { | ||
| return response, fmt.Errorf("unsubscribe url is located on an invalid domain") | ||
|
Comment on lines
+172
to
+177
|
||
| } | ||
|
|
||
| resp, err := http.Get(payload.UnsubscribeURL) | ||
| if err != nil { | ||
| return response, err | ||
|
|
||
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.
Domain validation is using
subscribeURL.Host, which includes the port (and preserves casing). This can incorrectly reject valid URLs likesns.<region>.amazonaws.com:443, and it will also reject mixed-case hosts even though DNS is case-insensitive. Consider validatingstrings.ToLower(subscribeURL.Hostname())and usinghostPattern.MatchString(...)to avoid the extra[]byteallocation.