Skip to content

Commit 7309d1e

Browse files
authored
Fix MSC2966 compliance around redirect_uri validity (#4529)
2 parents 82aa950 + ba986d3 commit 7309d1e

File tree

2 files changed

+17
-5
lines changed

2 files changed

+17
-5
lines changed

policies/client_registration/client_registration.rego

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ allow if {
1313

1414
parse_uri(url) := obj if {
1515
is_string(url)
16-
url_regex := `^(?P<scheme>[a-z][a-z0-9+.-]*):(?://(?P<host>((?:(?:[a-z0-9]|[a-z0-9][a-z0-9-]*[a-z0-9])\.)*(?:[a-z0-9]|[a-z0-9][a-z0-9-]*[a-z0-9])|127.0.0.1|0.0.0.0|\[::1\])(?::(?P<port>[0-9]+))?))?(?P<path>/[A-Za-z0-9/.-]*)$`
16+
url_regex := `^(?P<scheme>[a-z][a-z0-9+.-]*):(?://(?P<host>((?:(?:[a-z0-9]|[a-z0-9][a-z0-9-]*[a-z0-9])\.)*(?:[a-z0-9]|[a-z0-9][a-z0-9-]*[a-z0-9])|127.0.0.1|0.0.0.0|\[::1\])(?::(?P<port>[0-9]+))?))?(?P<path>/[A-Za-z0-9/.-]*)?(?P<query>\?[A-Za-z0-9/.-=]*)?$`
1717
[matches] := regex.find_all_string_submatch_n(url_regex, url, 1)
1818
obj := {"scheme": matches[1], "authority": matches[2], "host": matches[3], "port": matches[4], "path": matches[5]}
1919
}
@@ -31,9 +31,6 @@ secure_url(x) if {
3131
url.host != "127.0.0.1"
3232
url.host != "0.0.0.0"
3333
url.host != "[::1]"
34-
35-
# Must be standard port for HTTPS
36-
url.port == ""
3734
}
3835

3936
host_matches_client_uri(_) if {

policies/client_registration/client_registration_test.rego

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -212,7 +212,14 @@ test_web_redirect_uri if {
212212
client_registration.allow with input.client_metadata as {
213213
"application_type": "web",
214214
"client_uri": "https://example.com/",
215-
"redirect_uris": ["https://example.com/second/callback", "https://example.com/callback"],
215+
"redirect_uris": ["https://example.com/second/callback", "https://example.com/callback", "https://example.com/callback?query=value"],
216+
}
217+
218+
# HTTPS redirect_uri with non-standard port
219+
client_registration.allow with input.client_metadata as {
220+
"application_type": "web",
221+
"client_uri": "https://example.com/",
222+
"redirect_uris": ["https://example.com:8443/callback"],
216223
}
217224
}
218225

@@ -289,6 +296,14 @@ test_web_redirect_uri_localhost_not_allowed if {
289296
}
290297
}
291298

299+
test_web_redirect_uri_with_query if {
300+
client_registration.allow with input.client_metadata as {
301+
"application_type": "web",
302+
"client_uri": "https://example.com/",
303+
"redirect_uris": ["https://example.com/callback?query=value", "https://example.com?query=value"],
304+
}
305+
}
306+
292307
test_native_redirect_uri_allowed if {
293308
# This has all the redirect URIs types we're supporting for native apps
294309
client_registration.allow with input.client_metadata as {

0 commit comments

Comments
 (0)