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
25d80f35
Commit
25d80f35
authored
10 years ago
by
Mark Haines
Browse files
Options
Downloads
Patches
Plain Diff
Raise a SynapseError if the authorisation header is missing or malformed
parent
75e517a2
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/federation/transport.py
+27
-19
27 additions, 19 deletions
synapse/federation/transport.py
tests/utils.py
+4
-0
4 additions, 0 deletions
tests/utils.py
with
31 additions
and
19 deletions
synapse/federation/transport.py
+
27
−
19
View file @
25d80f35
...
...
@@ -211,36 +211,44 @@ class TransportLayer(object):
if
request
.
method
==
"
PUT
"
:
#TODO: Handle other method types? other content types?
content_bytes
=
request
.
content
.
read
()
content
=
json
.
loads
(
content_bytes
)
json_request
[
"
content
"
]
=
content
try
:
content_bytes
=
request
.
content
.
read
()
content
=
json
.
loads
(
content_bytes
)
json_request
[
"
content
"
]
=
content
except
:
raise
SynapseError
(
400
,
"
Unable to parse JSON
"
,
Codes
.
BAD_JSON
)
def
parse_auth_header
(
header_str
):
params
=
auth
.
split
(
"
"
)[
1
].
split
(
"
,
"
)
param_dict
=
dict
(
kv
.
split
(
"
=
"
)
for
kv
in
params
)
def
strip_quotes
(
value
):
if
value
.
startswith
(
"
\"
"
):
return
value
[
1
:
-
1
]
else
:
return
value
origin
=
strip_quotes
(
param_dict
[
"
origin
"
])
key
=
strip_quotes
(
param_dict
[
"
key
"
])
sig
=
strip_quotes
(
param_dict
[
"
sig
"
])
return
(
origin
,
key
,
sig
)
try
:
params
=
auth
.
split
(
"
"
)[
1
].
split
(
"
,
"
)
param_dict
=
dict
(
kv
.
split
(
"
=
"
)
for
kv
in
params
)
def
strip_quotes
(
value
):
if
value
.
startswith
(
"
\"
"
):
return
value
[
1
:
-
1
]
else
:
return
value
origin
=
strip_quotes
(
param_dict
[
"
origin
"
])
key
=
strip_quotes
(
param_dict
[
"
key
"
])
sig
=
strip_quotes
(
param_dict
[
"
sig
"
])
return
(
origin
,
key
,
sig
)
except
:
raise
SynapseError
(
400
,
"
Malformed Authorization Header
"
,
Codes
.
FORBIDDEN
)
auth_headers
=
request
.
requestHeaders
.
getRawHeaders
(
b
"
Authorization
"
)
if
not
auth_headers
:
raise
SynapseError
(
401
,
"
Missing Authorization headers
"
,
Codes
.
FORBIDDEN
,
)
for
auth
in
auth_headers
:
if
auth
.
startswith
(
"
X-Matrix
"
):
(
origin
,
key
,
sig
)
=
parse_auth_header
(
auth
)
json_request
[
"
origin
"
]
=
origin
json_request
[
"
signatures
"
].
setdefault
(
origin
,{})[
key
]
=
sig
if
not
json_request
[
"
signatures
"
]:
raise
SynapseError
(
401
,
"
Missing Authorization headers
"
,
Codes
.
FORBIDDEN
,
)
yield
self
.
keyring
.
verify_json_for_server
(
origin
,
json_request
)
defer
.
returnValue
((
origin
,
content
))
...
...
This diff is collapsed.
Click to expand it.
tests/utils.py
+
4
−
0
View file @
25d80f35
...
...
@@ -79,6 +79,10 @@ class MockHttpResource(HttpServer):
mock_request
.
method
=
http_method
mock_request
.
uri
=
path
mock_request
.
requestHeaders
.
getRawHeaders
.
return_value
=
[
"
X-Matrix origin=test,key=,sig=
"
]
# return the right path if the event requires it
mock_request
.
path
=
path
...
...
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