mirror of
https://git.anonymousland.org/anonymousland/synapse.git
synced 2025-08-16 14:20:16 -04:00
Merge remote-tracking branch 'upstream/release-v1.26.0'
This commit is contained in:
commit
d3547df958
183 changed files with 8528 additions and 2668 deletions
|
@ -32,7 +32,7 @@ from typing import (
|
|||
|
||||
import treq
|
||||
from canonicaljson import encode_canonical_json
|
||||
from netaddr import IPAddress, IPSet
|
||||
from netaddr import AddrFormatError, IPAddress, IPSet
|
||||
from prometheus_client import Counter
|
||||
from zope.interface import implementer, provider
|
||||
|
||||
|
@ -261,16 +261,16 @@ class BlacklistingAgentWrapper(Agent):
|
|||
|
||||
try:
|
||||
ip_address = IPAddress(h.hostname)
|
||||
|
||||
except AddrFormatError:
|
||||
# Not an IP
|
||||
pass
|
||||
else:
|
||||
if check_against_blacklist(
|
||||
ip_address, self._ip_whitelist, self._ip_blacklist
|
||||
):
|
||||
logger.info("Blocking access to %s due to blacklist" % (ip_address,))
|
||||
e = SynapseError(403, "IP address blocked by IP blacklist entry")
|
||||
return defer.fail(Failure(e))
|
||||
except Exception:
|
||||
# Not an IP
|
||||
pass
|
||||
|
||||
return self._agent.request(
|
||||
method, uri, headers=headers, bodyProducer=bodyProducer
|
||||
|
@ -725,7 +725,7 @@ class SimpleHttpClient:
|
|||
read_body_with_max_size(response, output_stream, max_size)
|
||||
)
|
||||
except BodyExceededMaxSize:
|
||||
SynapseError(
|
||||
raise SynapseError(
|
||||
502,
|
||||
"Requested file is too large > %r bytes" % (max_size,),
|
||||
Codes.TOO_LARGE,
|
||||
|
@ -767,14 +767,24 @@ class _ReadBodyWithMaxSizeProtocol(protocol.Protocol):
|
|||
self.max_size = max_size
|
||||
|
||||
def dataReceived(self, data: bytes) -> None:
|
||||
# If the deferred was called, bail early.
|
||||
if self.deferred.called:
|
||||
return
|
||||
|
||||
self.stream.write(data)
|
||||
self.length += len(data)
|
||||
# The first time the maximum size is exceeded, error and cancel the
|
||||
# connection. dataReceived might be called again if data was received
|
||||
# in the meantime.
|
||||
if self.max_size is not None and self.length >= self.max_size:
|
||||
self.deferred.errback(BodyExceededMaxSize())
|
||||
self.deferred = defer.Deferred()
|
||||
self.transport.loseConnection()
|
||||
|
||||
def connectionLost(self, reason: Failure) -> None:
|
||||
# If the maximum size was already exceeded, there's nothing to do.
|
||||
if self.deferred.called:
|
||||
return
|
||||
|
||||
if reason.check(ResponseDone):
|
||||
self.deferred.callback(self.length)
|
||||
elif reason.check(PotentialDataLoss):
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue