소스 검색

Fix rate limiting middleware

production
Jack Foltz 5 년 전
부모
커밋
5f2320a492
로그인 계정: foltik <jack@foltz.io> GPG 키 ID: D1F0331758D1F29A
3개의 변경된 파일6개의 추가작업 그리고 31개의 파일을 삭제
  1. +4
    -3
      app/routes/api/auth.js
  2. +0
    -26
      app/util/auth.js
  3. +2
    -2
      config/default.json

+ 4
- 3
app/routes/api/auth.js 파일 보기

@@ -98,11 +98,11 @@ router.post('/register',
res.status(200).json({'message': 'Registration successful.'});
}));

console.log(config.get('RateLimit'));
const loginLimiter = config.get('RateLimit.enable')
? rateLimit({
windowMs: config.get('RateLimit.login.window') * 1000,
max: config.get('RateLimit.login.max'),
skipSuccessfulRequests: true
windowMs: 60 * 60 * 1000,//config.get('RateLimit.login.window') * 1000,
max: 5,//config.get('RateLimit.login.max'),
})
: (req, res, next) => { next(); };
const loginProps = [
@@ -110,6 +110,7 @@ const loginProps = [
{name: 'displayname', type: 'string', optional: true},
{name: 'password', type: 'string'}];
router.post('/login',
loginLimiter,
bodyVerifier(loginProps),
canonicalizeRequest,
wrap(async (req, res, next) => {


+ 0
- 26
app/util/auth.js 파일 보기

@@ -53,32 +53,6 @@ const apiLimiter = config.get('RateLimit.enable')
// sets req.username, req.displayname, req.scope, and req.key if authenticated properly,
// otherwise throws an error code.
// If the user is banned, also throw an error.
/*
const requireAuth = scope => wrap(async (req, res, next) => {
const status = {
authenticated: false,
permission: false
};

// First, check the session
checkSession(req, scope, status);
// If not authenticated yet, check for a key
if (!status.authenticated)
await checkKey(req, scope, status);

if (!status.authenticated)
return res.status(401).json({message: 'Unauthorized.'});
else if (!status.permission)
return res.status(403).json({message: 'Forbidden.'});

// Check if the user is banned
const user = await User.findOne({username: req.username});
if (user && user.banned)
return res.status(403).json({message: 'Forbidden.'});

next();
});
*/
const requireAuth = scope => (req, res, next) => {
apiLimiter(req, res, wrap(async () => {



+ 2
- 2
config/default.json 파일 보기

@@ -41,11 +41,11 @@
"enable": true,
"login": {
"window": 600,
"max": 5
"max": 10
},
"register": {
"window": 600,
"max": 5
"max": 10
},
"api": {
"window": 600,


불러오는 중...
취소
저장