Skip to content
Merged
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 change/@azure-msal-common-state-error-hardening.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"type": "patch",
"comment": "Omit raw state values from authorization response validation errors [#8955](https://github.com/AzureAD/microsoft-authentication-library-for-js/pull/8955)",
"packageName": "@azure/msal-common",
"dependentChangeType": "patch"
}
6 changes: 2 additions & 4 deletions lib/msal-common/src/protocol/Authorize.ts
Original file line number Diff line number Diff line change
Expand Up @@ -351,8 +351,7 @@ export function validateAuthorizationResponse(
} catch (e) {
throw createClientAuthError(
ClientAuthErrorCodes.invalidState,
correlationId,
serverResponse.state
correlationId
);
}

Expand All @@ -361,8 +360,7 @@ export function validateAuthorizationResponse(
} catch (e) {
throw createClientAuthError(
ClientAuthErrorCodes.invalidState,
correlationId,
serverResponse.state
correlationId
);
}

Expand Down
67 changes: 50 additions & 17 deletions lib/msal-common/test/protocol/Authorize.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1783,26 +1783,59 @@ describe("Authorize Protocol Tests", () => {
}
});

it("throws invalid state error", (done) => {
const testServerCodeResponse: AuthorizeResponse = {
code: "testCode",
client_info: TEST_DATA_CLIENT_INFO.TEST_RAW_CLIENT_INFO,
state: TEST_STATE_VALUES.URI_ENCODED_LIB_STATE,
};
const validState = `${TEST_STATE_VALUES.URI_ENCODED_LIB_STATE}|<span>untrusted-state</span>`;
const malformedState = `${validState}%zz`;

it.each([
{
name: "malformed response state",
response: { code: "testCode", state: malformedState },
cachedState: validState,
},
{
name: "malformed response state on an error response",
response: {
error: "access_denied",
error_description: "Request denied",
state: malformedState,
},
cachedState: validState,
},
{
name: "malformed cached state",
response: { code: "testCode", state: validState },
cachedState: malformedState,
},
{
name: "matching malformed response and cached states",
response: { code: "testCode", state: malformedState },
cachedState: malformedState,
},
])(
"throws invalid_state without reflecting state for $name",
({ response, cachedState }) => {
const expectedError = new ClientAuthError(
ClientAuthErrorCodes.invalidState,
RANDOM_TEST_GUID
);
const validateResponse = () =>
AuthorizeProtocol.validateAuthorizationResponse(
response,
cachedState,
RANDOM_TEST_GUID
);

try {
AuthorizeProtocol.validateAuthorizationResponse(
testServerCodeResponse,
"dummy-state-%20%%%30%%%%%40",
""
expect(validateResponse).toThrow(ClientAuthError);
expect(validateResponse).toThrow(
expect.objectContaining({
errorCode: ClientAuthErrorCodes.invalidState,
correlationId: RANDOM_TEST_GUID,
message: expectedError.message,
errorMessage: expectedError.errorMessage,
})
);
} catch (e) {
expect(e).toBeInstanceOf(ClientAuthError);
const err = e as ClientAuthError;
expect(err.errorCode).toBe(ClientAuthErrorCodes.invalidState);
done();
}
});
);

it("throws ServerError and parser error no", (done) => {
const testServerCodeResponse: AuthorizeResponse = {
Expand Down
Loading