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

  1. Correct the CIDR entry to a valid 4-octet/prefix form: '192.168.1.0/24'.
  2. If clients are IPv6, note the matcher is IPv4-only; restrict to IPv4 clients or extend the matcher.
  3. 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

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


AI-assisted analysis of jeecgboot/JeecgBoot@96fb33f5ec (2026-08-14). Data as JSON: /api/errors/94baf6d53afeb810. Report an issue: GitHub.