[GH-ISSUE #6256] [Bug]: Limit IP does not force-disconnect Hysteria2 sessions (follow-up to #5350) #4246

Closed
opened 2026-10-31 20:38:16 +07:00 by bsakaguchi · 1 comment
Owner

Originally created by @rokokol on GitHub (Aug 18, 2026).
Original GitHub issue: https://github.com/MHSanaei/3x-ui/issues/6256

Describe the bug

#5350 fixed the ban half: the generated 3x-ipl action now covers UDP as well as TCP, which I can confirm on 3.6.0. The other half is still TCP-only.

When a client exceeds its IP limit, CheckClientIpJob.disconnectClientTemporarily removes and re-adds the user through the Xray API so established sessions drop immediately. That path is guarded by:

switch protocol {
case "vmess", "vless", "trojan", "shadowsocks":
    // supported protocols, continue
default:
    logger.Warningf("[LIMIT_IP] Temporary disconnect is not supported for protocol %s on inbound %s", protocol, inbound.Tag)
    return
}

hysteria falls into default, so a Hysteria2 client over its limit keeps its current QUIC session until the fail2ban rule times it out, instead of being dropped at once. On a link with a long idle timeout that is a noticeable window, and it differs from what the same limit does to a VLESS client.

How to reproduce the problem

  1. Create a Hysteria2 inbound and a client on it with Limit IP = 1.
  2. Connect from IP A and start a transfer.
  3. Connect from IP B with the same credentials.
  4. /var/log/x-ui/3xui.log records the violation, fail2ban bans IP B.
  5. The session from IP B stays alive until it times out; a VLESS client in the same test drops immediately.

Expected behavior

Either the Xray API user removal covers hysteria too, or the limitation is stated in the docs next to Limit IP, so the difference between protocols is not discovered in production.

Actual behavior

The disconnect is skipped and only the warning above is logged.

3x-ui version

3.6.0

Xray-core version

26.7.28

How did you install 3x-ui?

Install script

Operating system

Ubuntu 24.04

Originally created by @rokokol on GitHub (Aug 18, 2026). Original GitHub issue: https://github.com/MHSanaei/3x-ui/issues/6256 ### Describe the bug `#5350` fixed the ban half: the generated `3x-ipl` action now covers UDP as well as TCP, which I can confirm on 3.6.0. The other half is still TCP-only. When a client exceeds its IP limit, `CheckClientIpJob.disconnectClientTemporarily` removes and re-adds the user through the Xray API so established sessions drop immediately. That path is guarded by: ```go switch protocol { case "vmess", "vless", "trojan", "shadowsocks": // supported protocols, continue default: logger.Warningf("[LIMIT_IP] Temporary disconnect is not supported for protocol %s on inbound %s", protocol, inbound.Tag) return } ``` `hysteria` falls into `default`, so a Hysteria2 client over its limit keeps its current QUIC session until the fail2ban rule times it out, instead of being dropped at once. On a link with a long idle timeout that is a noticeable window, and it differs from what the same limit does to a VLESS client. ### How to reproduce the problem 1. Create a Hysteria2 inbound and a client on it with `Limit IP = 1`. 2. Connect from IP A and start a transfer. 3. Connect from IP B with the same credentials. 4. `/var/log/x-ui/3xui.log` records the violation, fail2ban bans IP B. 5. The session from IP B stays alive until it times out; a VLESS client in the same test drops immediately. ### Expected behavior Either the Xray API user removal covers `hysteria` too, or the limitation is stated in the docs next to `Limit IP`, so the difference between protocols is not discovered in production. ### Actual behavior The disconnect is skipped and only the warning above is logged. ### 3x-ui version 3.6.0 ### Xray-core version 26.7.28 ### How did you install 3x-ui? Install script ### Operating system Ubuntu 24.04
bsakaguchi 2026-10-31 20:38:16 +07:00
  • closed this issue
  • added the
    bug
    label
Author
Owner

@github-actions[bot] commented on GitHub (Aug 18, 2026):

Confirmed on main. The guard you quoted is still present and is the cause; this is a separate defect from #5350 (which changed the generated Fail2ban action), so this issue stays open rather than being closed as a duplicate.

Title: IP-limit force-disconnect skips Hysteria2 (and WireGuard) because disconnectClientTemporarily uses a stale protocol allowlist

Severity: Medium

Category: Correctness

Why this matters: on a Hysteria2 inbound the panel falls back to Fail2ban alone, while vmess/vless/trojan/shadowsocks inbounds get both the ban and an immediate teardown through the Xray API. Enforcement of the same Limit IP value therefore differs by protocol, and the difference is only visible in a warning line in the log.

What I found:

  • internal/web/job/check_client_ip_job.go:637-645 — the allowlist, introduced with the comment "Only perform remove/re-add for protocols supported by XrayAPI.AddUser".
  • That comment no longer matches the API layer. buildUserAccount in internal/xray/api.go:533 has a real case "hysteria" at line 614 returning hysteriaAccount.Account{Auth: ...}, and a case "wireguard" at line 622. So the job's list is narrower than what XrayAPI.AddUser actually supports, and wireguard is skipped for the same reason.
  • Live user alteration on Hysteria2 inbounds is already used elsewhere in the panel: internal/web/runtime/local.go:115 gates AddUser only on MTProto, and AddClient at line 132 passes auth in the user map, so ordinary client add/edit on a Hysteria2 inbound already goes through AlterInbound.
  • The job builds clientConfig by marshaling model.Client at internal/web/job/check_client_ip_job.go:627, and Auth carries the JSON tag auth (internal/database/model/model.go:879), so the map already contains the field buildUserAccount requires for hysteria — no extra plumbing like the shadowsocks cipher patch at lines 649-658.
  • Unsupported protocols are no longer a panic risk at the API layer (the historical reason for a defensive list, cf. #4056): buildUserAccount returns (nil, nil) for anything it does not know, and AddUser returns early at internal/xray/api.go:678-680.

Recommendation for @MHSanaei:

internal/web/job/check_client_ip_job.go, disconnectClientTemporarily, line 640

  case "vmess", "vless", "trojan", "shadowsocks":

Add "hysteria" (and "wireguard") to that case, or drop the allowlist entirely and
let AddUser's own nil-account early return (internal/xray/api.go:678-680) handle
protocols it cannot alter. Note also that this job calls xray.XrayAPI directly
(line 612) instead of dispatching through runtime.Runtime, contrary to the
layering rule in CLAUDE.md.

One caveat, and the reason the second half of your "Expected behavior" may still apply: whether xray-core's Hysteria2 inbound tears down an in-flight QUIC session on RemoveUser, or only refuses new authentications, is core-side behaviour I could not verify from this repository. If it is the latter, the documented-limitation route is the accurate outcome. Either way the docs are currently silent on it — docs/content/docs/en/config/clients.mdx:20 lists Limit IP as applying to "all" protocols and mentions only Fail2ban enforcement, with no note about the immediate-disconnect path or its protocol scope.

Confidence: High that the allowlist at line 640 is what skips the disconnect for hysteria, and that AddUser supports the protocol. Medium that widening the allowlist alone produces an immediate drop of the established session, for the core-side reason above.

This reply was generated automatically. A maintainer may follow up.

<!-- gh-comment-id:5329976788 --> @github-actions[bot] commented on GitHub (Aug 18, 2026): Confirmed on `main`. The guard you quoted is still present and is the cause; this is a separate defect from #5350 (which changed the generated Fail2ban action), so this issue stays open rather than being closed as a duplicate. Title: IP-limit force-disconnect skips Hysteria2 (and WireGuard) because `disconnectClientTemporarily` uses a stale protocol allowlist Severity: Medium Category: Correctness Why this matters: on a Hysteria2 inbound the panel falls back to Fail2ban alone, while `vmess`/`vless`/`trojan`/`shadowsocks` inbounds get both the ban and an immediate teardown through the Xray API. Enforcement of the same `Limit IP` value therefore differs by protocol, and the difference is only visible in a warning line in the log. What I found: - `internal/web/job/check_client_ip_job.go:637-645` — the allowlist, introduced with the comment "Only perform remove/re-add for protocols supported by XrayAPI.AddUser". - That comment no longer matches the API layer. `buildUserAccount` in `internal/xray/api.go:533` has a real `case "hysteria"` at line 614 returning `hysteriaAccount.Account{Auth: ...}`, and a `case "wireguard"` at line 622. So the job's list is narrower than what `XrayAPI.AddUser` actually supports, and `wireguard` is skipped for the same reason. - Live user alteration on Hysteria2 inbounds is already used elsewhere in the panel: `internal/web/runtime/local.go:115` gates `AddUser` only on MTProto, and `AddClient` at line 132 passes `auth` in the user map, so ordinary client add/edit on a Hysteria2 inbound already goes through `AlterInbound`. - The job builds `clientConfig` by marshaling `model.Client` at `internal/web/job/check_client_ip_job.go:627`, and `Auth` carries the JSON tag `auth` (`internal/database/model/model.go:879`), so the map already contains the field `buildUserAccount` requires for `hysteria` — no extra plumbing like the shadowsocks `cipher` patch at lines 649-658. - Unsupported protocols are no longer a panic risk at the API layer (the historical reason for a defensive list, cf. #4056): `buildUserAccount` returns `(nil, nil)` for anything it does not know, and `AddUser` returns early at `internal/xray/api.go:678-680`. Recommendation for @MHSanaei: ``` internal/web/job/check_client_ip_job.go, disconnectClientTemporarily, line 640 case "vmess", "vless", "trojan", "shadowsocks": Add "hysteria" (and "wireguard") to that case, or drop the allowlist entirely and let AddUser's own nil-account early return (internal/xray/api.go:678-680) handle protocols it cannot alter. Note also that this job calls xray.XrayAPI directly (line 612) instead of dispatching through runtime.Runtime, contrary to the layering rule in CLAUDE.md. ``` One caveat, and the reason the second half of your "Expected behavior" may still apply: whether xray-core's Hysteria2 inbound tears down an in-flight QUIC session on `RemoveUser`, or only refuses new authentications, is core-side behaviour I could not verify from this repository. If it is the latter, the documented-limitation route is the accurate outcome. Either way the docs are currently silent on it — `docs/content/docs/en/config/clients.mdx:20` lists `Limit IP` as applying to "all" protocols and mentions only Fail2ban enforcement, with no note about the immediate-disconnect path or its protocol scope. Confidence: High that the allowlist at line 640 is what skips the disconnect for `hysteria`, and that `AddUser` supports the protocol. Medium that widening the allowlist alone produces an immediate drop of the established session, for the core-side reason above. *This reply was generated automatically. A maintainer may follow up.*
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#4246
No description provided.