Skip to content

Commit

Permalink
Reorder upload and security middlewares (#1)
Browse files Browse the repository at this point in the history
- Move multipart middleware after security middleware so that security
  handlers can abort request pipeline before uploads are processed.

Fixes cdimascio#865

Co-authored-by: Matt Mower <[email protected]>
  • Loading branch information
mdmower-csnw and mdmower authored Oct 20, 2023
1 parent bb8d6b8 commit fecc989
Showing 1 changed file with 13 additions and 13 deletions.
26 changes: 13 additions & 13 deletions src/openapi.validator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -149,19 +149,6 @@ export class OpenApiValidator {
.catch(next);
});

if (this.options.fileUploader) {
// multipart middleware
let fumw;
middlewares.push(function multipartMiddleware(req, res, next) {
return pContext
.then(({ context: { apiDoc } }) => {
fumw = fumw || self.multipartMiddleware(apiDoc);
return fumw(req, res, next);
})
.catch(next);
});
}

// security middlware
let scmw;
middlewares.push(function securityMiddleware(req, res, next) {
Expand All @@ -178,6 +165,19 @@ export class OpenApiValidator {
.catch(next);
});

if (this.options.fileUploader) {
// multipart middleware
let fumw;
middlewares.push(function multipartMiddleware(req, res, next) {
return pContext
.then(({ context: { apiDoc } }) => {
fumw = fumw || self.multipartMiddleware(apiDoc);
return fumw(req, res, next);
})
.catch(next);
});
}

// request middlweare
if (this.options.validateRequests) {
let reqmw;
Expand Down

0 comments on commit fecc989

Please sign in to comment.