Skip to content

Commit

Permalink
ATO-1291: Add max_age support to query params
Browse files Browse the repository at this point in the history
We added it for request object so we need to have the
equivalent validation for query params
  • Loading branch information
Ryan-Andrews99 committed Jan 13, 2025
1 parent ffa42af commit 52eea6a
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 1 deletion.
22 changes: 21 additions & 1 deletion src/validators/tests/validate-auth-request-query-params.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ const defaultAuthRequest = {
nonce: "987654321",
scope: ["openid"],
claims: [validClaim],
vtr: [],
vtr: '["Cl.Cm"]',
prompt: [],
ui_locales: [],
max_age: 123,
Expand Down Expand Up @@ -185,4 +185,24 @@ describe("validateAuthRequestQueryParams tests", () => {
})
);
});

it("throws an invalid request error for max_age less than -1", () => {
expect(() =>
validateAuthRequestQueryParams(
{
...defaultAuthRequest,
max_age: -100,
},
config
)
).toThrow(
new AuthoriseRequestError({
errorCode: "invalid_request",
errorDescription: "Max age is negative in query params",
httpStatusCode: 302,
redirectUri: defaultAuthRequest.redirect_uri,
state: defaultAuthRequest.state,
})
);
});
});
11 changes: 11 additions & 0 deletions src/validators/validate-auth-request-query-params.ts
Original file line number Diff line number Diff line change
Expand Up @@ -95,4 +95,15 @@ export const validateAuthRequestQueryParams = (
queryParams.state,
queryParams.redirect_uri
);

if (queryParams.max_age && queryParams.max_age < -1) {
logger.error("Negative max_age in authorise request");
throw new AuthoriseRequestError({
errorCode: "invalid_request",
errorDescription: "Max age is negative in query params",
httpStatusCode: 302,
redirectUri: queryParams.redirect_uri,
state: queryParams.state,
});
}
};

0 comments on commit 52eea6a

Please sign in to comment.