[PR #6230] [MERGED] feat(limitip): let operators exempt trusted addresses from the IP limit #6191

Closed
opened 2026-11-02 04:07:01 +07:00 by bsakaguchi · 0 comments
Owner

📋 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)

  • 07b5aef feat(limitip): let operators exempt trusted addresses from the IP limit
  • d1e1a14 fix(limitip): keep each doc comment on its function and one grammar for the list
  • 9720953 chore: drop the accidentally committed dist build stub
  • 83f4fae Merge branch 'main' into upstream-ip-limit-allowlist
  • 6f3fef2 chore(i18n): translate the IP limit allowlist strings into the remaining locales
  • b855d0f refactor(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

  • Setting 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.
  • Entries are validated on save and rejected if malformed, rather than skipped silently at scan time. A typo in an allowlist is invisible: the address simply stays unprotected until someone notices it getting banned.
  • A read failure at scan time leaves the list empty, which enforces the limit as before rather than exempting everybody.

Why not write fail2ban's ignoreip

The 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_AllowlistedIpIsNeitherCountedNorBanned mirrors the existing ban test through updateInboundClientIps and asserts nothing is banned, both addresses stay persisted, and no line reaches the fail2ban log. Reverting the filter turns it red with an 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-check clean; 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.

## 📋 Pull Request Information **Original PR:** https://github.com/MHSanaei/3x-ui/pull/6230 **Author:** [@n0ctal](https://github.com/n0ctal) **Created:** 8/16/2026 **Status:** ✅ Merged **Merged:** 8/18/2026 **Merged by:** [@MHSanaei](https://github.com/MHSanaei) **Base:** `main` ← **Head:** `upstream-ip-limit-allowlist` --- ### 📝 Commits (6) - [`07b5aef`](https://github.com/MHSanaei/3x-ui/commit/07b5aef6f75d783cffce0254bf9c6edffeac9d51) feat(limitip): let operators exempt trusted addresses from the IP limit - [`d1e1a14`](https://github.com/MHSanaei/3x-ui/commit/d1e1a1427ae9d966dff4620aca7783c25a0a8ef0) fix(limitip): keep each doc comment on its function and one grammar for the list - [`9720953`](https://github.com/MHSanaei/3x-ui/commit/97209531c21506b2475c56fa0bf63f87fef876ea) chore: drop the accidentally committed dist build stub - [`83f4fae`](https://github.com/MHSanaei/3x-ui/commit/83f4fae4ad6bc8c653956c4732c6cfc6006de1c9) Merge branch 'main' into upstream-ip-limit-allowlist - [`6f3fef2`](https://github.com/MHSanaei/3x-ui/commit/6f3fef2d845748c95880acb053d997f3fedd893e) chore(i18n): translate the IP limit allowlist strings into the remaining locales - [`b855d0f`](https://github.com/MHSanaei/3x-ui/commit/b855d0f15aea261ea6e7367da4d2c7186bbdffdc) refactor(limitip): share one IP/CIDR list validator and read the allowlist only when enforcing ### 📊 Changes **28 files changed** (+373 additions, -27 deletions) <details> <summary>View changed files</summary> 📝 `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_ </details> ### 📄 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 - Setting `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. - Entries are **validated on save** and rejected if malformed, rather than skipped silently at scan time. A typo in an allowlist is invisible: the address simply stays unprotected until someone notices it getting banned. - A read failure at scan time leaves the list empty, which enforces the limit as before rather than exempting everybody. ## Why not write fail2ban's `ignoreip` The 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_AllowlistedIpIsNeitherCountedNorBanned` mirrors the existing ban test through `updateInboundClientIps` and asserts nothing is banned, both addresses stay persisted, and no line reaches the fail2ban log. Reverting the filter turns it red with `an 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-check` clean; 36 Go packages green; frontend typecheck, eslint and the i18n key test green. --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
bsakaguchi 2026-11-02 04:07:01 +07:00
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
MHSanaei/3x-ui#6191
No description provided.