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

What is the difference between actualToken and token in the getTokenValue method, and why does the value I pass in keep returning null #181

Open
mhiStrat opened this issue Jul 29, 2023 · 1 comment

Comments

@mhiStrat
Copy link

mhiStrat commented Jul 29, 2023

spring security version: 6.1.2
spring boot version :3.1.2

XorCsrfTokenRequestAttributeHandler class method getTokenValue

` public String resolveCsrfTokenValue(HttpServletRequest request, CsrfToken csrfToken) {
String actualToken = super.resolveCsrfTokenValue(request, csrfToken);
return getTokenValue(actualToken, csrfToken.getToken());
}

private static String getTokenValue(String actualToken, String token) {
    byte[] actualBytes;
    try {
        actualBytes = Base64.getUrlDecoder().decode(actualToken);
    } catch (Exception var9) {
        return null;
    }

    byte[] tokenBytes = Utf8.encode(token);
    int tokenSize = tokenBytes.length;
   if (actualBytes.length < tokenSize) {
        return null;
    }else {
        int randomBytesSize = actualBytes.length - tokenSize;
        byte[] xoredCsrf = new byte[tokenSize];
        byte[] randomBytes = new byte[randomBytesSize];
        System.arraycopy(actualBytes, 0, randomBytes, 0, randomBytesSize);
        System.arraycopy(actualBytes, randomBytesSize, xoredCsrf, 0, tokenSize);
        byte[] csrfBytes = xorCsrf(randomBytes, xoredCsrf);
        return Utf8.decode(csrfBytes);
    }
}`

Judgment has been entered into this code,
if (actualBytes.length < tokenSize) {
return null;
}
want to ask what is the difference between this method parameter

@dodgex
Copy link

dodgex commented Aug 4, 2024

You should ask this in https://github.com/spring-projects/spring-security as the class you mentioned is not part of spring-security-kerberos but of spring-security-web

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

No branches or pull requests

2 participants