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

Use constant time comparison for client secret verification #1861

Merged

Conversation

xtremerui
Copy link
Contributor

@xtremerui xtremerui commented Nov 11, 2020

Overview:
This PR adds an option to Dex config to enable enforement of client secret encryption.
Use subtle.ConstantTImeCompare for client secret verification to prevent a potential timing acttack

What problem does it solve?:
The current implementation for checking client secret is by plain text comparison, which is vulnerable to timing attack. Using constant time comparison will mitigate the threat.

Thx!

Josh Winters and others added 2 commits March 20, 2021 20:05
- this assumes that the client is already bcrytped
when passed to dex. Similar to user passwords.

Signed-off-by: Josh Winters <jwinters@pivotal.io>
Co-authored-by: Vikram Yadav <vyadav@pivotal.io>
* if enabled, it will make sure client secret is bcrypted correctly
* if not, it falls back to old behaviour that allowing empty client
secret and comparing plain text, though now it will do
ConstantTimeCompare to avoid a timing attack.

So in either way it should provide more secure of client secret
verification.

Co-authored-by: Alex Surraci <suraci.alex@gmail.com>
Signed-off-by: Rui Yang <ruiya@vmware.com>
@xtremerui xtremerui force-pushed the pr/bcrypt-for-client-secret-sync branch from cbe0a17 to d658c24 Compare March 20, 2021 20:05
@tkleczek
Copy link
Contributor

tkleczek commented Apr 25, 2021

@xtremerui I agree that using subtle.ConstantTimeCompare protects against timing attack. But could you explain a little bit more how encrypting client secret gives additional safety?
Also, your PR seems not to take into consideration that public clients have no secret.

the client secret coming in should be hashed and the one in storage
is the one in plaintext

Signed-off-by: Rui Yang <ruiya@vmware.com>
@xtremerui
Copy link
Contributor Author

@tkleczek FYI I just pushed a commit to fix a bug in the comparison that client secret in request should be hashed and client secret in dex storage should be plain text. Though I don't think your question is specific on the implementation.

I agree, not liking a password that could be used widely, a client secret is mostly specific to the client. Though I think it doesn't hurt to provide a way to hide client secret in request in case some one doesn't want client secret to be exposed anyway.

For public client that has no secret, the original logic still applies. subtle.ConstantTimeCompare takes empty value so it allows client secret to be empty. Not sure about what you mean here. Could you clarify please?

Thx for commenting!

@tkleczek
Copy link
Contributor

@xtremerui

For public client that has no secret, the original logic still applies. subtle.ConstantTimeCompare takes empty value so it allows client secret to be empty. Not sure about what you mean here. Could you clarify please?

Not sure now, maybe I was mistaken.

Though I think it doesn't hurt to provide a way to hide client secret in request in case some one doesn't want client secret to be exposed anyway.

I think it hurts mostly in the additional code that has to be maintained and excessive options in configuration. I don't think you have to protect client secret in transit more than standard TLS does. OIDC standard also does not mention this "extension".

Btw, you might want to split this PR in two separate ones. I think using subtle.ConstantTimeCompare is has obvious advantages so it could hopefully go in quicker

@xtremerui
Copy link
Contributor Author

xtremerui commented May 17, 2021

Btw, you might want to split this PR in two separate ones. I think using subtle.ConstantTimeCompare is has obvious advantages so it could hopefully go in quicker

yes I think that makes sense.

In our own use case, concourse CLI is actually a public client and we have the client secret in OSS github code. So technically this PR is also an option for us but not a must.

I will update this PR to include only subtle.ConstanTimeCompare. Thx!

constant time compare for client secret verification will be kept

Signed-off-by: Rui Yang <ruiya@vmware.com>
@xtremerui xtremerui changed the title Add client secret encryption option Use constant time comparison for client secret verification May 17, 2021
@sagikazarmark sagikazarmark added this to the v2.29.0 milestone May 17, 2021
Copy link
Member

@sagikazarmark sagikazarmark left a comment

Choose a reason for hiding this comment

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

Thanks!

@sagikazarmark sagikazarmark merged commit 18d1f70 into dexidp:master May 17, 2021
@xtremerui xtremerui deleted the pr/bcrypt-for-client-secret-sync branch May 17, 2021 16:02
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants