Skip to content

Commit f5a4cba

Browse files
authored
fix: hostname can be empty with redirect urls (#2241)
Oops. In in-app URLs like `com.app://` hostname is empty, but the regex expects at least one char.
1 parent cc640b2 commit f5a4cba

File tree

2 files changed

+11
-1
lines changed

2 files changed

+11
-1
lines changed

internal/api/verify_test.go

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -671,6 +671,13 @@ func (ts *VerifyTestSuite) TestVerifySignupWithRedirectURLContainedPath() {
671671
requestredirectURL: "http://japanese。.example.com/abc",
672672
expectedredirectURL: "http://localhost:3000",
673673
},
674+
{
675+
desc: "redirect with allowed deep-link url correctly without a hostname",
676+
siteURL: "http://localhost:3000",
677+
uriAllowList: []string{"com.myapp://**"},
678+
requestredirectURL: "com.myapp://",
679+
expectedredirectURL: "com.myapp:",
680+
},
674681
}
675682

676683
for _, tC := range testCases {

internal/utilities/request.go

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -101,12 +101,15 @@ func IsRedirectURLValid(config *conf.GlobalConfiguration, redirectURL string) bo
101101
return false
102102
}
103103

104+
scheme := strings.ToLower(refurl.Scheme)
105+
isHTTP := scheme == "http:" || scheme == "https:"
106+
104107
if decimalIPAddressPattern.MatchString(refurl.Hostname()) {
105108
// IP address in decimal form also not allowed in redirects!
106109
return false
107110
} else if ip := net.ParseIP(refurl.Hostname()); ip != nil {
108111
return ip.IsLoopback()
109-
} else if !regularHostname.MatchString(refurl.Hostname()) {
112+
} else if isHTTP && !regularHostname.MatchString(refurl.Hostname()) {
110113
// hostname uses characters that are not typically used
111114
return false
112115
}

0 commit comments

Comments
 (0)