This is an automated email from the ASF dual-hosted git repository.

lizhimins pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/rocketmq-dashboard.git


The following commit(s) were added to refs/heads/master by this push:
     new 21b554f1d fix(acl): grade bounded native wildcard addresses by prefix 
breadth in risk diagnostics (#7092)
21b554f1d is described below

commit 21b554f1d2b1dbf217916de92f2b03c6f8e995af
Author: 0 <[email protected]>
AuthorDate: Fri Nov 27 11:58:30 2026 +0800

    fix(acl): grade bounded native wildcard addresses by prefix breadth in risk 
diagnostics (#7092)
---
 web/src/utils/aclRiskDiagnostics.test.ts | 110 ++++++++++++++++++++++++++++
 web/src/utils/aclRiskDiagnostics.ts      | 118 +++++++++++++++++++++++++++++--
 2 files changed, 224 insertions(+), 4 deletions(-)

diff --git a/web/src/utils/aclRiskDiagnostics.test.ts 
b/web/src/utils/aclRiskDiagnostics.test.ts
index 7d53b5b9e..f6978181d 100644
--- a/web/src/utils/aclRiskDiagnostics.test.ts
+++ b/web/src/utils/aclRiskDiagnostics.test.ts
@@ -271,4 +271,114 @@ describe('ACL risk diagnostics', () => {
       ]),
     );
   });
+
+  it('treats bounded native IPv4 wildcards as scoped instead of critical', () 
=> {
+    const diagnostics = analyzeAclRisk(
+      config({
+        accounts: [
+          account({ accessKey: 'svc-edge', whiteRemoteAddress: '10.0.2.*' }),
+          account({ accessKey: 'svc-office', whiteRemoteAddress: '192.168.*.*' 
}),
+        ],
+        accountCount: 2,
+      }),
+    );
+
+    expect(diagnostics.status).toBe('healthy');
+    expect(diagnostics.summary.broadWhitelistCount).toBe(0);
+    expect(diagnostics.issues.map((item) => 
item.code)).not.toContain('BROAD_ACCOUNT_WHITELIST');
+  });
+
+  it('grades a /8-sized native IPv4 wildcard as broad but not open', () => {
+    const diagnostics = analyzeAclRisk(
+      config({
+        accounts: [account({ whiteRemoteAddress: '10.*.*.*' })],
+      }),
+    );
+
+    expect(diagnostics.summary.broadWhitelistCount).toBe(1);
+    expect(diagnostics.issues).toEqual([
+      expect.objectContaining({
+        code: 'BROAD_ACCOUNT_WHITELIST',
+        severity: 'warning',
+        evidence: ['10.*.*.*'],
+      }),
+    ]);
+  });
+
+  it('follows the /16 threshold for recognized native IPv6 wildcards', () => {
+    const diagnostics = analyzeAclRisk(
+      config({
+        accounts: [
+          account({
+            accessKey: 'svc-v6-scoped',
+            whiteRemoteAddress: '1050::0005:0600:300c:1-20:*',
+          }),
+          account({ accessKey: 'svc-v6-broad', whiteRemoteAddress: 
'1050:1-20:*' }),
+        ],
+        accountCount: 2,
+      }),
+    );
+
+    expect(diagnostics.summary.broadWhitelistCount).toBe(1);
+    expect(diagnostics.issues).toEqual([
+      expect.objectContaining({
+        code: 'BROAD_ACCOUNT_WHITELIST',
+        severity: 'warning',
+        account: 'svc-v6-broad',
+      }),
+    ]);
+  });
+
+  it('keeps entire-address-space wildcards critical', () => {
+    const diagnostics = analyzeAclRisk(
+      config({
+        accounts: [
+          account({ accessKey: 'all-bare', whiteRemoteAddress: '*' }),
+          account({ accessKey: 'all-v4', whiteRemoteAddress: '*.*.*.*' }),
+          account({ accessKey: 'all-v6', whiteRemoteAddress: '*:*:*:*:*:*:*:*' 
}),
+        ],
+        accountCount: 3,
+      }),
+    );
+
+    expect(diagnostics.status).toBe('critical');
+    expect(
+      diagnostics.issues.filter((item) => item.code === 
'BROAD_ACCOUNT_WHITELIST'),
+    ).toEqual([
+      expect.objectContaining({ account: 'all-bare', severity: 'critical' }),
+      expect.objectContaining({ account: 'all-v4', severity: 'critical' }),
+      expect.objectContaining({ account: 'all-v6', severity: 'critical' }),
+    ]);
+  });
+
+  it('keeps the conservative critical fallback for unrecognized wildcard 
forms', () => {
+    const diagnostics = analyzeAclRisk(
+      config({
+        accounts: [
+          // A concrete octet after the variable segment is outside the plain 
ACL grammar.
+          account({ accessKey: 'bad-v4', whiteRemoteAddress: '10.0.*.15' }),
+          account({ accessKey: 'bad-octet', whiteRemoteAddress: '300.168.*.*' 
}),
+          // "::1-20:*" anchors the range on the first group without a 
concrete prefix.
+          account({ accessKey: 'bad-v6', whiteRemoteAddress: '::1-20:*' }),
+          // A "*" variable must be the final segment, so one before a 
trailing wildcard
+          // and a range ahead of a compressed tail are both outside the 
grammar.
+          account({ accessKey: 'bad-v6-star', whiteRemoteAddress: '1050:*:*' 
}),
+          account({ accessKey: 'bad-v6-compressed', whiteRemoteAddress: 
'1050:1-20::*' }),
+          // Wildcards mixed into a CIDR mask are not a native expression 
either.
+          account({ accessKey: 'bad-cidr-mix', whiteRemoteAddress: 
'10.0.*.0/24' }),
+        ],
+        accountCount: 6,
+      }),
+    );
+
+    expect(diagnostics.status).toBe('critical');
+    expect(
+      diagnostics.issues
+        .filter((item) => item.code === 'BROAD_ACCOUNT_WHITELIST')
+        .every((item) => item.severity === 'critical'),
+    ).toBe(true);
+    expect(
+      diagnostics.issues.filter((item) => item.code === 
'BROAD_ACCOUNT_WHITELIST'),
+    ).toHaveLength(6);
+  });
 });
diff --git a/web/src/utils/aclRiskDiagnostics.ts 
b/web/src/utils/aclRiskDiagnostics.ts
index 74efa0651..ae34971b6 100644
--- a/web/src/utils/aclRiskDiagnostics.ts
+++ b/web/src/utils/aclRiskDiagnostics.ts
@@ -96,7 +96,20 @@ const PERMISSION_ALLOW_RANK: Record<AclPermission, number> = 
{
   UNKNOWN: 0,
 };
 
-const OPEN_WHITELIST_VALUES = new Set(['*', '0.0.0.0/0', '::/0', '0/0']);
+// The wildcard spellings of "every address" mirror 
PlainAclRemoteAddressValidator#isAllAddresses.
+const OPEN_WHITELIST_VALUES = new Set([
+  '*',
+  '*.*.*.*',
+  '*:*:*:*:*:*:*:*',
+  '0.0.0.0/0',
+  '::/0',
+  '0/0',
+]);
+
+// Breadth thresholds shared by CIDR and native wildcard expressions: an IPv4 
/8 and an
+// IPv6 /16 are the widest ranges still reported as broad instead of scoped.
+const IPV4_BROAD_PREFIX_BITS = 8;
+const IPV6_BROAD_PREFIX_BITS = 16;
 
 /**
  * The rule editor lets one rule carry several actions, and the repository 
stores them as a
@@ -131,18 +144,115 @@ const cidrPrefix = (address: string): number | null => {
   return Number.isFinite(prefix) ? prefix : null;
 };
 
+const isDecimalOctet = (value: string): boolean =>
+  /^\d{1,3}$/.test(value) && Number(value) <= 255;
+
+const isHexGroup = (value: string): boolean => /^[0-9a-f]{1,4}$/.test(value);
+
+const isDecimalRange = (value: string): boolean => {
+  const match = value.match(/^(\d{1,3})-(\d{1,3})$/);
+  if (!match) return false;
+  const start = Number(match[1]);
+  const end = Number(match[2]);
+  return start <= end && end <= 255;
+};
+
+const isHexRange = (value: string): boolean => {
+  const match = value.match(/^([0-9a-f]{1,4})-([0-9a-f]{1,4})$/);
+  if (!match) return false;
+  const start = parseInt(match[1], 16);
+  const end = parseInt(match[2], 16);
+  return start <= end && end <= 0xffff;
+};
+
+/**
+ * Mirror the IPv4 range grammar of PlainAclRemoteAddressValidator: a leading 
run of
+ * decimal octets, then one wildcard or decimal-range segment, then only 
wildcards.
+ * Return the fixed prefix length in bits, or null when the expression is not 
a form
+ * the plain ACL address grammar recognizes.
+ */
+const ipv4WildcardPrefixBits = (normalized: string): number | null => {
+  const segments = normalized.split('.');
+  if (segments.length !== 4 || !isDecimalOctet(segments[0])) return null;
+  let fixed = 1;
+  let sawVariable = false;
+  for (let i = 1; i < segments.length; i += 1) {
+    const segment = segments[i];
+    if (!sawVariable && isDecimalOctet(segment)) {
+      fixed += 1;
+    } else if (!sawVariable && (segment === '*' || isDecimalRange(segment))) {
+      sawVariable = true;
+    } else if (sawVariable && segment === '*') {
+      continue;
+    } else {
+      return null;
+    }
+  }
+  return sawVariable ? fixed * 8 : null;
+};
+
+/**
+ * Mirror the IPv6 range grammar of PlainAclRemoteAddressValidator: hex groups 
with at
+ * most one "::" run, one wildcard or hex-range segment anchored at the end 
(only a
+ * range may sit right before a trailing wildcard), and at least one concrete 
group
+ * before it. Return the fixed prefix length in bits, or null when the 
expression is
+ * not a form the plain ACL address grammar recognizes.
+ */
+const ipv6WildcardPrefixBits = (normalized: string): number | null => {
+  if (normalized.includes('.') || normalized.split('::').length > 2) return 
null;
+  const segments = normalized.split(':');
+  const lastIndex = segments.length - 1;
+  let nonEmpty = 0;
+  let fixed = 0;
+  let variableIndex = -1;
+  let variableIsStar = false;
+  for (let i = 0; i < segments.length; i += 1) {
+    const segment = segments[i];
+    if (!segment) continue;
+    nonEmpty += 1;
+    if (variableIndex < 0 && isHexGroup(segment)) {
+      fixed += 1;
+    } else if (variableIndex < 0 && (segment === '*' || isHexRange(segment))) {
+      variableIndex = i;
+      variableIsStar = segment === '*';
+    } else if (variableIndex >= 0 && segment === '*' && i === lastIndex) {
+      continue;
+    } else {
+      return null;
+    }
+  }
+  if (variableIndex < 0 || fixed < 1 || nonEmpty > 8) return null;
+  // The validator only accepts a "*" variable as the final segment, and a 
range
+  // variable as the final segment or right before one trailing wildcard.
+  const atEnd = variableIndex === lastIndex;
+  const beforeTrailingStar = variableIndex === lastIndex - 1 && 
segments[lastIndex] === '*';
+  if (variableIsStar ? !atEnd : !(atEnd || beforeTrailingStar)) return null;
+  return fixed * 16;
+};
+
 const classifyWhitelistAddress = (address: string): WhitelistClass => {
   const normalized = address.trim().toLowerCase();
   if (!normalized) return 'scoped';
   if (OPEN_WHITELIST_VALUES.has(normalized)) return 'open';
-  if (normalized.includes('*')) return 'open';
+  if (normalized.includes('*')) {
+    // Grade recognized native expressions by the same breadth thresholds as 
CIDR, and
+    // keep the conservative "open" verdict for anything the grammar would 
reject.
+    const prefixBits = normalized.includes(':')
+      ? ipv6WildcardPrefixBits(normalized)
+      : ipv4WildcardPrefixBits(normalized);
+    if (prefixBits === null) return 'open';
+    const broadPrefixBits = normalized.includes(':')
+      ? IPV6_BROAD_PREFIX_BITS
+      : IPV4_BROAD_PREFIX_BITS;
+    return prefixBits <= broadPrefixBits ? 'broad' : 'scoped';
+  }
 
   const prefix = cidrPrefix(normalized);
   if (prefix === null) return 'scoped';
   if (normalized.includes(':')) {
-    return prefix <= 16 ? 'broad' : 'scoped';
+    return prefix <= IPV6_BROAD_PREFIX_BITS ? 'broad' : 'scoped';
   }
-  return prefix <= 8 ? 'broad' : 'scoped';
+  return prefix <= IPV4_BROAD_PREFIX_BITS ? 'broad' : 'scoped';
 };
 
 const classifyWhitelist = (addresses: string[]): WhitelistClass => {

Reply via email to