validateAuthServerMetaURLs validates all URL fields in AuthServerMeta to ensure they don't use dangerous schemes that could enable XSS attacks. It also validates that URLs likely to be called by the client use HTTPS or are loopback addresses.
(asm *AuthServerMeta)
| 167 | // It also validates that URLs likely to be called by the client use |
| 168 | // HTTPS or are loopback addresses. |
| 169 | func validateAuthServerMetaURLs(asm *AuthServerMeta) error { |
| 170 | urls := []struct { |
| 171 | name string |
| 172 | value string |
| 173 | }{ |
| 174 | {"authorization_endpoint", asm.AuthorizationEndpoint}, |
| 175 | {"token_endpoint", asm.TokenEndpoint}, |
| 176 | {"jwks_uri", asm.JWKSURI}, |
| 177 | {"registration_endpoint", asm.RegistrationEndpoint}, |
| 178 | {"service_documentation", asm.ServiceDocumentation}, |
| 179 | {"op_policy_uri", asm.OpPolicyURI}, |
| 180 | {"op_tos_uri", asm.OpTOSURI}, |
| 181 | {"revocation_endpoint", asm.RevocationEndpoint}, |
| 182 | {"introspection_endpoint", asm.IntrospectionEndpoint}, |
| 183 | } |
| 184 | |
| 185 | for _, u := range urls { |
| 186 | if err := checkURLScheme(u.value); err != nil { |
| 187 | return fmt.Errorf("%s: %w", u.name, err) |
| 188 | } |
| 189 | } |
| 190 | |
| 191 | urls = []struct { |
| 192 | name string |
| 193 | value string |
| 194 | }{ |
| 195 | {"authorization_endpoint", asm.AuthorizationEndpoint}, |
| 196 | {"token_endpoint", asm.TokenEndpoint}, |
| 197 | {"registration_endpoint", asm.RegistrationEndpoint}, |
| 198 | {"introspection_endpoint", asm.IntrospectionEndpoint}, |
| 199 | } |
| 200 | |
| 201 | for _, u := range urls { |
| 202 | if err := checkHTTPSOrLoopback(u.value); err != nil { |
| 203 | return fmt.Errorf("%s: %w", u.name, err) |
| 204 | } |
| 205 | } |
| 206 | |
| 207 | return nil |
| 208 | } |
searching dependent graphs…