shiro反序列化漏洞修复

  • Post author:
  • Post category:其他


新建一个类

public class GenerateCipherKey {

    /**
     * 随机生成秘钥,参考org.apache.shiro.crypto.AbstractSymmetricCipherService#generateNewKey(int)
     * @return
     */
    public static byte[] generateNewKey() {
        KeyGenerator kg;
        try {
            kg = KeyGenerator.getInstance("AES");
        } catch (NoSuchAlgorithmException var5) {
            String msg = "Unable to acquire AES algorithm.  This is required to function.";
            throw new IllegalStateException(msg, var5);
        }

        kg.init(128);
        SecretKey key = kg.generateKey();
        byte[] encoded = key.getEncoded();
        return encoded;
    }
}

修改shiro配置文件,要自己改一下里面的包名

<bean id="rememberMeManager" class="org.apache.shiro.web.mgt.CookieRememberMeManager">
    <property name="cipherKey" value="#{T(com.xxx.xxx.xxx.xxx.GenerateCipherKey).generateNewKey()}"></property>
    <property name="cookie" ref="rememberMe"></property>
</bean>