mirror of
https://github.com/fosrl/pangolin.git
synced 2025-08-16 23:41:11 +02:00
Drop first
This commit is contained in:
parent
2428738fa6
commit
5e92aebd20
1 changed files with 32 additions and 8 deletions
|
@ -485,18 +485,42 @@ async function checkRules(
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
let hasAcceptRule = false;
|
||||||
|
|
||||||
|
// First pass: look for DROP rules
|
||||||
for (const rule of rules) {
|
for (const rule of rules) {
|
||||||
if (
|
if (
|
||||||
clientIp &&
|
(clientIp &&
|
||||||
rule.match == "CIDR" &&
|
rule.match == "CIDR" &&
|
||||||
isIpInCidr(clientIp, rule.value)
|
isIpInCidr(clientIp, rule.value) &&
|
||||||
|
rule.action === "DROP") ||
|
||||||
|
(path &&
|
||||||
|
rule.match == "PATH" &&
|
||||||
|
urlGlobToRegex(rule.value).test(path) &&
|
||||||
|
rule.action === "DROP")
|
||||||
) {
|
) {
|
||||||
return rule.action as "ACCEPT" | "DROP";
|
return "DROP";
|
||||||
} else if (path && rule.match == "PATH") {
|
}
|
||||||
// rule.value is a regex, match on the path and see if it matches
|
// Track if we see any ACCEPT rules for the second pass
|
||||||
const re = urlGlobToRegex(rule.value);
|
if (rule.action === "ACCEPT") {
|
||||||
if (re.test(path)) {
|
hasAcceptRule = true;
|
||||||
return rule.action as "ACCEPT" | "DROP";
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Second pass: only check ACCEPT rules if we found one and didn't find a DROP
|
||||||
|
if (hasAcceptRule) {
|
||||||
|
for (const rule of rules) {
|
||||||
|
if (rule.action !== "ACCEPT") continue;
|
||||||
|
|
||||||
|
if (
|
||||||
|
(clientIp &&
|
||||||
|
rule.match == "CIDR" &&
|
||||||
|
isIpInCidr(clientIp, rule.value)) ||
|
||||||
|
(path &&
|
||||||
|
rule.match == "PATH" &&
|
||||||
|
urlGlobToRegex(rule.value).test(path))
|
||||||
|
) {
|
||||||
|
return "ACCEPT";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue