@@ -159,18 +159,24 @@ func GetProtectedResourceMetadataFromHeader(ctx context.Context, header http.Hea
159159
160160// getPRM makes a GET request to the given URL, and validates the response.
161161// As part of the validation, it compares the returned resource field to wantResource.
162- func getPRM (ctx context.Context , url string , c * http.Client , wantResource string ) (* ProtectedResourceMetadata , error ) {
163- if ! strings .HasPrefix (strings .ToUpper (url ), "HTTPS://" ) {
164- return nil , fmt .Errorf ("resource URL %q does not use HTTPS" , url )
162+ func getPRM (ctx context.Context , purl string , c * http.Client , wantResource string ) (* ProtectedResourceMetadata , error ) {
163+ if ! strings .HasPrefix (strings .ToUpper (purl ), "HTTPS://" ) {
164+ return nil , fmt .Errorf ("resource URL %q does not use HTTPS" , purl )
165165 }
166- prm , err := getJSON [ProtectedResourceMetadata ](ctx , c , url , 1 << 20 )
166+ prm , err := getJSON [ProtectedResourceMetadata ](ctx , c , purl , 1 << 20 )
167167 if err != nil {
168168 return nil , err
169169 }
170170 // Validate the Resource field to thwart impersonation attacks (section 3.3).
171171 if prm .Resource != wantResource {
172172 return nil , fmt .Errorf ("got metadata resource %q, want %q" , prm .Resource , wantResource )
173173 }
174+ // Validate the authorization server URLs to prevent XSS attacks (see #526).
175+ for _ , u := range prm .AuthorizationServers {
176+ if err := checkURLScheme (u ); err != nil {
177+ return nil , err
178+ }
179+ }
174180 return prm , nil
175181}
176182
0 commit comments