Skip to content
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

iframe for frontend logout gets blocked if a custom CSP header is used #24568

Closed
1 task done
rmartinc opened this issue Nov 6, 2023 · 1 comment · Fixed by #24577 or #29291
Closed
1 task done

iframe for frontend logout gets blocked if a custom CSP header is used #24568

rmartinc opened this issue Nov 6, 2023 · 1 comment · Fixed by #24577 or #29291

Comments

@rmartinc
Copy link
Contributor

rmartinc commented Nov 6, 2023

Before reporting an issue

  • I have read and understood the above terms for submitting issues, and I understand that my issue may be closed without action if I do not follow them.

Area

core

Describe the bug

When Front channel logout is configured for a oidc client the logout is performed using an iframe to call the client front-channel URL. For example in my sample client:

<li>
  sample-rhsso
  <iframe src="http://localhost:8081/sample-rhsso/logout?sid=310d5fbf-7df7-4d75-957d-46208cdb77c2&amp;iss=http%3A%2F%2Flocalhost%3A8080%2Frealms%2Fmaster" style="display:none;"></iframe>
</li>

The CSP header by default is modified to allow client URL in the iframe adding the hostname of the client backchannel URL to the frame-src poclicy. In my sample:

Content-Security-Policy: frame-src localhost:8081 ; object-src 'none';

If a custom CSP header is configured in the realm the frame-src is not modified and therefore the iframe is not called because it's not allowed. For example is I change my realm Realm Settings -> Security Defenses -> Content-Security-Policy to frame-src 'self'; frame-ancestors 'self'; object-src 'none'; style-src 'self';.

I'm just adding the style-src directive to the default CSP value but now the CSP received by the browser is:

Content-Security-Policy: frame-src 'self'; frame-ancestors 'self'; object-src 'none'; style-src 'self';

And the backchannel URL is not called because it's not allowed by the CSP. So the client is not logged out.

Version

22.0.5

Expected behavior

I think we need a more intelligent design of the CSP header. I would do the following:

  • Manage frame-src and frame-ancestors independently of the other directives.
  • For frame-src add the hostnames needed to the current value defined by the realm (by default would be 'self' and transformed to 'self hostname1 hostname2...`.
  • For frame-ancestors remove the directive if and only if the default 'self' is in place. This modification is needed for the login iframe used by the JS adapter. If the administrator has modified the frame-ancestors it will be respected and not modified.

Actual behavior

If the CSP header is customized at realm level the modifications for frame-src and frame-ancestors are just not done. The logout or the iframe for login won't work.

How to Reproduce?

  1. Create an OIDC client with Front channel logout to ON and Front-channel logout URL configured.
  2. Test that by default the CSP and iframe is OK and the frontchannel URL is called.
  3. Modify the realm setting CSP to frame-src 'self'; frame-ancestors 'self'; object-src 'none'; style-src 'self';.
  4. Check the CSP is just sent as configured in the realm and the iframe URL is not called.

Anything else?

No response

@rmartinc rmartinc added kind/bug Categorizes a PR related to a bug status/triage labels Nov 6, 2023
@rmartinc
Copy link
Contributor Author

rmartinc commented Nov 6, 2023

Related issue: #14203

@rmartinc rmartinc self-assigned this Nov 6, 2023
rmartinc added a commit to rmartinc/keycloak that referenced this issue Nov 6, 2023
@rmartinc rmartinc added this to the 25.0.0 milestone Feb 7, 2024
@keycloak-github-bot keycloak-github-bot bot added priority/important Must be worked on very soon and removed action/priority-important labels Mar 1, 2024
rmartinc added a commit to rmartinc/keycloak that referenced this issue Apr 5, 2024
rmartinc added a commit to rmartinc/keycloak that referenced this issue Apr 5, 2024
rmartinc added a commit to rmartinc/keycloak that referenced this issue Apr 5, 2024
Closes keycloak#24568

Signed-off-by: rmartinc <rmartinc@redhat.com>
mposolda pushed a commit that referenced this issue Apr 8, 2024
Closes #24568

Signed-off-by: rmartinc <rmartinc@redhat.com>
rmartinc added a commit to rmartinc/keycloak that referenced this issue Apr 17, 2024
Closes keycloak#24568

Signed-off-by: rmartinc <rmartinc@redhat.com>
(cherry picked from commit 2b769e5)
rmartinc added a commit to rmartinc/keycloak that referenced this issue Apr 17, 2024
Closes keycloak#24568

Signed-off-by: rmartinc <rmartinc@redhat.com>
(cherry picked from commit 2b769e5)
mposolda pushed a commit that referenced this issue Apr 18, 2024
Closes #24568

Signed-off-by: rmartinc <rmartinc@redhat.com>
(cherry picked from commit 2b769e5)
mposolda pushed a commit that referenced this issue Apr 18, 2024
Closes #24568

Signed-off-by: rmartinc <rmartinc@redhat.com>
(cherry picked from commit 2b769e5)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
3 participants