Refine wildcard IP matching and fix range ban precedence - #32
MCLV-pandorabox wants to merge 3 commits into
Conversation
Fixes Issue minetest-mods#31 - Adjust wildcard prefix extraction to correctly handle patterns like ::ffff:79.127.164.* and 79.127.164.*. - Ensure both IPv4 and IPv4-mapped IPv6 addresses match the same wildcard bans. - Change ban lookup logic so non-banned exact IP entries no longer shadow later wildcard range bans. - Keep compatibility with existing xban2 databases while making IP range bans reliably effective.
| if wildcard_prefix and key:sub(1, #wildcard_prefix) == wildcard_prefix then | ||
| return e, i | ||
| end | ||
| local key_prefix = key:match("(.*)%*$") |
There was a problem hiding this comment.
Please move outside the loop. This does not need to be re-evaluated every time.
There was a problem hiding this comment.
I tried to fix this really simple thing, but I also wanted to try out copilot.
it messed up and apologized, then told me I was out of tokens when I asked it to fix it.
I have no idea what happened or have enough experience with github to fix this, but it looks like the entire init.lua was pushed as a nearly blank file.
Please advice
There was a problem hiding this comment.
To revert changes, look up git revert or git reset in your preferred manual.
| end | ||
| local key_prefix = key:match("(.*)%*$") | ||
| if key_prefix and name:sub(1, #key_prefix) == key_prefix then | ||
| return e, i |
There was a problem hiding this comment.
Can we be sure that e.banned is true?
There was a problem hiding this comment.
Thanks for catching that! Yes, we can't assume e.banned is true on an exact match, and that's intentional. The logic here is: if an entry exists (exact or wildcard match) and it's banned, block immediately. If it exists but is unbanned, keep searching — there might be another entry (wildcard or otherwise) that IS banned and should take precedence.
No code change needed I think
|
In case you're waiting on a feedback: Did you yet test these changes? I am pretty sure the word |
Fixes Issue #31
Adjust wildcard prefix extraction to correctly handle patterns like ::ffff:79.127.164.* and 79.127.164.*.
Ensure both IPv4 and IPv4-mapped IPv6 addresses match the same wildcard bans.
Change ban lookup logic so non-banned exact IP entries no longer shadow later wildcard range bans.
Keep compatibility with existing xban2 databases while making IP range bans reliably effective.