mirror of
https://git.anonymousland.org/anonymousland/synapse-product.git
synced 2025-01-16 02:37:06 -05:00
Add an option to enable recording IPs for appservice users (#3831)
This commit is contained in:
parent
fd96dd75a3
commit
1737753a62
1
changelog.d/3831.feature
Normal file
1
changelog.d/3831.feature
Normal file
@ -0,0 +1 @@
|
|||||||
|
Add an option to enable recording IPs for appservice users
|
@ -188,17 +188,33 @@ class Auth(object):
|
|||||||
"""
|
"""
|
||||||
# Can optionally look elsewhere in the request (e.g. headers)
|
# Can optionally look elsewhere in the request (e.g. headers)
|
||||||
try:
|
try:
|
||||||
user_id, app_service = yield self._get_appservice_user_id(request)
|
ip_addr = self.hs.get_ip_from_request(request)
|
||||||
if user_id:
|
user_agent = request.requestHeaders.getRawHeaders(
|
||||||
request.authenticated_entity = user_id
|
b"User-Agent",
|
||||||
defer.returnValue(
|
default=[b""]
|
||||||
synapse.types.create_requester(user_id, app_service=app_service)
|
)[0].decode('ascii', 'surrogateescape')
|
||||||
)
|
|
||||||
|
|
||||||
access_token = self.get_access_token_from_request(
|
access_token = self.get_access_token_from_request(
|
||||||
request, self.TOKEN_NOT_FOUND_HTTP_STATUS
|
request, self.TOKEN_NOT_FOUND_HTTP_STATUS
|
||||||
)
|
)
|
||||||
|
|
||||||
|
user_id, app_service = yield self._get_appservice_user_id(request)
|
||||||
|
if user_id:
|
||||||
|
request.authenticated_entity = user_id
|
||||||
|
|
||||||
|
if ip_addr and self.hs.config.track_appservice_user_ips:
|
||||||
|
yield self.store.insert_client_ip(
|
||||||
|
user_id=user_id,
|
||||||
|
access_token=access_token,
|
||||||
|
ip=ip_addr,
|
||||||
|
user_agent=user_agent,
|
||||||
|
device_id="dummy-device", # stubbed
|
||||||
|
)
|
||||||
|
|
||||||
|
defer.returnValue(
|
||||||
|
synapse.types.create_requester(user_id, app_service=app_service)
|
||||||
|
)
|
||||||
|
|
||||||
user_info = yield self.get_user_by_access_token(access_token, rights)
|
user_info = yield self.get_user_by_access_token(access_token, rights)
|
||||||
user = user_info["user"]
|
user = user_info["user"]
|
||||||
token_id = user_info["token_id"]
|
token_id = user_info["token_id"]
|
||||||
@ -208,11 +224,6 @@ class Auth(object):
|
|||||||
# stubbed out.
|
# stubbed out.
|
||||||
device_id = user_info.get("device_id")
|
device_id = user_info.get("device_id")
|
||||||
|
|
||||||
ip_addr = self.hs.get_ip_from_request(request)
|
|
||||||
user_agent = request.requestHeaders.getRawHeaders(
|
|
||||||
b"User-Agent",
|
|
||||||
default=[b""]
|
|
||||||
)[0].decode('ascii', 'surrogateescape')
|
|
||||||
if user and access_token and ip_addr:
|
if user and access_token and ip_addr:
|
||||||
yield self.store.insert_client_ip(
|
yield self.store.insert_client_ip(
|
||||||
user_id=user.to_string(),
|
user_id=user.to_string(),
|
||||||
|
@ -33,11 +33,16 @@ class AppServiceConfig(Config):
|
|||||||
def read_config(self, config):
|
def read_config(self, config):
|
||||||
self.app_service_config_files = config.get("app_service_config_files", [])
|
self.app_service_config_files = config.get("app_service_config_files", [])
|
||||||
self.notify_appservices = config.get("notify_appservices", True)
|
self.notify_appservices = config.get("notify_appservices", True)
|
||||||
|
self.track_appservice_user_ips = config.get("track_appservice_user_ips", False)
|
||||||
|
|
||||||
def default_config(cls, **kwargs):
|
def default_config(cls, **kwargs):
|
||||||
return """\
|
return """\
|
||||||
# A list of application service config file to use
|
# A list of application service config file to use
|
||||||
app_service_config_files: []
|
app_service_config_files: []
|
||||||
|
|
||||||
|
# Whether or not to track application service IP addresses. Implicitly
|
||||||
|
# enables MAU tracking for application service users.
|
||||||
|
track_appservice_user_ips: False
|
||||||
"""
|
"""
|
||||||
|
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user