|
|
@ -79,9 +79,9 @@ limiter = limiter.LimitWraperFactory()
|
|
|
|
def extract_network_from_ip(ip):
|
|
|
|
def extract_network_from_ip(ip):
|
|
|
|
n = ipaddress.ip_network(ip)
|
|
|
|
n = ipaddress.ip_network(ip)
|
|
|
|
if n.version == 4:
|
|
|
|
if n.version == 4:
|
|
|
|
return str(n.supernet(prefixlen_diff=(32-int(app.config["AUTH_RATELIMIT_IP_V4_MASK"]))).network_address)
|
|
|
|
return str(n.supernet(prefixlen_diff=(32-app.config["AUTH_RATELIMIT_IP_V4_MASK"])).network_address)
|
|
|
|
else:
|
|
|
|
else:
|
|
|
|
return str(n.supernet(prefixlen_diff=(128-int(app.config["AUTH_RATELIMIT_IP_V6_MASK"]))).network_address)
|
|
|
|
return str(n.supernet(prefixlen_diff=(128-app.config["AUTH_RATELIMIT_IP_V6_MASK"])).network_address)
|
|
|
|
|
|
|
|
|
|
|
|
def is_exempt_from_ratelimits(ip):
|
|
|
|
def is_exempt_from_ratelimits(ip):
|
|
|
|
ip = ipaddress.ip_address(ip)
|
|
|
|
ip = ipaddress.ip_address(ip)
|
|
|
@ -270,7 +270,7 @@ class MailuSession(CallbackDict, SessionMixin):
|
|
|
|
if 'webmail_token' in self:
|
|
|
|
if 'webmail_token' in self:
|
|
|
|
app.session_store.put(self['webmail_token'],
|
|
|
|
app.session_store.put(self['webmail_token'],
|
|
|
|
self.sid,
|
|
|
|
self.sid,
|
|
|
|
int(app.config['PERMANENT_SESSION_LIFETIME']),
|
|
|
|
app.config['PERMANENT_SESSION_LIFETIME'],
|
|
|
|
)
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
# get new session key
|
|
|
|
# get new session key
|
|
|
@ -284,7 +284,7 @@ class MailuSession(CallbackDict, SessionMixin):
|
|
|
|
self.app.session_store.put(
|
|
|
|
self.app.session_store.put(
|
|
|
|
key,
|
|
|
|
key,
|
|
|
|
pickle.dumps(dict(self)),
|
|
|
|
pickle.dumps(dict(self)),
|
|
|
|
int(app.config['SESSION_TIMEOUT']),
|
|
|
|
app.config['SESSION_TIMEOUT'],
|
|
|
|
)
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
self._key = key
|
|
|
|
self._key = key
|
|
|
@ -357,7 +357,7 @@ class MailuSessionConfig:
|
|
|
|
if now is None:
|
|
|
|
if now is None:
|
|
|
|
now = int(time.time())
|
|
|
|
now = int(time.time())
|
|
|
|
created = int.from_bytes(created, byteorder='big')
|
|
|
|
created = int.from_bytes(created, byteorder='big')
|
|
|
|
if not created <= now <= created + int(app.config['PERMANENT_SESSION_LIFETIME']):
|
|
|
|
if not created <= now <= created + app.config['PERMANENT_SESSION_LIFETIME']:
|
|
|
|
return None
|
|
|
|
return None
|
|
|
|
|
|
|
|
|
|
|
|
return (uid, sid, crt)
|
|
|
|
return (uid, sid, crt)
|
|
|
@ -402,7 +402,7 @@ class MailuSessionInterface(SessionInterface):
|
|
|
|
response.set_cookie(
|
|
|
|
response.set_cookie(
|
|
|
|
app.session_cookie_name,
|
|
|
|
app.session_cookie_name,
|
|
|
|
session.sid,
|
|
|
|
session.sid,
|
|
|
|
expires=datetime.now()+timedelta(seconds=int(app.config['PERMANENT_SESSION_LIFETIME'])),
|
|
|
|
expires=datetime.now()+timedelta(seconds=app.config['PERMANENT_SESSION_LIFETIME']),
|
|
|
|
httponly=self.get_cookie_httponly(app),
|
|
|
|
httponly=self.get_cookie_httponly(app),
|
|
|
|
domain=self.get_cookie_domain(app),
|
|
|
|
domain=self.get_cookie_domain(app),
|
|
|
|
path=self.get_cookie_path(app),
|
|
|
|
path=self.get_cookie_path(app),
|
|
|
@ -494,6 +494,6 @@ def gen_temp_token(email, session):
|
|
|
|
session['webmail_token'] = token
|
|
|
|
session['webmail_token'] = token
|
|
|
|
app.session_store.put(token,
|
|
|
|
app.session_store.put(token,
|
|
|
|
session.sid,
|
|
|
|
session.sid,
|
|
|
|
int(app.config['PERMANENT_SESSION_LIFETIME']),
|
|
|
|
app.config['PERMANENT_SESSION_LIFETIME'],
|
|
|
|
)
|
|
|
|
)
|
|
|
|
return token
|
|
|
|
return token
|
|
|
|