mirror of
https://github.com/MHSanaei/3x-ui.git
synced 2026-12-03 21:18:19 +07:00
[PR #6230] [MERGED] feat(limitip): let operators exempt trusted addresses from the IP limit #6191
Labels
No labels
backlog
bug
clarification needed
documentation
duplicate
enhancement
github_actions
good first issue
invalid
javascript
New Feature
PR welcomed
pull-request
question
wontfix
No milestone
No project
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set.
Reference
MHSanaei/3x-ui#6191
Loading…
Add table
Add a link
Reference in a new issue
No description provided.
Delete branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
📋 Pull Request Information
Original PR: https://github.com/MHSanaei/3x-ui/pull/6230
Author: @n0ctal
Created: 8/16/2026
Status: ✅ Merged
Merged: 8/18/2026
Merged by: @MHSanaei
Base:
main← Head:upstream-ip-limit-allowlist📝 Commits (6)
07b5aeffeat(limitip): let operators exempt trusted addresses from the IP limitd1e1a14fix(limitip): keep each doc comment on its function and one grammar for the list9720953chore: drop the accidentally committed dist build stub83f4faeMerge branch 'main' into upstream-ip-limit-allowlist6f3fef2chore(i18n): translate the IP limit allowlist strings into the remaining localesb855d0frefactor(limitip): share one IP/CIDR list validator and read the allowlist only when enforcing📊 Changes
28 files changed (+373 additions, -27 deletions)
View changed files
📝
frontend/public/openapi.json(+8 -0)📝
frontend/src/generated/examples.ts(+2 -0)📝
frontend/src/generated/schemas.ts(+8 -0)📝
frontend/src/generated/types.ts(+2 -0)📝
frontend/src/generated/zod.ts(+2 -0)📝
frontend/src/models/setting.ts(+1 -0)📝
frontend/src/pages/settings/GeneralTab.tsx(+12 -0)📝
frontend/src/schemas/setting.ts(+1 -0)📝
internal/web/entity/check_valid_test.go(+40 -1)📝
internal/web/entity/entity.go(+27 -11)📝
internal/web/job/check_client_ip_job.go(+25 -2)📝
internal/web/job/check_client_ip_job_integration_test.go(+49 -0)➕
internal/web/job/ip_limit_allowlist.go(+80 -0)➕
internal/web/job/ip_limit_allowlist_test.go(+70 -0)📝
internal/web/service/setting.go(+7 -0)📝
internal/web/translation/ar-EG.json(+3 -1)📝
internal/web/translation/en-US.json(+3 -1)📝
internal/web/translation/es-ES.json(+3 -1)📝
internal/web/translation/fa-IR.json(+3 -1)📝
internal/web/translation/id-ID.json(+3 -1)...and 8 more files
📄 Description
Closes #5378.
Summary
Behind a shared address — an office gateway, a campus NAT, a residential carrier — every user looks like the same client to the IP limit. One of them trips it, the address is disconnected and written to the fail2ban log, and everyone else behind that address goes with them.
This adds an allowlist of addresses and networks the IP limit leaves alone.
Why "not counted", not just "not banned"
The obvious reading of the request is "never ban these". That is half a fix. If the shared address still occupies one of the client's slots, the next ordinary connection pushes the client over the limit and something else gets banned instead — the office is still the reason someone was cut off, one step removed.
So a matching address is taken out of the accounting entirely: it is neither banned nor counted. That is what makes the setting do what the reporter's use case needs.
Behaviour
ipLimitAllowlist, comma-separated, each entry an IP or a CIDR, IPv4 and IPv6, empty by default — so nothing changes for anyone who does not set it.Why not write fail2ban's
ignoreipThe panel would have to own a file under
/etc/fail2ban/jail.d, which needs root, a reload, and a policy for what happens when an operator has edited it by hand. It is also fragile in a way that is easy to miss: fail2ban merges[DEFAULT]sections in filename order, so a later file silently overrides an earlier one and the panel's intent quietly disappears.Filtering before the log line is written means fail2ban never sees anything to act on, needs no privileges, and cannot be overridden by a stray config file.
Validation
Unit tests cover matching (address, CIDR, IPv6, mixed separators), malformed entries not widening the list, and the empty list being a no-op.
The wiring is covered separately, and that matters: my first attempt tested only the pure functions, so replacing the filtered list with the unfiltered one at the call site left everything green.
TestUpdateInboundClientIps_AllowlistedIpIsNeitherCountedNorBannedmirrors the existing ban test throughupdateInboundClientIpsand asserts nothing is banned, both addresses stay persisted, and no line reaches the fail2ban log. Reverting the filter turns it red withan allowlisted address pushed the client over its limit and something was banned.All examples use the documentation ranges from RFC 5737 and RFC 3849.
go build ./...,go vet,golangci-lint,make gen-checkclean; 36 Go packages green; frontend typecheck, eslint and the i18n key test green.🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.