Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
synapse
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package Registry
Container Registry
Model registry
Operate
Terraform modules
Monitor
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Timo Ley
synapse
Commits
04fd6221
Unverified
Commit
04fd6221
authored
2 years ago
by
David Robertson
Committed by
GitHub
2 years ago
Browse files
Options
Downloads
Patches
Plain Diff
Fix incorrectly sending authentication tokens to application service as headers (#14301)
parent
23fa636e
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
changelog.d/14301.bugfix
+1
-0
1 addition, 0 deletions
changelog.d/14301.bugfix
synapse/appservice/api.py
+7
-5
7 additions, 5 deletions
synapse/appservice/api.py
tests/appservice/test_api.py
+5
-3
5 additions, 3 deletions
tests/appservice/test_api.py
with
13 additions
and
8 deletions
changelog.d/14301.bugfix
0 → 100644
+
1
−
0
View file @
04fd6221
Fix a bug introduced in Synapse 1.70.0rc1 where access tokens would be incorrectly sent to application services as headers. Application services which were obtaining access tokens from query parameters were not affected.
This diff is collapsed.
Click to expand it.
synapse/appservice/api.py
+
7
−
5
View file @
04fd6221
...
...
@@ -123,7 +123,7 @@ class ApplicationServiceApi(SimpleHttpClient):
response
=
await
self
.
get_json
(
uri
,
{
"
access_token
"
:
service
.
hs_token
},
headers
=
{
"
Authorization
"
:
f
"
Bearer
{
service
.
hs_token
}
"
},
headers
=
{
"
Authorization
"
:
[
f
"
Bearer
{
service
.
hs_token
}
"
]
},
)
if
response
is
not
None
:
# just an empty json object
return
True
...
...
@@ -147,7 +147,7 @@ class ApplicationServiceApi(SimpleHttpClient):
response
=
await
self
.
get_json
(
uri
,
{
"
access_token
"
:
service
.
hs_token
},
headers
=
{
"
Authorization
"
:
f
"
Bearer
{
service
.
hs_token
}
"
},
headers
=
{
"
Authorization
"
:
[
f
"
Bearer
{
service
.
hs_token
}
"
]
},
)
if
response
is
not
None
:
# just an empty json object
return
True
...
...
@@ -190,7 +190,9 @@ class ApplicationServiceApi(SimpleHttpClient):
b
"
access_token
"
:
service
.
hs_token
,
}
response
=
await
self
.
get_json
(
uri
,
args
=
args
,
headers
=
{
"
Authorization
"
:
f
"
Bearer
{
service
.
hs_token
}
"
}
uri
,
args
=
args
,
headers
=
{
"
Authorization
"
:
[
f
"
Bearer
{
service
.
hs_token
}
"
]},
)
if
not
isinstance
(
response
,
list
):
logger
.
warning
(
...
...
@@ -230,7 +232,7 @@ class ApplicationServiceApi(SimpleHttpClient):
info
=
await
self
.
get_json
(
uri
,
{
"
access_token
"
:
service
.
hs_token
},
headers
=
{
"
Authorization
"
:
f
"
Bearer
{
service
.
hs_token
}
"
},
headers
=
{
"
Authorization
"
:
[
f
"
Bearer
{
service
.
hs_token
}
"
]
},
)
if
not
_is_valid_3pe_metadata
(
info
):
...
...
@@ -327,7 +329,7 @@ class ApplicationServiceApi(SimpleHttpClient):
uri
=
uri
,
json_body
=
body
,
args
=
{
"
access_token
"
:
service
.
hs_token
},
headers
=
{
"
Authorization
"
:
f
"
Bearer
{
service
.
hs_token
}
"
},
headers
=
{
"
Authorization
"
:
[
f
"
Bearer
{
service
.
hs_token
}
"
]
},
)
if
logger
.
isEnabledFor
(
logging
.
DEBUG
):
logger
.
debug
(
...
...
This diff is collapsed.
Click to expand it.
tests/appservice/test_api.py
+
5
−
3
View file @
04fd6221
...
...
@@ -11,7 +11,7 @@
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
from
typing
import
Any
,
List
,
Mapping
from
typing
import
Any
,
List
,
Mapping
,
Sequence
,
Union
from
unittest.mock
import
Mock
from
twisted.test.proto_helpers
import
MemoryReactor
...
...
@@ -70,13 +70,15 @@ class ApplicationServiceApiTestCase(unittest.HomeserverTestCase):
self
.
request_url
=
None
async
def
get_json
(
url
:
str
,
args
:
Mapping
[
Any
,
Any
],
headers
:
Mapping
[
Any
,
Any
]
url
:
str
,
args
:
Mapping
[
Any
,
Any
],
headers
:
Mapping
[
Union
[
str
,
bytes
],
Sequence
[
Union
[
str
,
bytes
]]],
)
->
List
[
JsonDict
]:
# Ensure the access token is passed as both a header and query arg.
if
not
headers
.
get
(
"
Authorization
"
)
or
not
args
.
get
(
b
"
access_token
"
):
raise
RuntimeError
(
"
Access token not provided
"
)
self
.
assertEqual
(
headers
.
get
(
"
Authorization
"
),
f
"
Bearer
{
TOKEN
}
"
)
self
.
assertEqual
(
headers
.
get
(
"
Authorization
"
),
[
f
"
Bearer
{
TOKEN
}
"
]
)
self
.
assertEqual
(
args
.
get
(
b
"
access_token
"
),
TOKEN
)
self
.
request_url
=
url
if
url
==
URL_USER
:
...
...
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