Skip to content

Commit cc8c782

Browse files
Merge remote branch
2 parents 15987bc + 75a9443 commit cc8c782

1 file changed

Lines changed: 10 additions & 1 deletion

File tree

moss-live-labs/examples/voice-agent/web/lib/tokenGuard.ts

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,16 @@ export function warnTokenGuardMisconfig(config: TokenGuardConfig): void {
5252
}
5353

5454
function normalizeIp(ip: string): string {
55-
return ip.trim().toLowerCase().replace(/^\[|\]$/g, "");
55+
const normalized = ip.trim().toLowerCase();
56+
const unwrapped =
57+
normalized.startsWith("[") && normalized.endsWith("]")
58+
? normalized.slice(1, -1)
59+
: normalized;
60+
if (unwrapped.startsWith("::ffff:")) {
61+
const v4 = unwrapped.slice("::ffff:".length);
62+
if (isValidIpv4(v4)) return v4;
63+
}
64+
return unwrapped;
5665
}
5766

5867
/** Valid dotted IPv4 with each octet in 0–255 (no leading junk). */

0 commit comments

Comments
 (0)