|
15 | 15 | import inspect |
16 | 16 | import logging |
17 | 17 | from typing import TYPE_CHECKING, Dict, Generic, List, Optional, TypeVar, Union |
18 | | -from urllib.parse import urlencode |
| 18 | +from urllib.parse import urlencode, urlparse |
19 | 19 |
|
20 | 20 | import attr |
21 | 21 | import pymacaroons |
|
68 | 68 | # |
69 | 69 | # Here we have the names of the cookies, and the options we use to set them. |
70 | 70 | _SESSION_COOKIES = [ |
71 | | - (b"oidc_session", b"Path=/_synapse/client/oidc; HttpOnly; Secure; SameSite=None"), |
72 | | - (b"oidc_session_no_samesite", b"Path=/_synapse/client/oidc; HttpOnly"), |
| 71 | + (b"oidc_session", b"HttpOnly; Secure; SameSite=None"), |
| 72 | + (b"oidc_session_no_samesite", b"HttpOnly"), |
73 | 73 | ] |
74 | 74 |
|
75 | 75 | #: A token exchanged from the token endpoint, as per RFC6749 sec 5.1. and |
@@ -279,6 +279,13 @@ def __init__( |
279 | 279 | self._config = provider |
280 | 280 | self._callback_url = hs.config.oidc_callback_url # type: str |
281 | 281 |
|
| 282 | + # Calculate the prefix for OIDC callback paths based on the public_baseurl. |
| 283 | + # We'll insert this into the Path= parameter of any session cookies we set. |
| 284 | + public_baseurl_path = urlparse(hs.config.server.public_baseurl).path |
| 285 | + self._callback_path_prefix = ( |
| 286 | + public_baseurl_path.encode("utf-8") + b"_synapse/client/oidc" |
| 287 | + ) |
| 288 | + |
282 | 289 | self._oidc_attribute_requirements = provider.attribute_requirements |
283 | 290 | self._scopes = provider.scopes |
284 | 291 | self._user_profile_method = provider.user_profile_method |
@@ -779,8 +786,13 @@ async def handle_redirect_request( |
779 | 786 |
|
780 | 787 | for cookie_name, options in _SESSION_COOKIES: |
781 | 788 | request.cookies.append( |
782 | | - b"%s=%s; Max-Age=3600; %s" |
783 | | - % (cookie_name, cookie.encode("utf-8"), options) |
| 789 | + b"%s=%s; Max-Age=3600; Path=%s; %s" |
| 790 | + % ( |
| 791 | + cookie_name, |
| 792 | + cookie.encode("utf-8"), |
| 793 | + self._callback_path_prefix, |
| 794 | + options, |
| 795 | + ) |
784 | 796 | ) |
785 | 797 |
|
786 | 798 | metadata = await self.load_metadata() |
|
0 commit comments