@@ -12,7 +12,7 @@ import {
12
12
OpenIdProviderDiscoveryMetadataSchema
13
13
} from "../shared/auth.js" ;
14
14
import { OAuthClientInformationFullSchema , OAuthMetadataSchema , OAuthProtectedResourceMetadataSchema , OAuthTokensSchema } from "../shared/auth.js" ;
15
- import { checkResourceAllowed , resourceUrlFromServerUrl } from "../shared/auth-utils.js" ;
15
+ import { checkResourceAllowed , resourceUrlFromServerUrl , isValidOAuthScheme } from "../shared/auth-utils.js" ;
16
16
import {
17
17
InvalidClientError ,
18
18
InvalidGrantError ,
@@ -820,6 +820,9 @@ export async function startAuthorization(
820
820
let authorizationUrl : URL ;
821
821
if ( metadata ) {
822
822
authorizationUrl = new URL ( metadata . authorization_endpoint ) ;
823
+ if ( ! isValidOAuthScheme ( authorizationUrl ) ) {
824
+ throw new Error ( `Invalid authorization_endpoint URL scheme: ${ authorizationUrl . protocol } . Only http: and https: are allowed.` ) ;
825
+ }
823
826
824
827
if ( ! metadata . response_types_supported . includes ( responseType ) ) {
825
828
throw new Error (
@@ -911,9 +914,15 @@ export async function exchangeAuthorization(
911
914
) : Promise < OAuthTokens > {
912
915
const grantType = "authorization_code" ;
913
916
914
- const tokenUrl = metadata ?. token_endpoint
915
- ? new URL ( metadata . token_endpoint )
916
- : new URL ( "/token" , authorizationServerUrl ) ;
917
+ let tokenUrl : URL ;
918
+ if ( metadata ?. token_endpoint ) {
919
+ tokenUrl = new URL ( metadata . token_endpoint ) ;
920
+ if ( ! isValidOAuthScheme ( tokenUrl ) ) {
921
+ throw new Error ( `Invalid token_endpoint URL scheme: ${ tokenUrl . protocol } . Only http: and https: are allowed.` ) ;
922
+ }
923
+ } else {
924
+ tokenUrl = new URL ( "/token" , authorizationServerUrl ) ;
925
+ }
917
926
918
927
if (
919
928
metadata ?. grant_types_supported &&
@@ -998,6 +1007,9 @@ export async function refreshAuthorization(
998
1007
let tokenUrl : URL ;
999
1008
if ( metadata ) {
1000
1009
tokenUrl = new URL ( metadata . token_endpoint ) ;
1010
+ if ( ! isValidOAuthScheme ( tokenUrl ) ) {
1011
+ throw new Error ( `Invalid token_endpoint URL scheme: ${ tokenUrl . protocol } . Only http: and https: are allowed.` ) ;
1012
+ }
1001
1013
1002
1014
if (
1003
1015
metadata . grant_types_supported &&
@@ -1069,6 +1081,9 @@ export async function registerClient(
1069
1081
}
1070
1082
1071
1083
registrationUrl = new URL ( metadata . registration_endpoint ) ;
1084
+ if ( ! isValidOAuthScheme ( registrationUrl ) ) {
1085
+ throw new Error ( `Invalid registration_endpoint URL scheme: ${ registrationUrl . protocol } . Only http: and https: are allowed.` ) ;
1086
+ }
1072
1087
} else {
1073
1088
registrationUrl = new URL ( "/register" , authorizationServerUrl ) ;
1074
1089
}
0 commit comments