You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I am facing a strange issue. If I tweak the signature key with next couple of chars , validation is still successful. Shouldn't the validation fail if the signature is altered?
PS: I have tested with multiple secret keys and multiple tokens and the above behaviour exists.
Token Creation
public class ValidateJWTClaims {
public String createToken(String secretKey) {
SignatureAlgorithm signatureAlgorithm = SignatureAlgorithm.HS256;
Key key = new SecretKeySpec(secretKey.getBytes(), signatureAlgorithm.getJcaName());
JwtBuilder builder = Jwts.builder()
.setId("testId")
.setAudience("all")
.setIssuedAt(new Date(System.currentTimeMillis()))
.setSubject("testSubject")
.setIssuer("testOrg")
.signWith(key, signatureAlgorithm);
return builder.compact();
}
}
I am facing a strange issue. If I tweak the signature key with next couple of chars , validation is still successful. Shouldn't the validation fail if the signature is altered?
PS: I have tested with multiple secret keys and multiple tokens and the above behaviour exists.
Token Creation
public class ValidateJWTClaims {
public String createToken(String secretKey) {
SignatureAlgorithm signatureAlgorithm = SignatureAlgorithm.HS256;
Key key = new SecretKeySpec(secretKey.getBytes(), signatureAlgorithm.getJcaName());
JwtBuilder builder = Jwts.builder()
.setId("testId")
.setAudience("all")
.setIssuedAt(new Date(System.currentTimeMillis()))
.setSubject("testSubject")
.setIssuer("testOrg")
.signWith(key, signatureAlgorithm);
return builder.compact();
}
}
Signature Validation
@test
public void createTokenAndVerify() throws Exception{
secretKey = "jhakjdhflashdfjasdhfjkashdfjhsfuhjjkadfhl";
String jwt = validateJWTClaims.createToken(secretKey);
System.out.println(jwt);
String works = "eyJhbGciOiJIUzI1NiJ9.eyJqdGkiOiJ0ZXN0SWQiLCJhdWQiOiJhbGwiLCJpYXQiOjE1NDM5Mzc1MjIsInN1YiI6InRlc3RTdWJqZWN0IiwiaXNzIjoidGVzdE9yZyJ9.k0QyR_aHXREikUc25yQ1hLDox_NAdFxPgNQ42-eXEGQ";
// String works = "eyJhbGciOiJIUzI1NiJ9.eyJqdGkiOi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Q42-eXEGU";
Claims claims = validateJWTClaims.getClaims(works,secretKey);
System.out.println(gson.toJson(claims));
}
please note that if I manually change the signature part's end char to something else , for some instances validation is still successful.
The text was updated successfully, but these errors were encountered: