question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

KEYCLOAK_SESSION not working for some user federation setups

See original GitHub issue

Describe the bug

In some cases with user federation, the ID of the user can contain some special characters. For example when configured LDAP provider with “Import Users” set to OFF and with “UUID LDAP Attribute” set to “uid” . Then when you have some user with special character in the “uid”, this is in turn used as the ID of the user. And this is saved in the KEYCLOAK_SESSION cookie:

KEYCLOAK_SESSION=**:spécial.char/**; 
KEYCLOAK_SESSION_LEGACY=***; 

The character “é” is present in the cookie name, which is not allowed by the undertow server. In the log is this (likely when accessing Keycloak from some Javascript application when the particular user with special character is logged):

ERROR [io.undertow.request] (default task-2) UT005023: Exception handling request to /auth/realms/defence-intra/protocol
/openid-connect/login-status-iframe.html: java.lang.IllegalArgumentException: UT000173: An invalid control character [233] was 
present in the cookie value or attribute

Version

19.0.1

Anything else?

For the fix, it is probably easiest to Base64Url encode the cookie KEYCLOAK_SESSION (and maybe some other related cookies, not yet sure for which of them is this applicable) to make sure that there are not special characters in these cookies.

Issue Analytics

  • State:closed
  • Created a year ago
  • Comments:5 (5 by maintainers)

github_iconTop GitHub Comments

1reaction
mposoldacommented, Sep 23, 2022

@pedro-hos I’ve did some digging and ended up creating alternative PR for this - https://github.com/keycloak/keycloak/pull/14560 . It uses URL Encoding instead of Base64Url just for the backwards compatibility (although Base64Url will probably work as well).

1reaction
pedro-hoscommented, Sep 14, 2022

Hi @mposolda I see now that you suggested using Base64Url, I can change my implementation if necessary. I create a StringUtils under server-spi. Another questio, I don’t know if this fix also the KEYCLOAK_SESSION_LEGACY. Let me know if I need to change somewhere else.

Thanks Marek!

Read more comments on GitHub >

github_iconTop Results From Across the Web

Server Administration Guide - Keycloak
Setup of Kerberos server; Setup and configuration of Keycloak ... User Federation - Sync users from LDAP and Active Directory servers.
Read more >
User Federation Troubles - Getting advice - Keycloak Discourse
I have a bind DN with a domain Admin account. I was able to sync all user/s to Keycloak and no problems occurred....
Read more >
Keycloak custom user storage not displaying attributes
It works all in the correct way except for a prticular. When I go to the users page in the admin console and...
Read more >
Using Custom User Providers with Keycloak - Baeldung
In this tutorial, we'll show how to add a custom provider to Keycloak, a popular open-source identity management solution, so we can use...
Read more >
Chapter 7. User Storage SPI - Red Hat Customer Portal
They are not enabled by default, but instead must be enabled and configured per realm under the User Federation tab in the administration...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found