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 possible ArrayIndexOutOfBoundsException in XorCsrfTokenRequestAtt… #14976

Closed
wants to merge 1 commit into from

Conversation

kratosmy
Copy link

To fix gh-#13310, I make a hotfix to ensure that System.arraycopy() won't cause a ArrayIndexOutOfBoundsException.

static byte[] xorCsrf(byte[] randomBytes, byte[] csrfBytes) {
if (csrfBytes.length < randomBytes.length) {
return null;
}
int len = Math.min(randomBytes.length, csrfBytes.length);
Copy link

Choose a reason for hiding this comment

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

Hi,
Isn't the value of randomBytes.length will always be smaller or equals to the value of csrfBytes.length?
If so you can remove the usage of the min fucntion and just call the value

Copy link
Member

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.

}

private static byte[] xorCsrf(byte[] randomBytes, byte[] csrfBytes) {
static byte[] xorCsrf(byte[] randomBytes, byte[] csrfBytes) {
if (csrfBytes.length < randomBytes.length) {
Copy link

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 the csrfBytes is longer then there might be a condition where some bytes of the csrf token is not xored

Copy link
Member

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.

@sjohnr
Copy link
Member

sjohnr commented May 31, 2024

@kratosmy thanks for submitting this PR! I appreciate your work in helping resolve this issue. However, after taking a deeper look at the original issue and fix as well as this additional fix, the resulting behavior isn't consistent and the fix can be improved. Since this is a fairly subtle and complex issue, I have decided to fix the issue myself in a separate commit and backport the fix to older OSS supported branches.

Since I won't be directly re-using either the fix or the tests you provided, I am unfortunately going to close this PR as declined. However, I again want to reiterate that your work is appreciated and was instrumental in helping resolve this issue. Thanks for your contribution!

@sjohnr sjohnr closed this May 31, 2024
@sjohnr sjohnr added in: messaging An issue in spring-security-messaging in: web An issue in web modules (web, webmvc) type: bug A general bug status: declined A suggestion or change that we don't feel we should currently apply and removed status: waiting-for-triage An issue we've not yet triaged labels May 31, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
in: messaging An issue in spring-security-messaging in: web An issue in web modules (web, webmvc) status: declined A suggestion or change that we don't feel we should currently apply type: bug A general bug
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants