-
-
Notifications
You must be signed in to change notification settings - Fork 250
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Cross-tenant requests are possible #526
Comments
Does using |
No, it doesn't help. I've added it to my options like this |
I think you need to limit the cookie scope to subdomain and also verify that the cookie is used on the correct subdomain afterwards somehow, because malicious user could take cookie from tenanta.ourdomain.com and use it on tenantb.ourdomain.com. I think the code simply has no knowledge that the cookie from tenanta is wrong when used on tenantb. |
Just an untested idea: According to https://github.com/bungle/lua-resty-session ( The cookie domain can be controlled with For the EDIT:
|
@zandbelt @oldium @bodewig I have just tried |
Just to be sure to prevent any surprises - the |
One additional note - omitting the
|
Not sure, if this is related, but since the recent update to 1.8 I am getting CORS related errors once my keycloak session needs to be refreshed. Here for example, grafana wants to pull fresh data but the OIDC session needs to be refreshed. So resty-openid redirects the browser to the keycloak auth backend and then the browser tries to preflight that domain for CORS rules via the 'OPTIONS' method. This then fails with 405 (Not allowed) Besides of the recent upgrade to resty-openidc 1.8, I did not change my setup: |
this then looks like something caused by lua-resty-session's behavioral changes between <=3.x and >= 4.x; it may be a setting that is configurable, hopefully someone else can answer that here or you could ask the question in the lua-resty-session project |
This makes sense. I will try to further investigate this in the near future. For the time being, I downgraded to 1.7.6-3 and all my problems went away. |
That is absolutely correct. There are new defaults for the
This is a behaviour change, so the
And a note - one interesting option is not yet documented, which is |
This looks like I only need to set the Same-Site policy from Lax to None to make subrequest working reliable again, I guess. I just wonder about the security impact here. |
I gave this second look with a great help of internet (MDN/CORS, RFC 6749...). Is this really a cookie/session problem? The question is what really happened... The URL we see in the screenshot is the auth endpoint, which means that it is the start of the Authorization Code Grant flow. This means that the token refresh failed for some reason, so you were redirected to the auth endpoint. We see the So Grafana tried to refresh shown data with background XHR request, the attempt to refresh the access token was made (or not?) and failed, so the full auth redirect was sent, which failed because it should be a browser page redirect, not XHR redirect. So it would be interesting to check why the token refresh failed actually. And one note: you probably have typo in your last comment, it should be |
@oldium Your analysis of the situation seems about on point. I myself do not understand, why this happens and unfortuantely, my workaround with SameSite = None did not work for long. |
It would be good if you would be able to collect DEBUG logs from Nginx running |
I just tested it with the mock OIDC server (I faked
Please be aware that the debug logs contain sensitive information (authorization header with password, access token, refresh token), so do not share it plain text without modifications to anybody! |
We have a multi-tenant setup where based on the subdomain in the URL a tenant is determined. Each tenant has his own Keycloak realm where he can authenticate. So when you do a request to tenanta.ourdomain.com, you authenticate at realm "tenanta" in Keycloak.
We use the default setting with cookies as session storage.
When you authenticate at tenanta, you get a cookie that holds the session information. However, if I do a request to tenantb and add this cookie of tenanta to the request, I am still authenticated.
Environment
Configuration
nginx.conf:
authentication.lua:
Minimized example
Expected behaviour
Step 3 resulting in a failed request, responding with a HTTP 302 or 401, depending on the configuration.
Actual behaviour
Step 3 responds with the requested resource, authentication went fine.
Additional
We figured we might make the session secret tenant specific, like in this nginx configuration:
Any request to tenantA results in a cookie encrypted with a session secret specific for tenantA, since it is part of the secret. A request like the one in step 3 would, when requesting to tenantB, then be decrypted with the wrong secret and automatically the request would fail.
This seemed to work at moments, but a lot of times it just authenticated fine for tenantB. So far we couldn't figure out what caused this unexpected behaviour.
Possible solutions:
opts
.The text was updated successfully, but these errors were encountered: