Skip to content

Commit

Permalink
feat: network based access check support for admin api(s)
Browse files Browse the repository at this point in the history
added STRAPI_ADMIN_ENABLE_NETWORK_CHECK and STRAPI_ADMIN_ALLOWED_IP_LIST env vars.
  • Loading branch information
imaksp committed May 28, 2024
1 parent 6aed026 commit 3ca3cb3
Showing 1 changed file with 12 additions and 0 deletions.
12 changes: 12 additions & 0 deletions packages/strapi-admin/middlewares/auth/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,18 @@ module.exports = (strapi) => ({
strapi.app.use(passportMiddleware);

strapi.app.use(async (ctx, next) => {
if (
process.env.STRAPI_ADMIN_ENABLE_NETWORK_CHECK === 'true' &&
process.env.STRAPI_ADMIN_ALLOWED_IP_LIST
) {
const allowedList = process.env.STRAPI_ADMIN_ALLOWED_IP_LIST.split(',').map((item) =>
item.trim()
);
if (!allowedList.includes(ctx.request.ip)) {
return ctx.forbidden('Invalid network');
}
}

if (
ctx.request.header.authorization &&
ctx.request.header.authorization.split(' ')[0] === 'Bearer'
Expand Down

0 comments on commit 3ca3cb3

Please sign in to comment.