Skip to content

Commit

Permalink
fix: fix authHeader without cookie-parser middleware (#1003)
Browse files Browse the repository at this point in the history
[express-openapi-validator v5.8.3][1] and
00d070b (fix: add cookie support for HTTP bearer authentication (#949), 2024-10-27)
breaks HTTP bearer authentication when the `cookie-parser` middleware
is not present (and therefore `req.cookies` is not present).

[1]: https://github.com/cdimascio/express-openapi-validator/releases/tag/v5.3.8
Fixes: 00d070b
  • Loading branch information
aloisklink authored Oct 30, 2024
1 parent f2aba32 commit 17e91d5
Showing 1 changed file with 3 additions and 2 deletions.
5 changes: 3 additions & 2 deletions src/middlewares/openapi.security.ts
Original file line number Diff line number Diff line change
Expand Up @@ -232,8 +232,9 @@ class AuthValidator {
const authHeader =
req.headers['authorization'] &&
req.headers['authorization'].toLowerCase();
// req.cookies will be `undefined` without `cookie-parser` middleware
const authCookie =
req.cookies[scheme.name] || req.signedCookies?.[scheme.name];
req.cookies?.[scheme.name] || req.signedCookies?.[scheme.name];

const type = scheme.scheme && scheme.scheme.toLowerCase();
if (type === 'bearer') {
Expand Down Expand Up @@ -289,4 +290,4 @@ class Util {
o.constructor === Object
);
}
}
}

0 comments on commit 17e91d5

Please sign in to comment.