Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
Matrix
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Code
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Container Registry
Model registry
Operate
Environments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
TeDomum
Matrix
Commits
216c9763
Commit
216c9763
authored
9 years ago
by
Daniel Wagner-Hall
Browse files
Options
Downloads
Plain Diff
Merge pull request #323 from matrix-org/daniel/sizelimits
Reject events which are too large
parents
259d10f0
e60dad86
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
synapse/api/auth.py
+21
-1
21 additions, 1 deletion
synapse/api/auth.py
synapse/api/errors.py
+9
-0
9 additions, 0 deletions
synapse/api/errors.py
with
30 additions
and
1 deletion
synapse/api/auth.py
+
21
−
1
View file @
216c9763
...
...
@@ -14,13 +14,14 @@
# limitations under the License.
"""
This module contains classes for authenticating the user.
"""
from
canonicaljson
import
encode_canonical_json
from
signedjson.key
import
decode_verify_key_bytes
from
signedjson.sign
import
verify_signed_json
,
SignatureVerifyException
from
twisted.internet
import
defer
from
synapse.api.constants
import
EventTypes
,
Membership
,
JoinRules
from
synapse.api.errors
import
AuthError
,
Codes
,
SynapseError
from
synapse.api.errors
import
AuthError
,
Codes
,
SynapseError
,
EventSizeError
from
synapse.types
import
RoomID
,
UserID
,
EventID
from
synapse.util.logutils
import
log_function
from
synapse.util
import
third_party_invites
...
...
@@ -64,6 +65,8 @@ class Auth(object):
Returns:
True if the auth checks pass.
"""
self
.
check_size_limits
(
event
)
try
:
if
not
hasattr
(
event
,
"
room_id
"
):
raise
AuthError
(
500
,
"
Event has no room_id: %s
"
%
event
)
...
...
@@ -131,6 +134,23 @@ class Auth(object):
logger
.
info
(
"
Denying! %s
"
,
event
)
raise
def
check_size_limits
(
self
,
event
):
def
too_big
(
field
):
raise
EventSizeError
(
"
%s too large
"
%
(
field
,))
if
len
(
event
.
user_id
)
>
255
:
too_big
(
"
user_id
"
)
if
len
(
event
.
room_id
)
>
255
:
too_big
(
"
room_id
"
)
if
event
.
is_state
()
and
len
(
event
.
state_key
)
>
255
:
too_big
(
"
state_key
"
)
if
len
(
event
.
type
)
>
255
:
too_big
(
"
type
"
)
if
len
(
event
.
event_id
)
>
255
:
too_big
(
"
event_id
"
)
if
len
(
encode_canonical_json
(
event
.
get_pdu_json
()))
>
65536
:
too_big
(
"
event
"
)
@defer.inlineCallbacks
def
check_joined_room
(
self
,
room_id
,
user_id
,
current_state
=
None
):
"""
Check if the user is currently joined in the room
...
...
This diff is collapsed.
Click to expand it.
synapse/api/errors.py
+
9
−
0
View file @
216c9763
...
...
@@ -119,6 +119,15 @@ class AuthError(SynapseError):
super
(
AuthError
,
self
).
__init__
(
*
args
,
**
kwargs
)
class
EventSizeError
(
SynapseError
):
"""
An error raised when an event is too big.
"""
def
__init__
(
self
,
*
args
,
**
kwargs
):
if
"
errcode
"
not
in
kwargs
:
kwargs
[
"
errcode
"
]
=
Codes
.
TOO_LARGE
super
(
EventSizeError
,
self
).
__init__
(
413
,
*
args
,
**
kwargs
)
class
EventStreamError
(
SynapseError
):
"""
An error raised when there a problem with the event stream.
"""
def
__init__
(
self
,
*
args
,
**
kwargs
):
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment