Skip to content

Commit

Permalink
express: ensure the authorization header starts with Bearer
Browse files Browse the repository at this point in the history
It used to just skip the 7 first chars without verifying that said
chars were indeed `Bearer `
  • Loading branch information
divarvel committed May 16, 2023
1 parent f4ab91d commit a8dc0ae
Showing 1 changed file with 5 additions and 2 deletions.
7 changes: 5 additions & 2 deletions snippets/biscuit-express.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,15 @@ export function middleware(options) {
// assumes the token is in the `Authorization` header,
// prefixed with `Bearer `
const defaultExtractor = function (req) {
const authHeader = req.headers.authorization?.slice(7);
const authHeader = req.headers.authorization;
if (!authHeader) {
throw new Error("Missing Authorization header");
}
if (!authHeader.startsWith("Bearer ")) {
throw new Error("Authorization header does not carry a bearer token");
}

return authHeader;
return authHeader.slice(7);
};

const defaultParser = function (data, publicKey) {
Expand Down

0 comments on commit a8dc0ae

Please sign in to comment.