diff --git a/packages/strapi-admin/middlewares/auth/index.js b/packages/strapi-admin/middlewares/auth/index.js index 3bad65e5..f235a515 100644 --- a/packages/strapi-admin/middlewares/auth/index.js +++ b/packages/strapi-admin/middlewares/auth/index.js @@ -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'