Skip to content
This repository has been archived by the owner on Apr 26, 2024. It is now read-only.

Commit

Permalink
Hoist up transaction validity checks
Browse files Browse the repository at this point in the history
  • Loading branch information
richvdh committed Mar 12, 2021
1 parent c0faab8 commit dee7360
Showing 1 changed file with 7 additions and 13 deletions.
20 changes: 7 additions & 13 deletions synapse/federation/federation_server.py
Original file line number Diff line number Diff line change
Expand Up @@ -170,6 +170,13 @@ async def on_incoming_transaction(

logger.debug("[%s] Got transaction", transaction_id)

# Reject malformed transactions early: reject if too many PDUs/EDUs
if len(transaction.pdus) > 50 or ( # type: ignore
hasattr(transaction, "edus") and len(transaction.edus) > 100 # type: ignore
):
logger.info("Transaction PDU or EDU count too large. Returning 400")
return 400, {}

# we only process one transaction from each origin at a time. We need to do
# this check here, rather than in _on_incoming_transaction_inner so that we
# don't cache the rejection in _transaction_resp_cache (so that if the txn
Expand Down Expand Up @@ -240,19 +247,6 @@ async def _handle_incoming_transaction(

logger.debug("[%s] Transaction is new", transaction.transaction_id) # type: ignore

# Reject if PDU count > 50 or EDU count > 100
if len(transaction.pdus) > 50 or ( # type: ignore
hasattr(transaction, "edus") and len(transaction.edus) > 100 # type: ignore
):

logger.info("Transaction PDU or EDU count too large. Returning 400")

response = {}
await self.transaction_actions.set_response(
origin, transaction, 400, response
)
return 400, response

# We process PDUs and EDUs in parallel. This is important as we don't
# want to block things like to device messages from reaching clients
# behind the potentially expensive handling of PDUs.
Expand Down

0 comments on commit dee7360

Please sign in to comment.