mirror of
https://git.anonymousland.org/anonymousland/synapse.git
synced 2025-05-02 17:44:49 -04:00
Use getClientAddress
instead of getClientIP
. (#12599)
getClientIP was deprecated in Twisted 18.4.0, which also added getClientAddress. The Synapse minimum version for Twisted is currently 18.9.0, so all supported versions have the new API.
This commit is contained in:
parent
116a4c8340
commit
7fbf42499d
16 changed files with 62 additions and 46 deletions
|
@ -112,7 +112,7 @@ class AuthRestServlet(RestServlet):
|
|||
|
||||
try:
|
||||
await self.auth_handler.add_oob_auth(
|
||||
LoginType.RECAPTCHA, authdict, request.getClientIP()
|
||||
LoginType.RECAPTCHA, authdict, request.getClientAddress().host
|
||||
)
|
||||
except LoginError as e:
|
||||
# Authentication failed, let user try again
|
||||
|
@ -132,7 +132,7 @@ class AuthRestServlet(RestServlet):
|
|||
|
||||
try:
|
||||
await self.auth_handler.add_oob_auth(
|
||||
LoginType.TERMS, authdict, request.getClientIP()
|
||||
LoginType.TERMS, authdict, request.getClientAddress().host
|
||||
)
|
||||
except LoginError as e:
|
||||
# Authentication failed, let user try again
|
||||
|
@ -161,7 +161,9 @@ class AuthRestServlet(RestServlet):
|
|||
|
||||
try:
|
||||
await self.auth_handler.add_oob_auth(
|
||||
LoginType.REGISTRATION_TOKEN, authdict, request.getClientIP()
|
||||
LoginType.REGISTRATION_TOKEN,
|
||||
authdict,
|
||||
request.getClientAddress().host,
|
||||
)
|
||||
except LoginError as e:
|
||||
html = self.registration_token_template.render(
|
||||
|
|
|
@ -176,7 +176,7 @@ class LoginRestServlet(RestServlet):
|
|||
|
||||
if appservice.is_rate_limited():
|
||||
await self._address_ratelimiter.ratelimit(
|
||||
None, request.getClientIP()
|
||||
None, request.getClientAddress().host
|
||||
)
|
||||
|
||||
result = await self._do_appservice_login(
|
||||
|
@ -188,19 +188,25 @@ class LoginRestServlet(RestServlet):
|
|||
self.jwt_enabled
|
||||
and login_submission["type"] == LoginRestServlet.JWT_TYPE
|
||||
):
|
||||
await self._address_ratelimiter.ratelimit(None, request.getClientIP())
|
||||
await self._address_ratelimiter.ratelimit(
|
||||
None, request.getClientAddress().host
|
||||
)
|
||||
result = await self._do_jwt_login(
|
||||
login_submission,
|
||||
should_issue_refresh_token=should_issue_refresh_token,
|
||||
)
|
||||
elif login_submission["type"] == LoginRestServlet.TOKEN_TYPE:
|
||||
await self._address_ratelimiter.ratelimit(None, request.getClientIP())
|
||||
await self._address_ratelimiter.ratelimit(
|
||||
None, request.getClientAddress().host
|
||||
)
|
||||
result = await self._do_token_login(
|
||||
login_submission,
|
||||
should_issue_refresh_token=should_issue_refresh_token,
|
||||
)
|
||||
else:
|
||||
await self._address_ratelimiter.ratelimit(None, request.getClientIP())
|
||||
await self._address_ratelimiter.ratelimit(
|
||||
None, request.getClientAddress().host
|
||||
)
|
||||
result = await self._do_other_login(
|
||||
login_submission,
|
||||
should_issue_refresh_token=should_issue_refresh_token,
|
||||
|
|
|
@ -352,7 +352,7 @@ class UsernameAvailabilityRestServlet(RestServlet):
|
|||
if self.inhibit_user_in_use_error:
|
||||
return 200, {"available": True}
|
||||
|
||||
ip = request.getClientIP()
|
||||
ip = request.getClientAddress().host
|
||||
with self.ratelimiter.ratelimit(ip) as wait_deferred:
|
||||
await wait_deferred
|
||||
|
||||
|
@ -394,7 +394,7 @@ class RegistrationTokenValidityRestServlet(RestServlet):
|
|||
)
|
||||
|
||||
async def on_GET(self, request: Request) -> Tuple[int, JsonDict]:
|
||||
await self.ratelimiter.ratelimit(None, (request.getClientIP(),))
|
||||
await self.ratelimiter.ratelimit(None, (request.getClientAddress().host,))
|
||||
|
||||
if not self.hs.config.registration.enable_registration:
|
||||
raise SynapseError(
|
||||
|
@ -441,7 +441,7 @@ class RegisterRestServlet(RestServlet):
|
|||
async def on_POST(self, request: SynapseRequest) -> Tuple[int, JsonDict]:
|
||||
body = parse_json_object_from_request(request)
|
||||
|
||||
client_addr = request.getClientIP()
|
||||
client_addr = request.getClientAddress().host
|
||||
|
||||
await self.ratelimiter.ratelimit(None, client_addr, update=False)
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue