Commit Graph
4 Commits
  • fix(job): skip fail2ban IP limit when disabled (#4581)
    Honor XUI_ENABLE_FAIL2BAN before running fail2ban-dependent IP-limit work. This avoids spawning fail2ban-client on disabled Docker installs while preserving the default enabled behavior when the env var is unset.
    
    Co-authored-by: Mayurifag <Mayurifag@users.noreply.github.com>
  • test(iplimit): align ban-policy tests with last-IP-wins (#4699)
    PR #4699 restored the "keep newest live IP, ban the oldest" policy in
    check_client_ip_job.go but left the integration test asserting the old
    "protect original, ban newcomer" behavior, so it failed. Update the test
    to expect the oldest live IP banned and the newest kept, and fix the now
    misleading name/comment on the partitionLiveIps concurrency unit test.
  • iplimit: dont count idle db-only ips toward the per-client limit
    after #4083 the staleness window is 30 minutes, which still lets an ip
    that stopped connecting a few minutes ago sit in the db blob and keep
    the protected slot on the ascending sort. the ip that is actually
    connecting right now gets classified as excess and sent to fail2ban,
    and never lands in inbound_client_ips.ips so the panel doesnt show it
    until you clear the log by hand.
    
    only count ips observed in the current scan toward the limit. db-only
    entries stay in the blob for display but dont participate in the ban
    decision. live subset still uses the "protect oldest, ban newcomer"
    rule.
    
    closes #4091. followup to #4077.
  • Fix IP Limit continuous ban loop from stale DB entries (#4077)
    After 60abeaa flipped the excess-IP selector to "oldest wins,
    newest loses" (to protect the original/current connections), the
    per-client IP table in `inbound_client_ips.ips` never evicted IPs
    that stopped connecting. Their stored timestamp stayed ancient, so
    on every subsequent run they counted as the "oldest protected"
    slot(s) and whichever IP was actually using the config now was
    classified as "new excess" and re-banned via fail2ban.
    
    This is exactly the #4077 scenario: two IPs connect once and get
    recorded, the ban lifts after the configured duration, the lone
    legitimate IP that reconnects gets banned again, and again, and
    again — a permanent 3xipl.log loop with no real abuser anywhere.
    
    Fix: when merging the persisted `old` list with the freshly
    observed `new` log lines, drop entries whose last-seen timestamp
    is older than `ipStaleAfterSeconds` (30 minutes). A client that's
    actually still active refreshes its timestamp any time xray emits
    a new `accepted` line for a fresh TCP, so the cutoff is far above
    even idle streaming sessions; a client that's genuinely gone falls
    out of the table in bounded time and frees its slot.
    
    Extracted the merge into `mergeClientIps` so it can be exercised
    by unit tests without spinning up the full DB-backed job.
    
    Tests cover:
    - stale old entry is dropped (the #4077 regression)
    - fresh old entries are still carried forward (access-log rotation
      is still backed by the persisted table)
    - newer timestamp wins when the same IP appears in both lists
    - a clock-skewed old `new` entry can't resurrect a stale IP
    - a zero cutoff never over-evicts
    
    Closes #4077