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

Changed url validation #286

Merged
merged 1 commit into from
May 23, 2022
Merged

Conversation

tobias-kuendig
Copy link
Contributor

@tobias-kuendig tobias-kuendig commented May 20, 2022

Because of the base API url validation, it is currently not possible to use a url like http://localhost/my-proxy/v3.

My specific use case is to proxy the requests to the Mailgun api via a https://my-internal-server/mailgun/v3 base. I cannot access the Mailgun API directly in the network but I have access to my-internal-server.

Using https://my-internal-server/mailgun/v3, I get an error that reads BaseAPI must end with a /v2, /v3 or /v4, which it does in my example, but the regex to validate the url is ^/v[2-4].*, which checks if it starts with the version segment.

Alltough I think this check could be removed completely (a user will notice the wrong URL when the request is sent, like they would notice a wrong username/password) this PR proposes to change the regex to just /v[2-4].* so only the presence of a /v3 segment is validated, no matter where in the URL.

I guess it would be better to validate the URL somewhere where the actual apiBase field is available so we could actually validate if it ends in /v3 but I did not find a way to implement it without breaking the api. The httpRequest struct does not know about the apiBase but only sees the fully constructed url which makes the validation for a specific format harder.

Copy link
Contributor

@thrawn01 thrawn01 left a comment

Choose a reason for hiding this comment

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

thank you for making this change and explaining your use case!

@thrawn01 thrawn01 merged commit acda9bf into mailgun:master May 23, 2022
@tobias-kuendig tobias-kuendig deleted the move-url-validation branch May 24, 2022 05:38
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