mirror of
https://github.com/qaiu/netdisk-fast-download.git
synced 2026-12-02 09:53:59 +00:00
fix: mitigate Java4Shell in Base64 decoders and containers
This commit is contained in:
1 parent
b6922b152f
commit
8c07c6e657
17 files changed
+231
-22
No files matched your search
@@ -2,6 +2,7 @@ package cn.qaiu.lz.common.util;
|
||||
|
||||
import cn.qaiu.lz.web.model.AuthParam;
|
||||
import cn.qaiu.util.AESUtils;
|
||||
import cn.qaiu.util.Base64Decoder;
|
||||
import cn.qaiu.vx.core.util.SharedDataUtil;
|
||||
import io.vertx.core.json.JsonObject;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
@@ -9,7 +10,6 @@ import org.apache.commons.lang3.StringUtils;
|
||||
|
||||
import java.net.URLDecoder;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.util.Base64;
|
||||
|
||||
/**
|
||||
* 认证参数编解码工具类
|
||||
@@ -88,7 +88,7 @@ public class AuthParamCodec {
|
||||
log.debug("认证参数规范化结果: {}", normalized);
|
||||
|
||||
// Step 2: Base64解码
|
||||
byte[] base64Decoded = Base64.getDecoder().decode(normalized);
|
||||
byte[] base64Decoded = Base64Decoder.decode(normalized);
|
||||
log.debug("Base64解码成功,长度: {}", base64Decoded.length);
|
||||
|
||||
// Step 3: AES解密
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
package cn.qaiu.lz.common.util;
|
||||
|
||||
import cn.qaiu.util.Base64Decoder;
|
||||
import cn.qaiu.lz.web.model.SysUser;
|
||||
import io.vertx.core.json.JsonObject;
|
||||
|
||||
@@ -102,7 +103,7 @@ public class JwtUtil {
|
||||
}
|
||||
|
||||
// 验证过期时间
|
||||
String payload = new String(Base64.getUrlDecoder().decode(encodedPayload), StandardCharsets.UTF_8);
|
||||
String payload = new String(Base64Decoder.decodeUrl(encodedPayload), StandardCharsets.UTF_8);
|
||||
JsonObject payloadJson = new JsonObject(payload);
|
||||
long expTime = payloadJson.getLong("exp", 0L);
|
||||
|
||||
@@ -125,7 +126,7 @@ public class JwtUtil {
|
||||
}
|
||||
|
||||
// Base64解码
|
||||
String payload = new String(Base64.getUrlDecoder().decode(parts[1]), StandardCharsets.UTF_8);
|
||||
String payload = new String(Base64Decoder.decodeUrl(parts[1]), StandardCharsets.UTF_8);
|
||||
JsonObject jsonObject = new JsonObject(payload);
|
||||
return jsonObject.getString("id");
|
||||
}
|
||||
@@ -143,7 +144,7 @@ public class JwtUtil {
|
||||
}
|
||||
|
||||
// Base64解码
|
||||
String payload = new String(Base64.getUrlDecoder().decode(parts[1]), StandardCharsets.UTF_8);
|
||||
String payload = new String(Base64Decoder.decodeUrl(parts[1]), StandardCharsets.UTF_8);
|
||||
JsonObject jsonObject = new JsonObject(payload);
|
||||
return jsonObject.getString("username");
|
||||
}
|
||||
@@ -161,7 +162,7 @@ public class JwtUtil {
|
||||
}
|
||||
|
||||
// Base64解码
|
||||
String payload = new String(Base64.getUrlDecoder().decode(parts[1]), StandardCharsets.UTF_8);
|
||||
String payload = new String(Base64Decoder.decodeUrl(parts[1]), StandardCharsets.UTF_8);
|
||||
JsonObject jsonObject = new JsonObject(payload);
|
||||
return jsonObject.getString("role");
|
||||
}
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
package cn.qaiu.lz.common.util;
|
||||
|
||||
import cn.qaiu.util.Base64Decoder;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.security.MessageDigest;
|
||||
import java.security.NoSuchAlgorithmException;
|
||||
@@ -72,7 +73,7 @@ public class PasswordUtil {
|
||||
String hashBase64 = parts[1];
|
||||
|
||||
// 解码盐
|
||||
byte[] salt = Base64.getDecoder().decode(saltBase64);
|
||||
byte[] salt = Base64Decoder.decode(saltBase64);
|
||||
|
||||
// 使用相同的盐计算哈希值
|
||||
MessageDigest md = MessageDigest.getInstance(ALGORITHM);
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
package cn.qaiu.lz.web.service.impl;
|
||||
|
||||
import cn.qaiu.util.Base64Decoder;
|
||||
import cn.qaiu.db.pool.JDBCPoolInit;
|
||||
import cn.qaiu.lz.common.model.UserInfo;
|
||||
import cn.qaiu.lz.web.model.StatisticsInfo;
|
||||
@@ -526,7 +527,7 @@ public class DbServiceImpl implements DbService {
|
||||
|
||||
private boolean isLikelyEncrypted(String value) {
|
||||
try {
|
||||
byte[] decoded = Base64.getDecoder().decode(value);
|
||||
byte[] decoded = Base64Decoder.decode(value);
|
||||
return decoded.length > 16;
|
||||
} catch (Exception e) {
|
||||
return false;
|
||||
@@ -538,8 +539,8 @@ public class DbServiceImpl implements DbService {
|
||||
throw new IllegalArgumentException("invalid donated account token");
|
||||
}
|
||||
String[] parts = token.split("\\.", 2);
|
||||
String payload = new String(Base64.getUrlDecoder().decode(parts[0]), StandardCharsets.UTF_8);
|
||||
String signature = new String(Base64.getUrlDecoder().decode(parts[1]), StandardCharsets.UTF_8);
|
||||
String payload = new String(Base64Decoder.decodeUrl(parts[0]), StandardCharsets.UTF_8);
|
||||
String signature = new String(Base64Decoder.decodeUrl(parts[1]), StandardCharsets.UTF_8);
|
||||
String expected = hmacSha256(payload);
|
||||
if (!expected.equals(signature)) {
|
||||
throw new IllegalArgumentException("donated account token signature invalid");
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
package cn.qaiu.lz.web.util;
|
||||
|
||||
import cn.qaiu.util.Base64Decoder;
|
||||
import cn.qaiu.vx.core.util.ConfigUtil;
|
||||
import cn.qaiu.vx.core.util.VertxHolder;
|
||||
import io.vertx.core.Future;
|
||||
@@ -81,7 +82,7 @@ public class CryptoUtil {
|
||||
}
|
||||
return secretKeyFuture.compose(secretKey -> {
|
||||
try {
|
||||
byte[] decodedBytes = Base64.getDecoder().decode(strToDecrypt);
|
||||
byte[] decodedBytes = Base64Decoder.decode(strToDecrypt);
|
||||
|
||||
// Extract IV from the beginning of the decoded bytes
|
||||
ByteBuffer byteBuffer = ByteBuffer.wrap(decodedBytes);
|
||||
|
||||
@@ -0,0 +1,40 @@
|
||||
package cn.qaiu.lz.common.util;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
import java.net.URLEncoder;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.util.Base64;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertFalse;
|
||||
import static org.junit.Assert.assertNull;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
|
||||
public class Base64CompatibilityTest {
|
||||
@Test
|
||||
public void acceptsStoredPasswordHash() {
|
||||
String password = "密码-test";
|
||||
String hash = PasswordUtil.hashPassword(password);
|
||||
assertTrue(PasswordUtil.checkPassword(password, hash));
|
||||
assertFalse(PasswordUtil.checkPassword("wrong", hash));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void acceptsJwtWithUnpaddedUrlSafePayload() {
|
||||
String json = "{\"username\":\"下载用户\"}";
|
||||
String payload = Base64.getUrlEncoder().withoutPadding().encodeToString(json.getBytes(StandardCharsets.UTF_8));
|
||||
assertEquals("下载用户", JwtUtil.getUsernameFromToken("header." + payload + ".signature"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void acceptsLegacyEncodedAuth() throws Exception {
|
||||
String key = "0123456789abcdef";
|
||||
String json = "{\"authType\":\"cookie\",\"token\":\"compatibility-test\"}";
|
||||
String base64 = cn.qaiu.util.AESUtils.encryptBase64ByAES(json, key);
|
||||
String urlEncoded = URLEncoder.encode(base64, StandardCharsets.UTF_8);
|
||||
assertEquals("cookie", AuthParamCodec.decode(urlEncoded, key).getAuthType());
|
||||
assertEquals("cookie", AuthParamCodec.decode(base64.replace('+', ' '), key).getAuthType());
|
||||
assertNull(AuthParamCodec.decode(base64 + "!", key));
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user