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

fix client admin rest call with empty secret #2571

Closed
wants to merge 2 commits into from
Closed

Conversation

strehle
Copy link
Member

@strehle strehle commented Oct 24, 2023

Empty client secret is allowed if client secret policy allows it.
Error says 1 char is needed, this is wrong

Why 2 validators, distinguish between user and client policy validation.

For users 1 minimum char for a password might be ok, for a client definitely not.
The empty secret should be treated as public, but we cannot disallow it.

Therefore, this here is a fix for a regression introduced with 76.22.0.

@cf-gitbot
Copy link

We have created an issue in Pivotal Tracker to manage this:

https://www.pivotaltracker.com/story/show/186322610

The labels on this github issue will be updated when the story is started.

Copy link
Member Author

@strehle strehle left a comment

Choose a reason for hiding this comment

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

inline

MessageResolver messageResolver) {
List<Rule> rules = new ArrayList<>();

//length is always a rule. We do not allow blank password
int minLength = Math.max(1, policy.getMinLength());
Copy link
Contributor

Choose a reason for hiding this comment

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

I don't understand this line. This seems to be the source of the problem. Why are we overriding the policy with this 1? This is what needs to be changed. If we want to enforce a minimum 1 policy, it should be in the policy.

Copy link
Member Author

Choose a reason for hiding this comment

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

Please check the history and you can also use an older UAA, but even if you run default client policy, means 0 as minimum secret is allowed you cannot have

uaac client add newclient --name xuaa --scope openid --authorized_grant_types password --autoapprove true --secret ''

We agree that the empty secret still should be allowed but with hard coded 1 this does not work.

For user passwords maybe and therefore I have divided the check into user and client validator.

Comment on lines +49 to +65
public static PasswordValidator secretValidator(GenericPasswordPolicy<?> policy,
MessageResolver messageResolver) {
return internalValidator(policy, 0, messageResolver);
}

public static PasswordValidator userValidator(GenericPasswordPolicy<?> policy,
MessageResolver messageResolver) {
return internalValidator(policy, 1, messageResolver);
}

public static PasswordValidator validator(GenericPasswordPolicy<?> policy,
private static PasswordValidator internalValidator(GenericPasswordPolicy<?> policy,
int minimumLength,
MessageResolver messageResolver) {
List<Rule> rules = new ArrayList<>();

//length is always a rule. We do not allow blank password
int minLength = Math.max(1, policy.getMinLength());
//length is always a rule. We do not allow blank password, but a blank secret
int minLength = Math.max(minimumLength, policy.getMinLength());
Copy link
Contributor

Choose a reason for hiding this comment

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

It really looks like this code should be in the PasswordValidator class.

Copy link
Member Author

Choose a reason for hiding this comment

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

the code is in the class. ,

I dont was change an existing beviour. Existing was. For a user password at least 1 character is needed.

Copy link
Contributor

Choose a reason for hiding this comment

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

For a user password at least 1 character is needed

This is ridiculous. A 1-character password and an empty password have literally the same level of security: none.
This line is completely useless.

@@ -82,8 +82,7 @@ public void validate(String clientSecret) throws InvalidClientSecretException {
clientSecretPolicy = zone.getConfig().getClientSecretPolicy();
}

PasswordValidator clientSecretValidator = validator(clientSecretPolicy,
Copy link
Contributor

Choose a reason for hiding this comment

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

Is this the source of the regression that was introduced recently? That we started validating client secrets?

Copy link
Member Author

Choose a reason for hiding this comment

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

no, the issue is seperate.

As mentioned before use an older UAA start it and run uaac to create an client with empty secret......

Copy link
Contributor

Choose a reason for hiding this comment

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

I don't want to reproduce the issue. I'm trying to find out what new code is the source of the problem. It seems to me like it should be documented in the fix, so that people understand what is going on.

Copy link
Member Author

Choose a reason for hiding this comment

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

well, after the fix, the documentation matches again, because it says
minLength defaults to 0, e.g. https://docs.cloudfoundry.org/api/uaa/version/76.23.0/index.html#identity-zones
But this was not the case

Empty client secret is allowed if client secret policy allows it.
Error says 1 char is needed, this is wrong

Why 2 validators, distinguish between user and client policy validation.

For users 1 minimum char for a password might be ok, for a client definitely not.
The empty secret should be treated as public, but we cannot disallow it.

Therefore, this here is a fix for a regression introduced with 76.22.0.
@strehle
Copy link
Member Author

strehle commented Oct 25, 2023

close this, related issue was #2570
do not use it, because we would have to touch the validator which is currently in-consistent from point of was documentations states and what it does in real

@strehle strehle closed this Oct 25, 2023
@strehle strehle deleted the fix/issue/2570 branch October 25, 2023 18:40
@cf-gitbot cf-gitbot added accepted Accepted the issue and removed delivered labels Nov 9, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
accepted Accepted the issue
Projects
Development

Successfully merging this pull request may close these issues.

4 participants