Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions packages/core/src/core/checks/helpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -59,13 +59,13 @@ export async function checkRouteIpAccess(
middleware: GuardMiddlewareProtocol,
): Promise<boolean | null> {
try {
if (routeConfig.ipBlacklist && routeConfig.ipBlacklist.length > 0) {
if (isIpInBlacklist(clientIp, routeConfig.ipBlacklist)) return false;
}

/* Reference check_route_ip_access: a configured route whitelist alone
decides; the route blacklist is consulted only when it is absent. */
if (routeConfig.ipWhitelist && routeConfig.ipWhitelist.length > 0) {
const whitelistResult = isIpInWhitelist(clientIp, routeConfig.ipWhitelist);
if (whitelistResult !== null) return whitelistResult;
} else if (routeConfig.ipBlacklist && routeConfig.ipBlacklist.length > 0) {
if (isIpInBlacklist(clientIp, routeConfig.ipBlacklist)) return false;
}

const countryResult = checkCountryAccess(clientIp, routeConfig, middleware.geoIpHandler);
Expand Down
10 changes: 7 additions & 3 deletions packages/core/src/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -473,9 +473,13 @@ export async function isIpAllowed(
try {
if (canonicalIpText(ip) === null) return false;

if (ipInList(ip, config.blacklist)) return false;

if (config.whitelist && config.whitelist.length > 0 && !ipInList(ip, config.whitelist)) return false;
/* Reference _check_ip_lists_detail: a configured whitelist alone decides;
the blacklist applies only when no whitelist is configured. */
if (config.whitelist && config.whitelist.length > 0) {
if (!ipInList(ip, config.whitelist)) return false;
} else if (ipInList(ip, config.blacklist)) {
return false;
}

/* v8 ignore start -- geoIpHandler branch unreachable in recursive JSON check because dangerousPatterns check returns first */
if (geoIpHandler) {
Expand Down
Loading
Loading