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

Commit

Permalink
Log when we get an invalid body on certain CS-API requests
Browse files Browse the repository at this point in the history
Some endpoints currently accept an invalid JSON object in the request body,
which we should stop. As a starting point, let's log when it happens so that we
can fix it.
  • Loading branch information
richvdh committed Jul 26, 2022
1 parent c7c84b8 commit 2a915bb
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 1 deletion.
1 change: 1 addition & 0 deletions changelog.d/13386.misc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Log when we get an invalid request body on room membership requests.
4 changes: 3 additions & 1 deletion synapse/rest/client/room.py
Original file line number Diff line number Diff line change
Expand Up @@ -319,9 +319,10 @@ async def on_POST(

try:
content = parse_json_object_from_request(request)
except Exception:
except Exception as e:
# Turns out we used to ignore the body entirely, and some clients
# cheekily send invalid bodies.
logger.warning("Ignoring invalid body on POST %s: %s", request.path, e)
content = {}

# twisted.web.server.Request.args is incorrectly defined as Optional[Any]
Expand Down Expand Up @@ -858,6 +859,7 @@ async def on_POST(
except Exception:
# Turns out we used to ignore the body entirely, and some clients
# cheekily send invalid bodies.
logger.warning("Ignoring invalid body on POST %s: %s", request.path, e)
content = {}

if membership_action == "invite" and self._has_3pid_invite_keys(content):
Expand Down

0 comments on commit 2a915bb

Please sign in to comment.