jeecgboot/JeecgBoot · warning · IllegalArgumentException
非法IPv4地址: {ip}
Error message
非法IPv4地址: {ip} What it means
Thrown by ApiAuthFilter.ipToLong when an IPv4 string passed to CIDR matching does not split into exactly 4 octets. Note: ipToLong is only reached via isCidrMatch, which wraps the call in try/catch(Exception) and returns false on failure, so in practice this exception is swallowed and logged as a warning - it surfaces as a CIDR non-match (which then may bubble up as error 146 'IP not in whitelist'), not directly to the client.
Source
Thrown at jeecg-boot/jeecg-module-system/jeecg-system-biz/src/main/java/org/jeecg/modules/openapi/filter/ApiAuthFilter.java:177
}
for (int i = 0; i < 4; i++) {
if ("*".equals(patternParts[i])) {
continue;
}
if (!ipParts[i].equals(patternParts[i])) {
return false;
}
}
return true;
}
/**
* IPv4地址转long
*/
private long ipToLong(String ip) {
String[] parts = ip.split("\\.");
if (parts.length != 4) {
throw new IllegalArgumentException("非法IPv4地址: " + ip);
}
long result = 0;
for (int i = 0; i < 4; i++) {
result = (result << 8) | (Integer.parseInt(parts[i]) & 0xFF);
}
return result;
}
//update-end---author:scott ---date:20260416 for:【PR/9083】OpenAPI白名单增强,支持CIDR网段和通配符匹配-----------
/**
* 签名验证
* @param appkey
* @param signature
* @param timestamp
* @return
*/
protected void checkSignValid(String appkey, String signature, String timestamp) {
if (!StringUtils.hasText(appkey)) {View on GitHub (pinned to 96fb33f5ec)
Solutions
- Correct the CIDR entry to a valid 4-octet/prefix form: '192.168.1.0/24'.
- If clients are IPv6, note the matcher is IPv4-only; restrict to IPv4 clients or extend the matcher.
- Inspect logs for 'CIDR匹配解析失败: cidr=..., ip=...' warnings to locate the offending entry.
Example fix
// before: white_list = "192.168.1/24" // after: white_list = "192.168.1.0/24"
Defensive patterns
Strategy: validation
Validate before calling
// Validate CIDR entries before saving them into white_list
private static boolean isValidCidr(String cidr) {
String[] p = cidr.split("/");
if (p.length != 2) return false;
String[] oct = p[0].split("\\.");
if (oct.length != 4) return false;
try { Integer.parseInt(p[1]); } catch (Exception e) { return false; }
return true;
} Prevention
- Always use 4-octet CIDR form (e.g. 192.168.1.0/24).
- Note the matcher is IPv4-only; do not put IPv6 entries in the whitelist.
- Watch logs for 'CIDR匹配解析失败' warnings to catch malformed entries early.
When it happens
Trigger: Configuring a CIDR entry like '192.168.1/24' (missing an octet), '10.0.0.0.0/8' (extra octet), or a non-numeric value; the caller IP itself is IPv6 or malformed.
Common situations: Typo in the whitelist CIDR; IPv6-only client whose '::1' style address is fed into the IPv4-only matcher; database migration that mangled the white_list column.
Related errors
- 原始接口路径包含非法字符
- 原始接口路径必须以 / 开头,或填写完整的 http(s) URL
- 原始接口路径仅支持相对路径或 http(s) 完整URL
- IP[{ip}]不在白名单中,禁止访问
- appkey为空
AI-assisted analysis of jeecgboot/JeecgBoot@96fb33f5ec (2026-08-14).
Data as JSON: /api/errors/94baf6d53afeb810.
Report an issue: GitHub.