Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Conversation

@jonkoops
Copy link
Contributor

@jonkoops jonkoops commented Oct 2, 2024

Closes #33330

Adds a shim for the Web Crypto API to admin and account console so they continue to work, even when being served from an non-secure context. This moves the polyfilling responsibility to Keycloak rather than Keycloak JS.

@jonkoops jonkoops requested review from a team as code owners October 2, 2024 14:43
edewit
edewit previously approved these changes Oct 2, 2024
@shawkins shawkins self-requested a review October 2, 2024 15:03
shawkins
shawkins previously approved these changes Oct 2, 2024
Copy link
Contributor

@shawkins shawkins left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM - we have similar logic to SecureContextResolver in SslRequired. SslRequired potentially does a DNS lookup to resolve the InetAddress. It might be good as a follow up to consolidate this logic - granted we'll probably be deprecating the SslRequired setting soon. cc @ahus1

@jonkoops
Copy link
Contributor Author

jonkoops commented Oct 2, 2024

It might be good as a follow up to consolidate this logic - granted we'll probably be deprecating the SslRequired setting soon.

Sounds logical to me, I am not familiar with this code, so I don't know how much overlap there is. Let's log an issue to follow up on it 👍

@jonkoops jonkoops requested a review from ahus1 October 2, 2024 15:12
Copy link
Contributor

@douglaspalmer douglaspalmer left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@shawkins
Copy link
Contributor

shawkins commented Oct 2, 2024

It might be good as a follow up to consolidate this logic - granted we'll probably be deprecating the SslRequired setting soon.

Sounds logical to me, I am not familiar with this code, so I don't know how much overlap there is. Let's log an issue to follow up on it 👍

Ok, added #33484

@jonkoops
Copy link
Contributor Author

jonkoops commented Oct 2, 2024

Looks like the tests are failing because HtmlUnit is once again too dumb to interpret even the most basic JavaScript syntax. Sigh. I'll do some work to turn it into a caveman version.

keycloak-github-bot[bot]

This comment was marked as outdated.

@keycloak-github-bot

This comment was marked as outdated.

@jonkoops
Copy link
Contributor Author

jonkoops commented Oct 2, 2024

Ok, should be fixed now. @edewit @shawkins @douglaspalmer can I ask you for another review?

Copy link
Contributor

@douglaspalmer douglaspalmer left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

shawkins
shawkins previously approved these changes Oct 2, 2024
Copy link
Contributor

@shawkins shawkins left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

ahus1
ahus1 previously approved these changes Oct 2, 2024
Copy link
Contributor

@ahus1 ahus1 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm approving it as it solves the problem at hand. The warning message "Keycloak JS should only be used in a secure context" could be more specific. It doesn't contain any why, the "secure context" is a bit a vague as it requires the crypto API, and "should" is also off as it requires the crypto API (unless someone uses a shim, which is not mentioned here).

As the log message is normally not shown (only if you enable logging for the JS library), I would be ok to continue as is for the sake of KC26.

One small wording in the upgrading guide. Might be worth adding it to the release notes as well.

keycloak-github-bot[bot]

This comment was marked as off-topic.

@keycloak-github-bot

This comment was marked as off-topic.

@jonkoops jonkoops dismissed stale reviews from ahus1 and shawkins via f42ca0c October 2, 2024 17:03
Copy link
Contributor

@ahus1 ahus1 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you for updating the release notes.

Approving with the same comment as before: "I'm approving it as it solves the problem at hand. The warning message "Keycloak JS should only be used in a secure context" could be more specific. It doesn't contain any why, the "secure context" is a bit a vague as it requires the crypto API, and "should" is also off as it requires the crypto API (unless someone uses a shim, which is not mentioned here).
As the log message is normally not shown (only if you enable logging for the JS library), I would be ok to continue as is for the sake of KC26."

@jonkoops
Copy link
Contributor Author

jonkoops commented Oct 2, 2024

Sorry I missed your comment @ahus1, let me reply here.

The warning message "Keycloak JS should only be used in a secure context" could be more specific. It doesn't contain any why, the "secure context" is a bit a vague as it requires the crypto API, and "should" is also off as it requires the crypto API (unless someone uses a shim, which is not mentioned here).

Agreed. The URL in the message explains that some APIs are not available in the browser if not in a secure context. But we could do a better job, but I think that will suffice for now.

This is not specifically about the Web Crypto API, but about a whole sub-set of APIs that are only available in a secure context that we might want make use of in the future. For example, the new cookie store APIs and possibly the FedCM API. Hence I don't want to advise the user to polyfill/shim this behaviour, as that could break in unexpected manners in the future.

The Web Crypto API is only used in PKCE flows (which is the default but can be opted out of), if it is not enabled the Web Crypto API is not used. Hence it is not a hard requirement in all scenarios.

@jonkoops
Copy link
Contributor Author

jonkoops commented Oct 3, 2024

The Web Crypto API is only used in PKCE flows (which is the default but can be opted out of), if it is not enabled the Web Crypto API is not used. Hence it is not a hard requirement in all scenarios.

Upon closer inspection, we're also using the same API to generate UUIDs. We are however not using the appropriate crypto.randomUUID() method, but rather the crypto.getRandomValues() method as a seed to some custom logic. I'll make a follow up PR to improve this.

@jonkoops jonkoops enabled auto-merge (squash) October 3, 2024 10:17
@jonkoops jonkoops merged commit aacdf80 into keycloak:main Oct 3, 2024
@keycloak-github-bot

This comment was marked as off-topic.

keycloak-github-bot[bot]

This comment was marked as off-topic.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

flaky-test status/hold PR should not be merged. On hold for later. team/ui

Projects

None yet

Development

Successfully merging this pull request may close these issues.

"somethingWentWrong" when opening Keycloak URL in unsecure context

5 participants