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

Empty CSP header value breaks security filter #29458

Closed
2 tasks done
pschichtel opened this issue May 10, 2024 · 0 comments · Fixed by #29467
Closed
2 tasks done

Empty CSP header value breaks security filter #29458

pschichtel opened this issue May 10, 2024 · 0 comments · Fixed by #29467
Assignees
Labels
area/authentication Indicates an issue on Authentication area kind/bug Categorizes a PR related to a bug kind/regression priority/important Must be worked on very soon release/24.0.5 release/25.0.0 team/core-clients

Comments

@pschichtel
Copy link
Contributor

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

authentication

Describe the bug

When a realm doesn't have a CSP header configured under "Security Defenses", then all login-related pages fail with an HTTP 500.

The logs contains the following when the default log level is increased:

2024-05-10 21:51:49,949 ERROR [io.quarkus.vertx.http.runtime.QuarkusErrorHandler] (executor-thread-8) HTTP Request to /auth/realms/realm-name/protocol/openid-connect/3p-cookies/step1.html failed, error id: 5b1c2c8a-a315-42d8-9ce4-7d1c25fa6f52-27: java.lang.NullPointerException: Cannot invoke "Object.toString()" because the return value of "jakarta.ws.rs.core.MultivaluedMap.getFirst(Object)" is null
  at org.keycloak.headers.DefaultSecurityHeadersProvider.addHtmlHeaders(DefaultSecurityHeadersProvider.java:110)
  at org.keycloak.headers.DefaultSecurityHeadersProvider.addHeaders(DefaultSecurityHeadersProvider.java:81)
  at org.keycloak.services.filters.KeycloakSecurityHeadersFilter.filter(KeycloakSecurityHeadersFilter.java:43)
  at org.jboss.resteasy.reactive.server.handlers.ResourceResponseFilterHandler.handle(ResourceResponseFilterHandler.java:25)
  at io.quarkus.resteasy.reactive.server.runtime.QuarkusResteasyReactiveRequestContext.invokeHandler(QuarkusResteasyReactiveRequestContext.java:150)
  at org.jboss.resteasy.reactive.common.core.AbstractResteasyReactiveContext.run(AbstractResteasyReactiveContext.java:147)
  at io.quarkus.vertx.core.runtime.VertxCoreRecorder$14.runWith(VertxCoreRecorder.java:582)
  at org.jboss.threads.EnhancedQueueExecutor$Task.run(EnhancedQueueExecutor.java:2513)
  at org.jboss.threads.EnhancedQueueExecutor$ThreadBody.run(EnhancedQueueExecutor.java:1538)
  at org.jboss.threads.DelegatingRunnable.run(DelegatingRunnable.java:29)
  at org.jboss.threads.ThreadLocalResettingRunnable.run(ThreadLocalResettingRunnable.java:29)
  at io.netty.util.concurrent.FastThreadLocalRunnable.run(FastThreadLocalRunnable.java:30)
  at java.base/java.lang.Thread.run(Thread.java:840)

ContentSecurityPolicyBuilder csp = ContentSecurityPolicyBuilder.create(
headers.getFirst(CONTENT_SECURITY_POLICY.getHeaderName()).toString());

this section is missing the check for non-null value that e.g. the addHeader() method has. 047e804 introduced this error.

Version

24.0.4

Regression

  • The issue is a regression

Expected behavior

CSP header can be left blank and login still works albeit less securely.

Actual behavior

Login-related pages (realm login page, step1.html and possibly more) fail with HTTP 500.

How to Reproduce?

  1. Create a realm
  2. Remove the default value of the CSP
  3. Try logging in to that realm

Anything else?

The affected realm in our deployment had this header cleared many releases go and it just started failing with one of the 24.0.* releases.

@pschichtel pschichtel added kind/bug Categorizes a PR related to a bug status/triage labels May 10, 2024
@keycloak-github-bot keycloak-github-bot bot added area/authentication Indicates an issue on Authentication area team/core-clients labels May 10, 2024
@rmartinc rmartinc self-assigned this May 11, 2024
rmartinc added a commit to rmartinc/keycloak that referenced this issue May 11, 2024
Closes keycloak#29458

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

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

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

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

Signed-off-by: rmartinc <rmartinc@redhat.com>
(cherry picked from commit 2cc0513)
mposolda pushed a commit that referenced this issue May 13, 2024
Closes #29458

Signed-off-by: rmartinc <rmartinc@redhat.com>
(cherry picked from commit 2cc0513)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area/authentication Indicates an issue on Authentication area kind/bug Categorizes a PR related to a bug kind/regression priority/important Must be worked on very soon release/24.0.5 release/25.0.0 team/core-clients
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants