Skip to content

Commit

Permalink
Merge pull request #2988 from bcgov/auth-crash-fix
Browse files Browse the repository at this point in the history
Auth crash fix
  • Loading branch information
micheal-w-wells authored Nov 27, 2023
2 parents 87253c6 + e83ad5c commit ce9f8eb
Showing 1 changed file with 13 additions and 1 deletion.
14 changes: 13 additions & 1 deletion api/src/utils/auth-utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,19 @@ export const authenticate = async (req: InvasivesRequest) => {

MDC.additionalContext.isPublicURL = isPublicURL;

const token = authHeader.split(/\s/)[1];
let token: string;

try {
token = authHeader.split(/\s/)[1];
} catch (error) {
defaultLog.info({ label: 'authenticate', message: 'malformed auth token received' });

throw {
code: 400,
message: 'Authorization header parse failure',
namespace: 'auth-utils'
};
}

if (isPublicURL && (req.method === 'GET' || req.method === 'POST') && !token) {
return new Promise<void>((resolve: any) => {
Expand Down

0 comments on commit ce9f8eb

Please sign in to comment.