fix: mitigate Java4Shell in Base64 decoders and containers

This commit is contained in:
qaiu committed 2026-11-20 18:29:17 +08:00
1 parent b6922b152f
commit 8c07c6e657
17 files changed
+231 -22

No files matched your search

@@ -6,6 +6,7 @@ import cn.qaiu.parser.PanBase;
import cn.qaiu.parser.PasswordLoginRisk;
import cn.qaiu.parser.TokenCache;
import cn.qaiu.util.CommonUtils;
import cn.qaiu.util.Base64Decoder;
import cn.qaiu.util.FileSizeConverter;
import cn.qaiu.util.YeShareHostUtil;
import io.vertx.core.Future;
@@ -23,7 +24,6 @@ import java.net.MalformedURLException;
import java.time.OffsetDateTime;
import java.time.format.DateTimeFormatter;
import java.util.ArrayList;
import java.util.Base64;
import java.util.List;
import java.util.Map;
import java.util.Random;
@@ -514,7 +514,7 @@ public class Ye2Tool extends PanBase {
return;
}
byte[] decodeByte = Base64.getDecoder().decode(params);
byte[] decodeByte = Base64Decoder.decode(params);
String downUrl2 = new String(decodeByte);
clientNoRedirects.getAbs(downUrl2).putHeaders(header).send().onSuccess(res3 -> {
@@ -4,6 +4,7 @@ import cn.qaiu.entity.FileInfo;
import cn.qaiu.entity.ShareLinkInfo;
import cn.qaiu.parser.PanBase;
import cn.qaiu.util.CommonUtils;
import cn.qaiu.util.Base64Decoder;
import cn.qaiu.util.FileSizeConverter;
import cn.qaiu.util.JsExecUtils;
import io.vertx.core.Future;
@@ -166,7 +167,7 @@ public class YeTool extends PanBase {
try {
Map<String, String> urlParams = CommonUtils.getURLParams(downURL);
String params = urlParams.get("params");
byte[] decodeByte = Base64.getDecoder().decode(params);
byte[] decodeByte = Base64Decoder.decode(params);
String downUrl2 = new String(decodeByte);
// 获取直链
@@ -219,12 +219,12 @@ public class AESUtils {
*/
public static String decryptByBase64AES(String encrypted, String keyString) throws IllegalBlockSizeException,
BadPaddingException, InvalidKeyException, NoSuchPaddingException, NoSuchAlgorithmException {
return decryptByAES(Base64.getDecoder().decode(encrypted), keyString);
return decryptByAES(Base64Decoder.decode(encrypted), keyString);
}
public static String decryptByBase64AES(String encrypted, Key key) throws IllegalBlockSizeException,
BadPaddingException, InvalidKeyException, NoSuchPaddingException, NoSuchAlgorithmException {
return decryptByAES(Base64.getDecoder().decode(encrypted), key);
return decryptByAES(Base64Decoder.decode(encrypted), key);
}
// ================================飞机盘Id解密========================================== //
@@ -0,0 +1,49 @@
package cn.qaiu.util;
/** Strict Base64 decoding without the HotSpot Base64 intrinsic (CVE-2026-114938). */
public final class Base64Decoder {
private static final String BASIC = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
private static final String URL_SAFE = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_";
private Base64Decoder() {
}
public static byte[] decode(String input) {
return decode(input, BASIC);
}
public static byte[] decodeUrl(String input) {
return decode(input, URL_SAFE);
}
private static byte[] decode(String input, String alphabet) {
int length = input.length();
int firstPadding = input.indexOf('=');
int dataLength = firstPadding < 0 ? length : firstPadding;
int remainder = dataLength % 4;
if (remainder == 1 || (firstPadding >= 0
&& (remainder == 0 || length % 4 != 0
|| length - dataLength != 4 - remainder
|| input.charAt(length - 1) != '='))) {
throw new IllegalArgumentException("Invalid Base64 padding or length");
}
byte[] decoded = new byte[dataLength / 4 * 3 + remainder * 6 / 8];
int buffer = 0;
int bits = 0;
int outputIndex = 0;
for (int i = 0; i < dataLength; i++) {
int value = alphabet.indexOf(input.charAt(i));
if (value < 0) {
throw new IllegalArgumentException("Invalid Base64 character");
}
buffer = (buffer << 6) | value;
bits += 6;
if (bits >= 8) {
bits -= 8;
decoded[outputIndex++] = (byte) (buffer >>> bits);
}
}
return decoded;
}
}
@@ -100,12 +100,12 @@ public class CommonUtils {
Exception last = null;
for (String candidate : new String[]{s, padBase64(s)}) {
try {
return new String(java.util.Base64.getUrlDecoder().decode(candidate), StandardCharsets.UTF_8);
return new String(Base64Decoder.decodeUrl(candidate), StandardCharsets.UTF_8);
} catch (Exception e) {
last = e;
}
try {
return new String(java.util.Base64.getDecoder().decode(candidate), StandardCharsets.UTF_8);
return new String(Base64Decoder.decode(candidate), StandardCharsets.UTF_8);
} catch (Exception e) {
last = e;
}