mirror of
				https://github.com/strapi/strapi.git
				synced 2025-11-04 03:43:34 +00:00 
			
		
		
		
	- set security defaults for development mode that are standard - refactor error messages to work without ctx.request.admin - remove mask middleware and add a sanitization layer to the core-api to hide private fileds
		
			
				
	
	
		
			32 lines
		
	
	
		
			642 B
		
	
	
	
		
			JavaScript
		
	
	
	
	
	
			
		
		
	
	
			32 lines
		
	
	
		
			642 B
		
	
	
	
		
			JavaScript
		
	
	
	
	
	
const lazyRateLimit = {
 | 
						|
  get RateLimit() {
 | 
						|
    return require('koa2-ratelimit').RateLimit;
 | 
						|
  },
 | 
						|
};
 | 
						|
 | 
						|
module.exports = async (ctx, next) => {
 | 
						|
  const message = [
 | 
						|
    {
 | 
						|
      messages: [
 | 
						|
        {
 | 
						|
          id: 'Auth.form.error.ratelimit',
 | 
						|
          message: 'Too many attempts, please try again in a minute.',
 | 
						|
        },
 | 
						|
      ],
 | 
						|
    },
 | 
						|
  ];
 | 
						|
 | 
						|
  return lazyRateLimit.RateLimit.middleware(
 | 
						|
    Object.assign(
 | 
						|
      {},
 | 
						|
      {
 | 
						|
        interval: 1 * 60 * 1000,
 | 
						|
        max: 5,
 | 
						|
        prefixKey: `${ctx.request.url}:${ctx.request.ip}`,
 | 
						|
        message,
 | 
						|
      },
 | 
						|
      strapi.plugins['users-permissions'].config.ratelimit
 | 
						|
    )
 | 
						|
  )(ctx, next);
 | 
						|
};
 |