Skip to content
This repository has been archived by the owner on Apr 26, 2024. It is now read-only.

Serving synapse on a subpath breaks OIDC due to session cookie having incorrect path #9574

Closed
imaspeer opened this issue Mar 9, 2021 · 6 comments
Labels
T-Enhancement New features, changes in functionality, improvements in performance, or user-facing enhancements.

Comments

@imaspeer
Copy link

imaspeer commented Mar 9, 2021

The session cookie synapse sets before redirecting to the OIDC provider always has its path set to /_synapse/client/oidc regardless of the configured public_baseurl.

If synapse is served on a subpath rather than at the webserver's root (e.g. domain.example/matrix), this causes the cookie to not be sent with the callback request (since the path /matrix/_synapse/client/oidc/callback does not match the cookie's), which then fails with the error missing_session.

@anoadragon453 anoadragon453 added T-Enhancement New features, changes in functionality, improvements in performance, or user-facing enhancements. T-Task Refactoring, removal, replacement, enabling or disabling functionality, other engineering tasks. X-Needs-Discussion and removed T-Task Refactoring, removal, replacement, enabling or disabling functionality, other engineering tasks. labels Mar 10, 2021
@anoadragon453
Copy link
Member

We currently only support endpoints being hosted at the root path of a domain, hence the hardcoded path. However we have been planning towards lifting this restriction.

I'm curious whether you've been successfully hosting your Client Server API (and Federation API?) on a subpath without running into any other issues?

@imaspeer
Copy link
Author

Hi,

We're running a non-federating server, so can't speak about federation API ; regarding client-server API, in a few weeks of running 1.28.0 with patched OIDC we have not ran into any other issue.

I'm attaching the patch to synapse/handlers/oidc_handlers.py we use; it works for us, however we haven't tried it against latest versions.
oidc_cookie_prefix.patch.txt

@anoadragon453
Copy link
Member

@imaspeer Thanks for providing a patch! I've modified it slightly and stuck it up as a PR at #9726 to get some feedback from the team on it 🙂

@richvdh
Copy link
Member

richvdh commented Apr 16, 2021

@imaspeer out of interest, what is the usecase for hosting synapse at a sub-path? This came up in another context and I'm interested to know if there are important reasons we should support it.

@callahad
Copy link
Contributor

After discussion today: we're inclined to fix this for you by merging #9726, but we have no intention of formally supporting Synapse on a subpath :)

We would love to know more about your use case, though!

anoadragon453 added a commit that referenced this issue Apr 23, 2021
Applied a (slightly modified) patch from #9574.

As far as I understand this would allow the cookie set during the OIDC flow to work on deployments using public baseurls that do not sit at the URL path root.
@anoadragon453
Copy link
Member

Closing this issue now that the patch has landed - but feel free to still comment here about your use case! This likely won't be the last thing to need fixing w.r.t hosting endpoints on subpaths :)

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
T-Enhancement New features, changes in functionality, improvements in performance, or user-facing enhancements.
Projects
None yet
Development

No branches or pull requests

4 participants