feat(limitip): let operators exempt trusted addresses from the IP limit (#6230)

* feat(limitip): let operators exempt trusted addresses from the IP limit

Behind a shared address — an office gateway, a campus NAT, a residential
carrier — every user looks like the same client. One of them trips the IP
limit and the address is disconnected and handed to fail2ban, taking the
others with it. Today the only way out is editing jail.d by hand, which an
update overwrites.

Add an allowlist setting of addresses and networks. A matching address is
neither banned nor counted towards the limit: counting it would still cut the
shared network the entry exists to protect.

Entries are validated on save rather than skipped at scan time — a typo would
otherwise leave the address unprotected until someone noticed the bans.

* fix(limitip): keep each doc comment on its function and one grammar for the list

Three review follow-ups. loadAllowlist landed between hasLimitIp's doc comment
and hasLimitIp itself, so godoc showed one function's rationale above another's
body; it now sits after that function with its own comment.

The parser advertised semicolons and whitespace as separators while the
settings validator accepts commas only, making those forms unreachable through
the panel and the API — a promise the software never keeps. Both sides now read
the same comma-separated grammar.

The dist stub was a build artifact and does not belong in the tree.

* chore: drop the accidentally committed dist build stub

internal/web/dist/.gitkeep is what make dist-stub creates locally. Committing
it changes fresh-clone behaviour for everyone: today a bare go build fails
loudly on //go:embed all:dist, which is the documented signal to run the stub
target; with the file present the build succeeds and the panel serves an empty
dist instead.

* chore(i18n): translate the IP limit allowlist strings into the remaining locales

Ten locales carried the English source text verbatim; only ru-RU and uk-UA
were translated. The i18n dead-key test only checks that a key exists in every
file, so an untranslated value passes it silently.

Wording follows each locale's existing terms: the ipLimit noun already in the
file, and the comma-separated IP/CIDR phrasing from trustedProxyCidrsDesc.

* refactor(limitip): share one IP/CIDR list validator and read the allowlist only when enforcing

The allowlist check in CheckValid was a line-for-line copy of the trusted-proxy
loop directly above it. Both now call one helper, each passing its own message,
so the two lists cannot drift apart.

Run() read the allowlist on every 10s scan, including the majority of panels
where no client carries an IP limit and the value is discarded. It is now read
only once enforcement is known to apply.

CheckValid had no test for either list. The new one pins that a malformed entry
is rejected and that each list still names itself in the error, which is what
the shared helper could otherwise break.

---------

Co-authored-by: n0ctal <n0ctal@users.noreply.github.com>
Co-authored-by: Sanaei <ho3ein.sanaei@gmail.com>
This commit is contained in:
n0ctal
2026-08-18 15:23:10 +05:00
committed by GitHub
parent 6e80a468e3
commit d6472740dc
28 changed files with 373 additions and 27 deletions
+3 -1
View File
@@ -1368,7 +1368,9 @@
"secretClear": "مسح",
"secretClearUndo": "تراجع عن المسح",
"calendarGregorian": "Gregorian (Standard)",
"calendarJalalian": "Jalalian (شمسی)"
"calendarJalalian": "Jalalian (شمسی)",
"ipLimitAllowlist": "قائمة سماح حد IP",
"ipLimitAllowlistDesc": "عناوين وشبكات لا يحسبها حد IP ولا يحظرها، حتى لا يستهلك عنوان مكتب أو حرم جامعي مشترك حد العميل. IPs/CIDRs مفصولة بفواصل."
},
"xray": {
"save": "احفظ",
+3 -1
View File
@@ -1485,7 +1485,9 @@
"secretClear": "Clear",
"secretClearUndo": "Undo clear",
"calendarGregorian": "Gregorian (Standard)",
"calendarJalalian": "Jalalian (شمسی)"
"calendarJalalian": "Jalalian (شمسی)",
"ipLimitAllowlist": "IP limit allowlist",
"ipLimitAllowlistDesc": "Addresses and networks that the IP limit never counts and never bans, so a shared office or campus address cannot use up a client's limit. Comma-separated, IP or CIDR."
},
"xray": {
"save": "Save",
+3 -1
View File
@@ -1368,7 +1368,9 @@
"secretClear": "Borrar",
"secretClearUndo": "Deshacer borrado",
"calendarGregorian": "Gregorian (Standard)",
"calendarJalalian": "Jalalian (شمسی)"
"calendarJalalian": "Jalalian (شمسی)",
"ipLimitAllowlist": "Lista de permitidos del límite de IP",
"ipLimitAllowlistDesc": "Direcciones y redes que el límite de IP nunca cuenta ni banea, para que una dirección compartida de oficina o campus no agote el límite de un cliente. IP/CIDR separados por coma."
},
"xray": {
"save": "Guardar configuración",
+3 -1
View File
@@ -1368,7 +1368,9 @@
"secretClear": "پاک کردن",
"secretClearUndo": "لغو پاک کردن",
"calendarGregorian": "Gregorian (Standard)",
"calendarJalalian": "Jalalian (شمسی)"
"calendarJalalian": "Jalalian (شمسی)",
"ipLimitAllowlist": "فهرست مجاز محدودیت IP",
"ipLimitAllowlistDesc": "نشانی‌ها و شبکه‌هایی که محدودیت IP هرگز آن‌ها را نمی‌شمارد و مسدود نمی‌کند، تا نشانی مشترک یک اداره یا دانشگاه محدودیت کاربر را مصرف نکند. IPها/CIDRها (با کاما)."
},
"xray": {
"save": "ذخیره",
+3 -1
View File
@@ -1368,7 +1368,9 @@
"secretClear": "Hapus",
"secretClearUndo": "Batalkan hapus",
"calendarGregorian": "Gregorian (Standard)",
"calendarJalalian": "Jalalian (شمسی)"
"calendarJalalian": "Jalalian (شمسی)",
"ipLimitAllowlist": "Daftar izin batas IP",
"ipLimitAllowlistDesc": "Alamat dan jaringan yang tidak pernah dihitung maupun diblokir oleh batas IP, sehingga alamat kantor atau kampus bersama tidak menghabiskan batas klien. IP/CIDR (dipisahkan koma)."
},
"xray": {
"save": "Simpan",
+3 -1
View File
@@ -1368,7 +1368,9 @@
"secretClear": "クリア",
"secretClearUndo": "クリアを取り消す",
"calendarGregorian": "Gregorian (Standard)",
"calendarJalalian": "Jalalian (شمسی)"
"calendarJalalian": "Jalalian (شمسی)",
"ipLimitAllowlist": "IP 制限の許可リスト",
"ipLimitAllowlistDesc": "IP 制限がカウントもブロックもしないアドレスとネットワーク。オフィスや学内の共有アドレスがクライアントの上限を使い切らないようにします。IP/CIDR (カンマ区切り)。"
},
"xray": {
"importRules": "ルールをインポート",
+3 -1
View File
@@ -1368,7 +1368,9 @@
"secretClear": "Limpar",
"secretClearUndo": "Desfazer limpeza",
"calendarGregorian": "Gregorian (Standard)",
"calendarJalalian": "Jalalian (شمسی)"
"calendarJalalian": "Jalalian (شمسی)",
"ipLimitAllowlist": "Lista de permissões do limite de IP",
"ipLimitAllowlistDesc": "Endereços e redes que o limite de IP nunca conta nem bane, para que um endereço compartilhado de escritório ou campus não esgote o limite de um cliente. IPs/CIDRs separados por vírgula."
},
"xray": {
"importRules": "Importar regras",
+3 -1
View File
@@ -1368,7 +1368,9 @@
"secretClear": "Очистить",
"secretClearUndo": "Отменить очистку",
"calendarGregorian": "Григорианский (обычный)",
"calendarJalalian": "Джалали (شمسی)"
"calendarJalalian": "Джалали (شمسی)",
"ipLimitAllowlist": "Доверенные адреса для лимита",
"ipLimitAllowlistDesc": "Адреса и подсети, которые лимит не считает и не банит: общий офисный или студенческий адрес не израсходует лимит клиента. Через запятую, адрес или подсеть."
},
"xray": {
"importRules": "Импорт правил",
+3 -1
View File
@@ -1368,7 +1368,9 @@
"secretClear": "Temizle",
"secretClearUndo": "Temizlemeyi geri al",
"calendarGregorian": "Gregorian (Standard)",
"calendarJalalian": "Jalalian (شمسی)"
"calendarJalalian": "Jalalian (شمسی)",
"ipLimitAllowlist": "IP limiti izin listesi",
"ipLimitAllowlistDesc": "IP limitinin asla saymadığı ve engellemediği adresler ve ağlar; böylece ortak bir ofis veya kampüs adresi kullanıcının limitini tüketmez. IP'ler/CIDR'ler (virgülle ayrılmış)."
},
"xray": {
"save": "Kaydet",
+3 -1
View File
@@ -1368,7 +1368,9 @@
"secretClear": "Очистити",
"secretClearUndo": "Скасувати очищення",
"calendarGregorian": "Григоріанський (звичайний)",
"calendarJalalian": "Джалалі (شمسی)"
"calendarJalalian": "Джалалі (شمسی)",
"ipLimitAllowlist": "Довірені адреси для ліміту",
"ipLimitAllowlistDesc": "Адреси та підмережі, які ліміт не рахує і не банить: спільна офісна чи студентська адреса не витратить ліміт клієнта. Через кому, адреса або підмережа."
},
"xray": {
"save": "Зберегти",
+3 -1
View File
@@ -1368,7 +1368,9 @@
"secretClear": "Xóa",
"secretClearUndo": "Hoàn tác xóa",
"calendarGregorian": "Gregorian (Standard)",
"calendarJalalian": "Jalalian (شمسی)"
"calendarJalalian": "Jalalian (شمسی)",
"ipLimitAllowlist": "Danh sách cho phép của giới hạn IP",
"ipLimitAllowlistDesc": "Các địa chỉ và mạng mà giới hạn IP không bao giờ tính và không bao giờ chặn, để một địa chỉ dùng chung của văn phòng hoặc trường học không dùng hết giới hạn của người dùng. IPs/CIDRs cách nhau bằng dấu phẩy."
},
"xray": {
"importRules": "Nhập quy tắc",
+3 -1
View File
@@ -1368,7 +1368,9 @@
"secretClear": "清除",
"secretClearUndo": "撤销清除",
"calendarGregorian": "Gregorian (Standard)",
"calendarJalalian": "Jalalian (شمسی)"
"calendarJalalian": "Jalalian (شمسی)",
"ipLimitAllowlist": "IP 限制白名单",
"ipLimitAllowlistDesc": "IP 限制永远不会计入也不会封禁的地址和网段,避免办公室或校园的共享地址耗尽客户端的限额。IP/CIDR(逗号分隔)。"
},
"xray": {
"importRules": "导入规则",
+3 -1
View File
@@ -1368,7 +1368,9 @@
"secretClear": "清除",
"secretClearUndo": "復原清除",
"calendarGregorian": "Gregorian (Standard)",
"calendarJalalian": "Jalalian (شمسی)"
"calendarJalalian": "Jalalian (شمسی)",
"ipLimitAllowlist": "IP 限制白名單",
"ipLimitAllowlistDesc": "IP 限制永遠不會計入也不會封鎖的位址與網段,避免辦公室或校園的共用位址耗盡客戶端的額度。IP/CIDR(逗號分隔)。"
},
"xray": {
"save": "儲存",