Skip to content

Commit 5090429

Browse files
amitportnicolodavis
authored andcommitted
API: check secret _before_ handling the request (#231)
* API: check secret _before_ handling the request * keep async-await in secret check
1 parent 2959acd commit 5090429

1 file changed

Lines changed: 2 additions & 2 deletions

File tree

src/server/api.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -128,14 +128,14 @@ export const createApiServer = ({ db, games }) => {
128128
// If API_SECRET is set, then require that requests set an
129129
// api-secret header that is set to the same value.
130130
app.use(async (ctx, next) => {
131-
await next();
132-
133131
if (
134132
!!process.env.API_SECRET &&
135133
ctx.request.headers['api-secret'] !== process.env.API_SECRET
136134
) {
137135
ctx.throw(403, 'Invalid API secret');
138136
}
137+
138+
await next();
139139
});
140140

141141
app.use(router.routes()).use(router.allowedMethods());

0 commit comments

Comments
 (0)