【问题标题】:Does spring security JWT implementation deal with alg:none attack? [closed]spring security JWT 实现是否处理 alg:none 攻击? [关闭]
【发布时间】:2019-08-17 18:53:23
【问题描述】:

JWT 实现可能会受到不同的攻击,其中之一是 alg:none 攻击(查看更多详细信息 here)。

我在 pom.xml 文件中使用了 spring-security-jwt 依赖项,但无法确定此实现是否处理 alg:none 攻击。

spring security JWT 实现是否缓解了这种攻击?

【问题讨论】:

    标签: spring spring-security jwt spring-security-rest


    【解决方案1】:

    如果您使用的是 spring-security-oauth/spring-security-jwt 那么是的,这种攻击得到了缓解。根据您共享的链接,减轻这种攻击的一种方法是考虑将带有 "alg":"none" 标头的 JWT 令牌视为无效或在选择算法时不依赖 alg 标头。

    在spring-security-jwt文件JwtHelper的源代码中decode方法在选择算法时不依赖alg标头。

    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 并报告您认为需要修补的任何漏洞。

    【讨论】:

      猜你喜欢
      • 2015-06-26
      • 2018-03-05
      • 1970-01-01
      • 2014-08-07
      • 2011-06-18
      • 2013-10-17
      • 1970-01-01
      • 2020-09-23
      • 1970-01-01
      相关资源
      最近更新 更多