Only use simplified user agent for login detection

This commit is contained in:
Johannes Zellner
2021-05-04 09:11:16 +02:00
parent 885647f484
commit e10b7b59dc
3 changed files with 12 additions and 2 deletions

View File

@@ -74,6 +74,7 @@ let assert = require('assert'),
tokens = require('./tokens.js'),
userdb = require('./userdb.js'),
uuid = require('uuid'),
uaParser = require('ua-parser-js'),
superagent = require('superagent'),
validator = require('validator'),
_ = require('underscore');
@@ -545,15 +546,18 @@ function checkLoginLocation(user, ip, userAgent) {
if (!city || !country) return;
const ua = uaParser(userAgent);
const simplifiedUserAgent = ua.browser.name + ' - ' + ua.os.name;
const knownLogin = user.loginLocations.find(function (l) {
return l.userAgent === userAgent && l.country === country && l.city === city;
return l.userAgent === simplifiedUserAgent && l.country === country && l.city === city;
});
if (knownLogin) return;
// purge potentially old locations where ts > now() - 6 months
const sixMonthsBack = Date.now() - 6 * 30 * 24 * 60 * 60 * 1000;
const newLoginLocation = { ts: Date.now(), ip, userAgent, country, city };
const newLoginLocation = { ts: Date.now(), ip, simplifiedUserAgent, country, city };
let loginLocations = user.loginLocations.filter(function (l) { return l.ts > sixMonthsBack; });
loginLocations.push(newLoginLocation);