Skip to content

Commit

Permalink
asd
Browse files Browse the repository at this point in the history
  • Loading branch information
dbarrosop committed Feb 9, 2024
1 parent 9618af0 commit c99d24b
Showing 1 changed file with 5 additions and 10 deletions.
15 changes: 5 additions & 10 deletions src/middleware/auth.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,24 +30,19 @@ export const authenticationGate = (
return sendError(res, 'unauthenticated-user');
}

const auth = req.auth as RequestAuth;
if (await failsElevatedCheck(auth, bypassIfNoKeys)) {
if (checkElevatedPermissions) {
const auth = req.auth as RequestAuth;
if (await failsElevatedCheck(auth, bypassIfNoKeys)) {
return sendError(res, 'elevated-claim-required');
}
}

return next();
};
}

export const failsElevatedCheck = async (auth: RequestAuth, bypassIfNoKeys = false) => {
if (!checkElevatedPermissions ||
ENV.AUTH_REQUIRE_ELEVATED_CLAIM === 'disabled' ||
!ENV.AUTH_WEBAUTHN_ENABLED
) {
return false;
}

if (auth.elevated) {
if (ENV.AUTH_REQUIRE_ELEVATED_CLAIM === 'disabled' || !ENV.AUTH_WEBAUTHN_ENABLED || auth.elevated) {
return false;
}

Expand Down

0 comments on commit c99d24b

Please sign in to comment.