Skip to content

The client secret in the database will become {bcrypt} secret when login. #1337

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

Closed
Waylon-Firework opened this issue Aug 20, 2023 · 9 comments
Assignees
Labels
status: invalid An issue that we don't feel is valid

Comments

@Waylon-Firework
Copy link

image

Step 1: register a client with {noop} secret.

mysql database
image

Step 2: login with oauth flow, the client secret in the database will become {bcrypt} secret.

http://localhost:9000/oauth2/authorize?response_type=code&client_id=message-client&scope=openid%20profile%20message.read&state=some-state&redirect_uri=http://127.0.0.1:8080/authorized

mysql database
image

@Waylon-Firework Waylon-Firework added the type: bug A general bug label Aug 20, 2023
@Waylon-Firework
Copy link
Author

Waylon-Firework commented Aug 20, 2023

When login api is triggered, the sql update client will be called and the client secret will be changed from {noop} to {bcrypt}

image image image

I'm curious why it's forcing me to change to {bcrypt} when login. Is there any way to prevent it.

@shanman190
Copy link
Contributor

Hi @Waylon-Firework! 👋

So I'll start with a little bit of a primer as to the feature that you're coming across here. Similar to the password upgrades that Spring Security users have come to know for end user accounts, this provides the same mechanisms for upgrading the security of the OAuth client credentials themselves. The framework uses the current encoding and strength, if applicable, to determine if the source secret that we have just confirmed is correct is in need of being upgraded. Upgraded in this context may mean changing the underlying encoding entirely or increasing the strength of the current algorithm. The way that this is triggered is by the current configured implementation of PasswordEncoder in use for your application.

Based upon what you have presented here so far, this leads me to know that the presently available PasswordEncoder in your app is the BcryptPasswordEncoder implementation. As such, the provider is interpreting that you want to upgrade the secret by changing the encoding type from noop to bcrypt with strength 10.

If you don't want for this to happen, in what I hope is your demo/testing app, then you just need to configure your application with the NoOpPasswordEncoder implementation. The NoOpPasswordEncoder implementation is for testing purposes as stated by the documentation here as it provides no secure storage of the credentials when it is at rest in the database. When this encoder encounters your secret, it will perform no actions as the encoding of the stored secret matches the current configured encoding type.

@Waylon-Firework
Copy link
Author

Thank you @shanman190 .

I added the {noop} password encoder and it works as expected.

But I feel that this update behavior should not be the default. Because it makes our key a secret. We will have to find its original value from the sql backup. Wouldn't it be better if it could be turned on with a configuration?

@Waylon-Firework
Copy link
Author

Anyway, it does come in handy for users who need to upgrade their security. However, it happened too suddenly. 😄

@shanman190
Copy link
Contributor

Would you mind expressing how this feature in particular is causing you an issue?

From an authentication standpoint, the same secret will still be used to authenticate and would result in a successful authentication.

@Waylon-Firework
Copy link
Author

Waylon-Firework commented Aug 21, 2023

@shanman190 Sure.

We have some external customers, we generate client_id, client_secret and limit scope for them. Customers can log in to our system, and they can see the client secret we generated for them from the page. Of course, to view it, they need to verify the email verification code.

Currently, the client secret stored in the database becomes a {bcrypt} secret when we upgrade the spring authorization server version. This prevents them from viewing the original client secret.

Moreover, as a server, we also cannot see the original secret when we upgrade the spring authorization server version, because {bcrypt} is difficult to crack. We will have to restore them from historical mysql data.

@Waylon-Firework
Copy link
Author

@shanman190
We also have a requirement, we hope that client secret password encoder and user's password encoder can be configured separately. Because the user's password requires {bcript}

@shanman190
Copy link
Contributor

So the password encoder can be configured separately for just for the OAuth piece presently via:

public OAuth2AuthorizationServerConfigurer clientAuthentication(Customizer<OAuth2ClientAuthenticationConfigurer> clientAuthenticationCustomizer) {

Personally for the other part, the use case really sounds more like the OIDC Dynamic Client registration flow which provides back the client secret on the response itself. This enables secure storage without compromising on the feature of being able to show the user the secret one time.
https://docs.spring.io/spring-authorization-server/docs/current/reference/html/protocol-endpoints.html#oidc-client-registration-endpoint

@Waylon-Firework
Copy link
Author

Waylon-Firework commented Aug 21, 2023

Thank you @shanman190 . That's great.
And for the client secret, when we go to register a google api, they will also give us a page that can be used to view the secret. I think I need to store them somewhere else. Because we really didn't expect that this would be adjusted for automatic updates. For my case, my server is a oidc provider.

@jgrandja jgrandja self-assigned this Aug 24, 2023
@jgrandja jgrandja added status: invalid An issue that we don't feel is valid and removed type: bug A general bug labels Aug 24, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
status: invalid An issue that we don't feel is valid
Projects
None yet
Development

No branches or pull requests

3 participants