Skip to content

api: reject invalid destination URLs at the API boundary#2

Open
ademboukabes wants to merge 1 commit into
edaywalid:mainfrom
ademboukabes:fix/destination-url-validation
Open

api: reject invalid destination URLs at the API boundary#2
ademboukabes wants to merge 1 commit into
edaywalid:mainfrom
ademboukabes:fix/destination-url-validation

Conversation

@ademboukabes

Copy link
Copy Markdown

Problem

Currently, destinations with malformed or unsupported URLs (e.g., missing scheme, ftp://, relative paths) are silently accepted and stored by the API. The error only manifests later in the delivery worker, which moves the event to the dead-letter queue. This results in a poor user experience as the user receives no immediate feedback that their destination URL is invalid.

Solution

This PR introduces a validateURL helper that validates the destination URL synchronously at the API boundary.

  • The URL scheme is now strictly enforced to be either http or https.
  • The URL must have a non-empty host.
  • Validation is applied to both POST /destinations and PATCH /destinations/{id} endpoints.

Verification

  • Added table-driven tests for URL validation covering valid and invalid cases (http, https, relative paths, missing scheme, ftp://, empty hosts).
  • go vet and go test -race ./... pass successfully.

Destinations with a non-http/https scheme or a missing host were silently
accepted and only failed later in the delivery worker, moving the event to
dead-letter with no clear error for the user. validateURL now catches this
on POST and PATCH /destinations, and tests cover the main invalid cases.
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.

1 participant