Skip to content

Verify SNS host for both Subscribe() and Unsubscribe()#3763

Open
mnafees wants to merge 1 commit intomainfrom
nafees/sns-host-pattern
Open

Verify SNS host for both Subscribe() and Unsubscribe()#3763
mnafees wants to merge 1 commit intomainfrom
nafees/sns-host-pattern

Conversation

@mnafees
Copy link
Copy Markdown
Member

@mnafees mnafees commented Apr 28, 2026

Description

Make sure we verify SNS payloads' subscribe and unsubscribe URLs.

Type of change

  • Bug fix (non-breaking change which fixes an issue)

@mnafees mnafees requested a review from grutt April 28, 2026 15:02
@mnafees mnafees self-assigned this Apr 28, 2026
Copilot AI review requested due to automatic review settings April 28, 2026 15:02
@vercel
Copy link
Copy Markdown

vercel Bot commented Apr 28, 2026

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
hatchet-docs Ready Ready Preview, Comment Apr 28, 2026 3:03pm

Request Review

Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR hardens the SNS ingestor helper by validating that both SubscribeURL and UnsubscribeURL are HTTPS and on an expected SNS host before issuing confirmation requests.

Changes:

  • Added URL parsing + scheme checks for SubscribeURL confirmation.
  • Added URL parsing + scheme checks for UnsubscribeURL confirmation (including empty-string guard).
  • Added host allowlist validation via hostPattern for both flows.

Comment on lines +133 to +138
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")
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.
Comment on lines +172 to +177
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")
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.
Comment on lines +163 to +165
if payload.UnsubscribeURL == "" {
return response, errors.New("payload does not have an UnsubscribeURL")
}
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.
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.

2 participants