Skip to content

Commit d8fa8f7

Browse files
authored
Fix client_registration URI regex not accepting full query string grammar (#4563)
2 parents d7d8879 + 6ecc150 commit d8fa8f7

File tree

2 files changed

+19
-2
lines changed

2 files changed

+19
-2
lines changed

policies/client_registration/client_registration.rego

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,9 @@ 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/.-]*)?(?P<query>\?[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)
18-
obj := {"scheme": matches[1], "authority": matches[2], "host": matches[3], "port": matches[4], "path": matches[5]}
18+
obj := {"scheme": matches[1], "authority": matches[2], "host": matches[3], "port": matches[4], "path": matches[5], "query": matches[6]}
1919
}
2020

2121
secure_url(_) if {

policies/client_registration/client_registration_test.rego

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -215,6 +215,13 @@ test_web_redirect_uri if {
215215
"redirect_uris": ["https://example.com/second/callback", "https://example.com/callback", "https://example.com/callback?query=value"],
216216
}
217217

218+
client_registration.allow with input.client_metadata as {
219+
"application_type": "web",
220+
"client_uri": "http://localhost:8080",
221+
"redirect_uris": ["http://localhost:8080/?no_universal_links=true"],
222+
}
223+
with client_registration.allow_insecure_uris as true
224+
218225
# HTTPS redirect_uri with non-standard port
219226
client_registration.allow with input.client_metadata as {
220227
"application_type": "web",
@@ -403,3 +410,13 @@ test_reverse_dns_match if {
403410
not client_registration.reverse_dns_match("example.com", "org.example")
404411
not client_registration.reverse_dns_match("test.com", "com.example")
405412
}
413+
414+
test_parse_uri if {
415+
client_uri_query := client_registration.parse_uri("https://example.com:8080/users?query=test")
416+
client_uri_query.authority == "example.com:8080"
417+
client_uri_query.host == "example.com"
418+
client_uri_query.path == "/users"
419+
client_uri_query.scheme == "https"
420+
client_uri_query.port == "8080"
421+
client_uri_query.query == "?query=test"
422+
}

0 commit comments

Comments
 (0)