spring 安全 JWT 实现是否处理 alg:none 攻击?
Does spring security JWT implementation deal with alg:none attack?
JWT 实现可能会受到不同的攻击,其中之一是 alg:none
攻击(查看更多详细信息 here)。
我在我的 pom.xml 文件中使用 spring-security-jwt
依赖项,无法确定此实现是否处理 alg:none
攻击。
spring 安全 JWT 实施是否缓解了这种攻击?
如果您使用 spring-security-oauth/spring-security-jwt 那么是的,此攻击已得到缓解。根据您分享的 link,减轻这种攻击的一种方法是将 header 和 "alg":"none"
的 JWT 令牌视为无效或不依赖于 alg
header选择算法时。
在spring-security-jwt文件的源代码JwtHelper中decode
方法选择算法时不依赖alg
header
public static Jwt decode(String token) {
int firstPeriod = token.indexOf('.');
int lastPeriod = token.lastIndexOf('.');
if (firstPeriod <= 0 || lastPeriod <= firstPeriod) {
throw new IllegalArgumentException("JWT must have 3 tokens");
}
CharBuffer buffer = CharBuffer.wrap(token, 0, firstPeriod);
// TODO: Use a Reader which supports CharBuffer
JwtHeader header = JwtHeaderHelper.create(buffer.toString());
buffer.limit(lastPeriod).position(firstPeriod + 1);
byte[] claims = b64UrlDecode(buffer);
boolean emptyCrypto = lastPeriod == token.length() - 1;
byte[] crypto;
if (emptyCrypto) {
if (!"none".equals(header.parameters.alg)) {
throw new IllegalArgumentException(
"Signed or encrypted token must have non-empty crypto segment");
}
crypto = new byte[0];
}
else {
buffer.limit(token.length()).position(lastPeriod + 1);
crypto = b64UrlDecode(buffer);
}
return new JwtImpl(header, claims, crypto);
}
spring-security-jwt
中没有文档或漏洞汇编,但您可以检查 spring-security-jwt
下的问题 section 并报告您认为需要修补的任何漏洞。
JWT 实现可能会受到不同的攻击,其中之一是 alg:none
攻击(查看更多详细信息 here)。
我在我的 pom.xml 文件中使用 spring-security-jwt
依赖项,无法确定此实现是否处理 alg:none
攻击。
spring 安全 JWT 实施是否缓解了这种攻击?
如果您使用 spring-security-oauth/spring-security-jwt 那么是的,此攻击已得到缓解。根据您分享的 link,减轻这种攻击的一种方法是将 header 和 "alg":"none"
的 JWT 令牌视为无效或不依赖于 alg
header选择算法时。
在spring-security-jwt文件的源代码JwtHelper中decode
方法选择算法时不依赖alg
header
public static Jwt decode(String token) {
int firstPeriod = token.indexOf('.');
int lastPeriod = token.lastIndexOf('.');
if (firstPeriod <= 0 || lastPeriod <= firstPeriod) {
throw new IllegalArgumentException("JWT must have 3 tokens");
}
CharBuffer buffer = CharBuffer.wrap(token, 0, firstPeriod);
// TODO: Use a Reader which supports CharBuffer
JwtHeader header = JwtHeaderHelper.create(buffer.toString());
buffer.limit(lastPeriod).position(firstPeriod + 1);
byte[] claims = b64UrlDecode(buffer);
boolean emptyCrypto = lastPeriod == token.length() - 1;
byte[] crypto;
if (emptyCrypto) {
if (!"none".equals(header.parameters.alg)) {
throw new IllegalArgumentException(
"Signed or encrypted token must have non-empty crypto segment");
}
crypto = new byte[0];
}
else {
buffer.limit(token.length()).position(lastPeriod + 1);
crypto = b64UrlDecode(buffer);
}
return new JwtImpl(header, claims, crypto);
}
spring-security-jwt
中没有文档或漏洞汇编,但您可以检查 spring-security-jwt
下的问题 section 并报告您认为需要修补的任何漏洞。