@@ -17,6 +17,11 @@ parse_uri(url) = obj {
1717 obj := {" scheme" : matches[1 ], " authority" : matches[2 ], " host" : matches[3 ], " port" : matches[4 ], " path" : matches[5 ]}
1818}
1919
20+ secure_url (x) {
21+ x
22+ data.client_registration.allow_insecure_uris
23+ }
24+
2025secure_url (x) {
2126 url := parse_uri (x)
2227 url.scheme == " https"
@@ -31,6 +36,21 @@ secure_url(x) {
3136 url.port == " "
3237}
3338
39+ host_matches_client_uri (x) {
40+ x
41+
42+ # Do not check we allow host mismatch
43+ data.client_registration.allow_host_mismatch
44+ }
45+
46+ host_matches_client_uri (x) {
47+ x
48+
49+ # Do not check if the client_uri is missing and we allow that
50+ data.client_registration.allow_missing_client_uri
51+ not data.client_metadata.client_uri
52+ }
53+
3454host_matches_client_uri (x) {
3555 client_uri := parse_uri (input.client_metadata.client_uri)
3656 uri := parse_uri (x)
@@ -43,43 +63,36 @@ violation[{"msg": "missing client_uri"}] {
4363}
4464
4565violation[{" msg" : " invalid client_uri" }] {
46- not data.client_registration.allow_insecure_uris
4766 not secure_url (input.client_metadata.client_uri)
4867}
4968
5069violation[{" msg" : " invalid tos_uri" }] {
5170 input.client_metadata.tos_uri
52- not data.client_registration.allow_insecure_uris
5371 not secure_url (input.client_metadata.tos_uri)
5472}
5573
5674violation[{" msg" : " tos_uri not on the same host as the client_uri" }] {
5775 input.client_metadata.tos_uri
58- not data.client_registration.allow_host_mismatch
5976 not host_matches_client_uri (input.client_metadata.tos_uri)
6077}
6178
6279violation[{" msg" : " invalid policy_uri" }] {
6380 input.client_metadata.policy_uri
64- not data.client_registration.allow_insecure_uris
6581 not secure_url (input.client_metadata.policy_uri)
6682}
6783
6884violation[{" msg" : " policy_uri not on the same host as the client_uri" }] {
6985 input.client_metadata.policy_uri
70- not data.client_registration.allow_host_mismatch
7186 not host_matches_client_uri (input.client_metadata.policy_uri)
7287}
7388
7489violation[{" msg" : " invalid logo_uri" }] {
7590 input.client_metadata.logo_uri
76- not data.client_registration.allow_insecure_uris
7791 not secure_url (input.client_metadata.logo_uri)
7892}
7993
8094violation[{" msg" : " logo_uri not on the same host as the client_uri" }] {
8195 input.client_metadata.logo_uri
82- not data.client_registration.allow_host_mismatch
8396 not host_matches_client_uri (input.client_metadata.logo_uri)
8497}
8598
@@ -108,22 +121,6 @@ violation[{"msg": "empty redirect_uris"}] {
108121 count (input.client_metadata.redirect_uris) == 0
109122}
110123
111- violation[{" msg" : " invalid redirect_uri" , " redirect_uri" : redirect_uri}] {
112- # For 'web' apps, we should verify that redirect_uris are secure
113- input.client_metadata.application_type != " native"
114- some redirect_uri in input.client_metadata.redirect_uris
115- not data.client_registration.allow_host_mismatch
116- not host_matches_client_uri (redirect_uri)
117- }
118-
119- violation[{" msg" : " invalid redirect_uri" }] {
120- # For 'web' apps, we should verify that redirect_uris are secure
121- input.client_metadata.application_type != " native"
122- some redirect_uri in input.client_metadata.redirect_uris
123- not data.client_registration.allow_insecure_uris
124- not secure_url (redirect_uri)
125- }
126-
127124# Used to verify that a reverse-dns formatted scheme is a strict subdomain of
128125# another host.
129126# This is used so a redirect_uri like 'com.example.app:/' works for
@@ -173,11 +170,17 @@ valid_native_redirector(x) {
173170 reverse_dns_match (client_uri.host, url.scheme)
174171}
175172
176- violation[{" msg" : " invalid redirect_uri" }] {
177- # For 'native' apps, we need to check that the redirect_uri is either
178- # a custom scheme, or localhost
179- # TODO: this might not be right, because of app-associated domains on mobile?
173+ valid_redirect_uri (uri) {
180174 input.client_metadata.application_type == " native"
175+ valid_native_redirector (uri)
176+ }
177+
178+ valid_redirect_uri (uri) {
179+ secure_url (uri)
180+ host_matches_client_uri (uri)
181+ }
182+
183+ violation[{" msg" : " invalid redirect_uri" , " redirect_uri" : redirect_uri}] {
181184 some redirect_uri in input.client_metadata.redirect_uris
182- not valid_native_redirector (redirect_uri)
185+ not valid_redirect_uri (redirect_uri)
183186}
0 commit comments