-
Notifications
You must be signed in to change notification settings - Fork 4.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add check for OIDC provider to permit a non-exact redirect URI from O…
…IDC client if it is the IPv4 or IPv6 loopback address.
- Loading branch information
paladin-devops
committed
Feb 2, 2022
1 parent
057c67f
commit 4a66798
Showing
3 changed files
with
54 additions
and
1 deletion.
There are no files selected for viewing
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
```release-note:bug | ||
oidc: Support dynamic port for loopback redirect URI | ||
``` |
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
package vault | ||
|
||
import ( | ||
"net/url" | ||
"regexp" | ||
"strings" | ||
) | ||
|
||
func isValidRedirectURI(uri string, validUris []string) bool { | ||
requestedUri, err := url.Parse(uri) | ||
if err != nil { | ||
return false | ||
} | ||
|
||
for _, validUri := range validUris { | ||
if strings.ToLower(validUri) == strings.ToLower(uri) || isLoopbackURI(requestedUri, validUri) { | ||
return true | ||
} | ||
} | ||
|
||
return false | ||
} | ||
|
||
func isLoopbackURI(requestUri *url.URL, validUri string) bool { | ||
registeredUri, err := url.Parse(validUri) | ||
if err != nil { | ||
return false | ||
} | ||
|
||
// Verifies that the valid URL is HTTP and is the loopback address before | ||
// proceeding, otherwise return false | ||
if registeredUri.Scheme != "http" || !isLoopbackAddress(registeredUri.Host) { | ||
return false | ||
} | ||
|
||
// Returns true if the path after the IP/port is the same | ||
// Request URL and valid URL have already been validated as loopback | ||
if requestUri.Scheme == "http" && isLoopbackAddress(requestUri.Host) && registeredUri.Path == requestUri.Path { | ||
return true | ||
} | ||
|
||
return false | ||
} | ||
|
||
// Returns true if the address hostname is the IPv4 or IPv6 loopback address and ignores port | ||
func isLoopbackAddress(address string) bool { | ||
match, _ := regexp.MatchString("^(127.0.0.1|\\[::1\\])(:?)(\\d*)$", address) | ||
return match | ||
} |