evil host redirect hanlding for pentest#9398
Open
NamanMahor wants to merge 2 commits into
Open
Conversation
begelundmuller
requested changes
May 26, 2026
Comment on lines
179
to
+195
| if redirect != "" { | ||
| if !a.admin.URLs.IsSafeRedirectURL(redirect, host) { | ||
| // The redirect is not on a primary/canonical host and not on the request host. | ||
| // The only legitimate case is the server-generated second call in the custom | ||
| // domain login flow (canonical domain, custom_domain_flow=true), where the | ||
| // redirect points to <custom-domain>/auth/custom-domain-callback. | ||
| if !customDomainFlow { | ||
| http.Error(w, "invalid redirect parameter", http.StatusBadRequest) | ||
| return | ||
| } | ||
| parsed, _ := url.Parse(redirect) | ||
| _, err := a.admin.DB.FindOrganizationByCustomDomain(r.Context(), parsed.Host) | ||
| if errors.Is(err, database.ErrNotFound) { | ||
| http.Error(w, "invalid redirect parameter", http.StatusBadRequest) | ||
| return | ||
| } else if err != nil { | ||
| http.Error(w, "internal server error", http.StatusInternalServerError) |
Contributor
There was a problem hiding this comment.
The diff and nested logic in this PR is getting quite hard to follow. Firstly, there's calls to FindOrganizationByCustomDomain in two different places. Secondly, I'm not quite following the value of additionalHost since for non-Rill hosts, I would expect the lookup for FindOrganizationByCustomDomain to be sufficient?
Can you perhaps pull all the safe redirect logic, including the custom domain lookup, into a single utility function in this package?
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
PLAT-473: Pentest: Remove open redirects in auth
Checklist: