Skip to content

Issue #1213 fix (RFC 9207) #1327

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions projects/lib/src/auth.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -279,6 +279,12 @@ export class AuthConfig {
*/
public checkOrigin? = false;

/**
* Defines whether the authorization server provides the iss parameter in the authorization response.
* Set to false if you don't fetch metadata and want to skip iss parameter validation.
*/
public authorizationResponseIssParameterSupported? = true;

constructor(json?: Partial<AuthConfig>) {
if (json) {
Object.assign(this, json);
Expand Down
37 changes: 36 additions & 1 deletion projects/lib/src/oauth-service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -565,6 +565,8 @@ export class OAuthService extends AuthConfig implements OnDestroy {
this.jwksUri = doc.jwks_uri;
this.sessionCheckIFrameUrl =
doc.check_session_iframe || this.sessionCheckIFrameUrl;
this.authorizationResponseIssParameterSupported =
doc.authorization_response_iss_parameter_supported || false;

this.discoveryDocumentLoaded = true;
this.discoveryDocumentLoadedSubject.next(doc);
Expand Down Expand Up @@ -1743,6 +1745,7 @@ export class OAuthService extends AuthConfig implements OnDestroy {

const code = parts['code'];
const state = parts['state'];
const iss = parts['iss'];

const sessionState = parts['session_state'];

Expand All @@ -1754,6 +1757,7 @@ export class OAuthService extends AuthConfig implements OnDestroy {
.replace(/code=[^&\$]*/, '')
.replace(/scope=[^&\$]*/, '')
.replace(/state=[^&\$]*/, '')
.replace(/iss=[^&\$]*/, '')
.replace(/session_state=[^&\$]*/, '')
.replace(/^\?&/, '?')
.replace(/&$/, '')
Expand All @@ -1766,6 +1770,21 @@ export class OAuthService extends AuthConfig implements OnDestroy {
history.replaceState(null, window.name, href);
}

// if Authorization Response or Error Response
if ((code || parts['error']) && !this.skipIssuerCheck) {
if (
(this.authorizationResponseIssParameterSupported &&
iss !== this.issuer) ||
(!this.authorizationResponseIssParameterSupported && iss)
) {
const err = 'Wrong issuer: ' + iss;
this.logger.warn(err);
const event = new OAuthErrorEvent('code_error', {}, parts);
this.eventsSubject.next(event);
return Promise.reject(err);
}
}

let [nonceInState, userState] = this.parseState(state);
this.state = userState;

Expand Down Expand Up @@ -1987,6 +2006,23 @@ export class OAuthService extends AuthConfig implements OnDestroy {
this.debug('parsed url', parts);

const state = parts['state'];
const accessToken = parts['access_token'];
const iss = parts['iss'];

// if Access Token Response or Error Response
if ((accessToken || parts['error']) && !this.skipIssuerCheck) {
if (
(this.authorizationResponseIssParameterSupported &&
iss !== this.issuer) ||
(!this.authorizationResponseIssParameterSupported && iss)
) {
const err = 'Wrong issuer: ' + iss;
this.logger.warn(err);
const event = new OAuthErrorEvent('token_error', {}, parts);
this.eventsSubject.next(event);
return Promise.reject(err);
}
}

let [nonceInState, userState] = this.parseState(state);
this.state = userState;
Expand All @@ -1999,7 +2035,6 @@ export class OAuthService extends AuthConfig implements OnDestroy {
return Promise.reject(err);
}

const accessToken = parts['access_token'];
const idToken = parts['id_token'];
const sessionState = parts['session_state'];
const grantedScopes = parts['scope'];
Expand Down
1 change: 1 addition & 0 deletions projects/lib/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -197,4 +197,5 @@ export interface OidcDiscoveryDoc {
service_documentation: string;
ui_locales_supported: string[];
revocation_endpoint: string;
authorization_response_iss_parameter_supported: boolean;
}