Skip to content

Commit 9e1b504

Browse files
authored
fix: fix authHeader without cookie-parser middleware
[express-openapi-validator v5.8.3][1] and 00d070b (fix: add cookie support for HTTP bearer authentication (cdimascio#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
1 parent f2aba32 commit 9e1b504

File tree

1 file changed

+3
-2
lines changed

1 file changed

+3
-2
lines changed

src/middlewares/openapi.security.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -232,8 +232,9 @@ class AuthValidator {
232232
const authHeader =
233233
req.headers['authorization'] &&
234234
req.headers['authorization'].toLowerCase();
235+
// req.cookies will be `undefined` without `cookie-parser` middleware
235236
const authCookie =
236-
req.cookies[scheme.name] || req.signedCookies?.[scheme.name];
237+
req.cookies?.[scheme.name] || req.signedCookies?.[scheme.name];
237238

238239
const type = scheme.scheme && scheme.scheme.toLowerCase();
239240
if (type === 'bearer') {
@@ -289,4 +290,4 @@ class Util {
289290
o.constructor === Object
290291
);
291292
}
292-
}
293+
}

0 commit comments

Comments
 (0)