forked from MirrorHub/synapse
Fix regression where synapse checked whether push rules were valid JSON before the compatibility hack that handled clients sending invalid JSON
This commit is contained in:
parent
494d0c8e02
commit
398cd1edfb
2 changed files with 19 additions and 6 deletions
|
@ -119,13 +119,13 @@ def parse_string(request, name, default=None, required=False,
|
||||||
return default
|
return default
|
||||||
|
|
||||||
|
|
||||||
def parse_json_object_from_request(request):
|
def parse_json_value_from_request(request):
|
||||||
"""Parse a JSON object from the body of a twisted HTTP request.
|
"""Parse a JSON value from the body of a twisted HTTP request.
|
||||||
|
|
||||||
:param request: the twisted HTTP request.
|
:param request: the twisted HTTP request.
|
||||||
|
:returns: The JSON value.
|
||||||
:raises
|
:raises
|
||||||
SynapseError if the request body couldn't be decoded as JSON or
|
SynapseError if the request body couldn't be decoded as JSON.
|
||||||
if it wasn't a JSON object.
|
|
||||||
"""
|
"""
|
||||||
try:
|
try:
|
||||||
content_bytes = request.content.read()
|
content_bytes = request.content.read()
|
||||||
|
@ -137,6 +137,19 @@ def parse_json_object_from_request(request):
|
||||||
except simplejson.JSONDecodeError:
|
except simplejson.JSONDecodeError:
|
||||||
raise SynapseError(400, "Content not JSON.", errcode=Codes.NOT_JSON)
|
raise SynapseError(400, "Content not JSON.", errcode=Codes.NOT_JSON)
|
||||||
|
|
||||||
|
return content
|
||||||
|
|
||||||
|
|
||||||
|
def parse_json_object_from_request(request):
|
||||||
|
"""Parse a JSON object from the body of a twisted HTTP request.
|
||||||
|
|
||||||
|
:param request: the twisted HTTP request.
|
||||||
|
:raises
|
||||||
|
SynapseError if the request body couldn't be decoded as JSON or
|
||||||
|
if it wasn't a JSON object.
|
||||||
|
"""
|
||||||
|
content = parse_json_value_from_request(request)
|
||||||
|
|
||||||
if type(content) != dict:
|
if type(content) != dict:
|
||||||
message = "Content must be a JSON object."
|
message = "Content must be a JSON object."
|
||||||
raise SynapseError(400, message, errcode=Codes.BAD_JSON)
|
raise SynapseError(400, message, errcode=Codes.BAD_JSON)
|
||||||
|
|
|
@ -25,7 +25,7 @@ from synapse.storage.push_rule import (
|
||||||
from synapse.push.clientformat import format_push_rules_for_user
|
from synapse.push.clientformat import format_push_rules_for_user
|
||||||
from synapse.push.baserules import BASE_RULE_IDS
|
from synapse.push.baserules import BASE_RULE_IDS
|
||||||
from synapse.push.rulekinds import PRIORITY_CLASS_MAP
|
from synapse.push.rulekinds import PRIORITY_CLASS_MAP
|
||||||
from synapse.http.servlet import parse_json_object_from_request
|
from synapse.http.servlet import parse_json_value_from_request
|
||||||
|
|
||||||
|
|
||||||
class PushRuleRestServlet(ClientV1RestServlet):
|
class PushRuleRestServlet(ClientV1RestServlet):
|
||||||
|
@ -51,7 +51,7 @@ class PushRuleRestServlet(ClientV1RestServlet):
|
||||||
if '/' in spec['rule_id'] or '\\' in spec['rule_id']:
|
if '/' in spec['rule_id'] or '\\' in spec['rule_id']:
|
||||||
raise SynapseError(400, "rule_id may not contain slashes")
|
raise SynapseError(400, "rule_id may not contain slashes")
|
||||||
|
|
||||||
content = parse_json_object_from_request(request)
|
content = parse_json_value_from_request(request)
|
||||||
|
|
||||||
user_id = requester.user.to_string()
|
user_id = requester.user.to_string()
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue