fix(ip-utils): Fix IP wildcard/shorthand handling and add validation test
This commit is contained in:
@@ -127,8 +127,20 @@ export class SecurityManager {
|
||||
const normalizedIPVariants = normalizeIP(ip);
|
||||
if (normalizedIPVariants.length === 0) return false;
|
||||
|
||||
// Normalize the pattern IPs for consistent comparison
|
||||
const expandedPatterns = patterns.flatMap(normalizeIP);
|
||||
// Expand shorthand patterns and normalize IPs for consistent comparison
|
||||
const expandShorthand = (pattern: string): string => {
|
||||
// Expand shorthand IP patterns like '192.168.*' to '192.168.*.*'
|
||||
if (pattern.includes('*') && !pattern.includes(':')) {
|
||||
const parts = pattern.split('.');
|
||||
while (parts.length < 4) {
|
||||
parts.push('*');
|
||||
}
|
||||
return parts.join('.');
|
||||
}
|
||||
return pattern;
|
||||
};
|
||||
|
||||
const expandedPatterns = patterns.map(expandShorthand).flatMap(normalizeIP);
|
||||
|
||||
// Check for any match between normalized IP variants and patterns
|
||||
return normalizedIPVariants.some((ipVariant) =>
|
||||
|
||||
Reference in New Issue
Block a user