Skip to content

Commit

Permalink
API: check secret _before_ handling the request (#231)
Browse files Browse the repository at this point in the history
* API: check secret _before_ handling the request

* keep async-await in secret check
  • Loading branch information
amitport authored and nicolodavis committed Jul 3, 2018
1 parent 2959acd commit 5090429
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions src/server/api.js
Original file line number Diff line number Diff line change
Expand Up @@ -128,14 +128,14 @@ export const createApiServer = ({ db, games }) => {
// If API_SECRET is set, then require that requests set an
// api-secret header that is set to the same value.
app.use(async (ctx, next) => {
await next();

if (
!!process.env.API_SECRET &&
ctx.request.headers['api-secret'] !== process.env.API_SECRET
) {
ctx.throw(403, 'Invalid API secret');
}

await next();
});

app.use(router.routes()).use(router.allowedMethods());
Expand Down

0 comments on commit 5090429

Please sign in to comment.