Skip to content

Use org.keycloak.common.util.Base64Url to encode/decode clientID - #15736

Merged
hmlnarik merged 1 commit into
keycloak:mainfrom
douph1:#15734_base64url_1
Dec 8, 2022
Merged

hmlnarik merged 1 commit into
keycloak:mainfrom
douph1:#15734_base64url_1

Conversation

@douph1

@douph1 douph1 commented Nov 29, 2022 •

Copy link
Copy Markdown
Contributor

fix #15734
related #10227 #10231

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Istn't the .replace("=", "");missing here?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

no, as the the method already take the part before the first "="
(see comment)

public static String encodeBase64ToBase64Url(String base64) {
    String s = base64.split("=")[0]; // Remove any trailing '='s
    s = s.replace('+', '-'); // 62nd char of encoding
    s = s.replace('/', '_'); // 63rd char of encoding
    return s;
}

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

You are right, I haven't checked that. I just compared it to https://github.com/keycloak/keycloak/pull/15735/files but apparently standard Java does not remove trailing =?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

true, standard java doesn't, but since we know the boundaries from the base64, we don't need to keep the = for padding

Java 17 always use padding by default :
padding

but provide a way to disable it

java_no_padding

@ahus1

ahus1 commented Dec 5, 2022

Copy link
Copy Markdown
Member

Pinging @hmlnarik - I'm starting to review this.

@ahus1

ahus1 commented Dec 5, 2022 •

Copy link
Copy Markdown
Member

Hi @douph1 - could you please update the initial comment/description of this PR to not include backticks? When you do this, GitHub should link this PR to the original issue as "fix" would then be recognized as a keyword, see https://docs.github.com/en/issues/tracking-your-work-with-issues/linking-a-pull-request-to-an-issue

Thanks!

@ahus1
ahus1 self-requested a review December 5, 2022 11:45

@ahus1 ahus1 left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I reviewed the change and it looks good to me. Thanks for adding another unit test for me. All builds are green, approving it.

@ahus1

ahus1 commented Dec 5, 2022

Copy link
Copy Markdown
Member

Hi @hmlnarik - this IMHO ready to be merged. As you've been involved in the original issue, I'd ask you to merge this. Thanks!

@hmlnarik hmlnarik left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Thanks for the fix!

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.

clientID are base64 encoded in state uri param with non URI friendly base64

4 participants