-
Notifications
You must be signed in to change notification settings - Fork 5.9k
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 possible ArrayIndexOutOfBoundsException in XorCsrfTokenRequestAtt… #14976
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -56,13 +56,16 @@ static String getTokenValue(String actualToken, String token) { | |
System.arraycopy(actualBytes, randomBytesSize, xoredCsrf, 0, tokenSize); | ||
|
||
byte[] csrfBytes = xorCsrf(randomBytes, xoredCsrf); | ||
return Utf8.decode(csrfBytes); | ||
return (csrfBytes != null) ? Utf8.decode(csrfBytes) : null; | ||
} | ||
|
||
private static byte[] xorCsrf(byte[] randomBytes, byte[] csrfBytes) { | ||
static byte[] xorCsrf(byte[] randomBytes, byte[] csrfBytes) { | ||
if (csrfBytes.length < randomBytes.length) { | ||
return null; | ||
} | ||
int len = Math.min(randomBytes.length, csrfBytes.length); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Hi, There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||
byte[] xoredCsrf = new byte[len]; | ||
System.arraycopy(csrfBytes, 0, xoredCsrf, 0, csrfBytes.length); | ||
System.arraycopy(csrfBytes, 0, xoredCsrf, 0, len); | ||
for (int i = 0; i < len; i++) { | ||
xoredCsrf[i] ^= randomBytes[i]; | ||
} | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
don't you want to assert that these values equals?
if the
randomBytes
will be larger there is no downside but if thecsrfBytes
is longer then there might be a condition where some bytes of the csrf token is not xoredThere was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for your comments on this PR @roysav13! I will be addressing this comment in a separate fix. See gh-15184.