Skip to content
Open
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
30 changes: 30 additions & 0 deletions internal/integrations/ingestors/sns/sns.go
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Comment on lines +133 to +138
Copy link

Copilot AI Apr 28, 2026

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 like sns.<region>.amazonaws.com:443, and it will also reject mixed-case hosts even though DNS is case-insensitive. Consider validating strings.ToLower(subscribeURL.Hostname()) and using hostPattern.MatchString(...) to avoid the extra []byte allocation.

Copilot uses AI. Check for mistakes.
}

resp, err := http.Get(payload.SubscribeURL)
if err != nil {
return response, err
Expand All @@ -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
Copy link

Copilot AI Apr 28, 2026

Choose a reason for hiding this comment

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

New error string casing/punctuation is inconsistent with the existing errors in this file (e.g., Subscribe() uses Payload...!). Go conventions also recommend lowercase error messages without punctuation. Consider normalizing the error messages for Subscribe/Unsubscribe (and ideally the existing ones too) to a single style, and include context like "unsubscribe URL" in the https/domain validation errors to make debugging easier.

Copilot uses AI. Check for mistakes.

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
Copy link

Copilot AI Apr 28, 2026

Choose a reason for hiding this comment

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

Same as Subscribe(): validation uses unsubscribeURL.Host which includes the port and may preserve mixed-case hostnames. Prefer validating strings.ToLower(unsubscribeURL.Hostname()) and hostPattern.MatchString(...) so the check is resilient to :443 and avoids extra allocation.

Copilot uses AI. Check for mistakes.
}

resp, err := http.Get(payload.UnsubscribeURL)
if err != nil {
return response, err
Expand Down
Loading