Commit Graph
3657 Commits
  • feat(ci): let the review bot read the discussion, the issue and xray-core
    The bot never read the replies under its own findings, so a finding a
    maintainer had already declined came back on the next `@claude review`.
    It now reads every comment and inline thread first: a maintainer's answer
    settles a finding for good, anyone else's is a claim checked against the
    code, and the summary gives each earlier finding a disposition. It also
    reads the issue the PR claims to fix and reports a partial fix.
    
    REVIEW.md asks for an upstream symbol behind every wire-format claim, but
    the job had no xray-core source (#6718's review said so). The module the
    base go.mod pins is now unpacked into a hidden dir in the base workspace;
    nothing from pr-head runs.
    
    REVIEW.md gains the rules only /senior-review carried: keep read,
    reproduced and inferred claims apart, evidence for performance findings,
    a traced trust boundary for security ones, and duplicated logic as a
    finding. The summary now says each inline finding in one line.
  • fix(ci): stop the review bot naming where the fix belongs
    65b9bfed narrowed the fix carve-out to "one clause naming WHERE the fix
    belongs", but the bot still closes every finding with that clause, and set
    beside the defect it already named, the location is the fix. On #6718 it
    listed the two capabilities the bounding set lacks, then wrote "The fix
    belongs in the capability bounding set". Drop the carve-out from REVIEW.md
    and the workflow prompt: the finding's file:line already says where.
  • fix(sub): carry REALITY ML-KEM hint in VLESS links (#6712)
    * fix(sub): carry REALITY ML-KEM hint in VLESS links
    
    Keep raw share links in parity with Clash subscriptions for Xray 26.9.8+. Preserve the URI hint through Go and frontend imports, expose it in the outbound editor, and update the documentation tooling.
    
    * fix(link): accept REALITY ML-KEM boolean aliases
    
    * test(frontend): isolate Happ preset notifications
    
    * fix(link): keep the ML-KEM hint out of Xray REALITY settings
    
    support-x25519mlkem768 is a Mihomo reality-opts option; xray-core's
    REALITYConfig (infra/conf/transport_security.go) has no such field and its
    JSON loader drops unknown keys silently. The PR also stored it as
    realitySettings.supportX25519Mlkem768 in Xray outbounds (form switch, Go and
    TS link import, docs outbound builders) and as an inbound settings default
    that is stripped before Xray and read by no link generator. The outbound
    switch therefore did nothing, and imported links carried a dead key into the
    JSON subscription.
    
    The share-link hint itself stays: Go, frontend and docs still emit
    support-x25519mlkem768=true on VLESS REALITY links and drop it on a TLS host
    override.
    
    ---------
    
    Co-authored-by: libmur-dev <333915961+libmur-dev@users.noreply.github.com>
    Co-authored-by: MHSanaei <ho3ein.sanaei@gmail.com>
  • fix(maskcompat): size xdns domain list from domains alone
    CodeQL (go/allocation-size-overflow, alerts #115/#116) flagged the
    len(rawDomains)+len(rawResolvers) capacity hint. The sum cannot overflow
    in practice, but the hint bought nothing: resolver-derived domains are
    deduplicated and append grows the slice as needed.
  • chore(deps): update project dependencies
    Refresh Go, frontend, and documentation dependencies, including MSW 3 and pnpm 12.8.1. Update the MSW test setup to use the renamed `onUnhandledFrame` option.
  • feat(xray): update xray-core to v26.9.30 and adapt panel
    Bump xtls/xray-core to b26a91de4f (v26.9.30) and the three binary pins
    (DockerInit.sh, release.yml Linux + Windows) in lockstep. No deleted
    symbols; the sing and sing-shadowsocks indirect deps drop out with the
    SS2022 rewrite.
    
    XDNS finalmask (#6718) replaced its string lists with objects: domains
    are {name, types, edns0, lenLimit, labelLimit} and client resolvers
    {type, settings.addr}. The loader no longer parses the old lists, so a
    single stored xdns mask keeps the whole core from starting. The new leaf
    package internal/util/maskcompat converts them: "name[:type]" becomes a
    domain and "name[:type]+udp://addr" a domain plus a udp resolver. A bare
    name maps to TXT, the type legacy clients queried by default, and each
    converted domain keeps the 1232-byte EDNS0 the old code always used
    (without it the server caps answers at 512). It runs from:
    - the XdnsFinalmaskObjectsFix seeder, over inbound streams, hosts, the
      xray template, the global sub-JSON mask and cached subscription
      outbounds;
    - inbound save (normalizeStreamSettings) and GetXrayConfig, for rows
      that never went through the seeder;
    - both link importers, since fm= from an older panel carries the lists.
    The finalmask form edits the object shape (every key needs a registered
    field, or the finalmask watch drops it on save) and lifts legacy masks
    on open. The udp-mask golden fixture moves to the object shape, which
    TestGoldenStreamFixturesBuildInXray now builds through the core. The
    wire format changed as well, so pre-upgrade clients need the new core.
    
    WireGuard outbound (#6771) dropped settings.domainStrategy and the
    remoteDNS "local" mode. The endpoint lookup now follows
    sockopt.domainStrategy and in-tunnel targets the outbound's
    targetStrategy. The old key is silently ignored, which undid the
    IPv4-first endpoint lookup the WARP outbound depends on (#5205), and
    "local" now panics the core at startup because remoteDNS goes through
    netip.MustParseAddr. The WireguardDomainStrategyFix seeder moves a stored
    family preference to both keys (a value already set wins) and turns
    "local" into targetStrategy; the outbound form lifts legacy rows the same
    way and drops its select, the WARP modal writes the new placement, and
    the inbound form loses a field the server never read.
    ValidateOutboundConfig now refuses a non-IP remoteDNS entry, which
    conf.Build() lets through, on template save and for outbound
    subscriptions.
    
    Noise finalmask items accept type "exp" (#6862), a tag expression. The
    form offers it for noise items only: header-custom items go through the
    core's PraseByteSlice, which refuses it.
    
    TUN gained autoSystemDnsToGateway (Linux) and autoSystemWfpBlockLeak
    (Windows). Both pass through the settings schema so a value set in JSON
    survives the next form save.
    
    MASQUE (inbound, outbound, transport) and the XDRIVE transport are new
    protocols the panel does not offer yet; their new loader refusals only
    cover configs the panel never generates. The FakeDNS IPv6 pool default,
    the SS2022 rewrite (same gRPC account; emails are now deduped
    case-insensitively, as the panel already does), the restored udphop
    interval default and the rest change no panel-facing config.
  • fix(frontend): keep the given file name on mobile downloads
    FileManager typed every download text/plain. Android's MediaStore appends
    the MIME type's extension whenever the name's own extension maps elsewhere,
    so a subscriber saving a WireGuard config got peer.conf.txt, which the
    WireGuard app refuses; .json, .yaml and .log downloads were renamed the same
    way. Desktop browsers honour the download name, which is why only phones
    saw it. application/octet-stream carries no extension of its own, so the
    name the panel chose is kept.
  • fix(hosts): advertise Hosts in every WireGuard, AmneziaWG and TUIC config
    Invariant: an inbound's enabled Hosts are the endpoints every client config
    for it advertises, whichever surface renders that config.
    
    WireGuard and AmneziaWG broke it. Their raw generators ignored the
    externalProxy entries Hosts are injected as and always emitted
    resolveInboundAddress, so the raw subscription, the sub page .conf, the
    clients links API and "export all links" gave out the panel address while
    the JSON and Clash formats of the same inbound used the Host.
    advertisedEndpoints now states the fan-out once for mtproto, wireguard and
    amneziawg.
    
    The browser-built configs had the same gap. The Clients page WireGuard and
    AmneziaWG config blocks and QR panels, and its TUIC Clash config, used the
    panel hostname next to server links that already used Hosts; the Inbounds
    page peer configs, QR and export ignored them too. withMtprotoHostEndpoints
    becomes withHostEndpoints over a shared hostEndpointsFor mirror of the
    backend, the tunnel fan-outs render one config per Host, and the clients
    page waits for the hosts list the way the inbounds page does, so an empty
    list means "no hosts" rather than "not loaded yet".
  • docs(architecture): fix table padding flagged by oxfmt
    The NodePendingReset row added in 4210a50c had one extra space of padding,
    failing the Docs CI format check.
  • fix(inbounds): keep the stored client list and enable on inbound save
    Invariant: saving an inbound's configuration never changes which clients it
    holds nor whether it is enabled; both have their own endpoints. The edit
    modal posts back the clients and the enable flag it loaded when it opened.
    A client added meanwhile (another admin, the bot, the API, LDAP) was
    detached and its stats deleted; a client deleted meanwhile came back with
    its credentials, restoring access that had been revoked; an inbound
    switched off meanwhile was switched back on.
    
    For every save but a master's node-sync push, UpdateInbound now takes the
    client list and enable from the row it re-reads inside the writer; this
    replaces the lifecycle-only carry from the previous commit. Client
    validation (renewal schedule, Hysteria auth, TUIC credentials) moves after
    that swap so it judges the clients actually saved: a protocol switch keeps
    the stored clients, and #6268's refusal must apply to them.
    
    The edit form no longer loads or sends clients, so neither the JSON editor
    nor validation sees a copy the server ignores, and the enable switch shows
    only when adding; the list toggle (/setEnable) covers existing inbounds.
    
    Tests that added or re-keyed clients through a panel inbound save pinned
    the old rule; they now drive the master-push path, where payload clients
    still apply.
  • fix(mtproto): zero sidecar quotas only for clients whose usage was reset
    Invariant: the sidecar's quota counter for a client is zeroed exactly when
    the panel zeroes that client's usage. InboundService.ResetAllTraffics
    resets only inbound counters, yet it cleared every MTProto client's
    sidecar quota - on the master and, through its node propagation, on every
    node - handing out a fresh quota while the panel still counted the old
    usage. ResetAllClientTraffics for one inbound likewise cleared the quotas
    of MTProto clients on every other inbound.
    
    The inbound-level reset no longer touches sidecar quotas, and the
    per-inbound client reset zeroes only the clients it reset.
  • fix(traffic): make a client reset reach every counter enforcing its quota
    Invariant: a client traffic reset zeroes every counter that enforces the
    client's quota - the master's, each hosting node's, and the local MTProto
    sidecar's. A node cuts a client on its own local counters, and the master
    adopts that verdict when both judged the same limits (#4917).
    
    Node counters: ResetClientTraffic tried the node once and dropped a
    failure ("nothing replays a reset"); BulkResetTraffic,
    ResetAllClientTraffics and ClientService.ResetAllTraffics never told the
    node at all. The node kept its pre-reset usage, switched the client off
    again on its next tick, and the master latched that - a client shown at
    zero usage stayed disabled.
    
    Every reset path now queues a node_pending_resets row per hosting node in
    its own transaction. It is delivered right after commit (per-client
    endpoint up to the push threshold, bulkResetTraffic above) and replayed by
    the node sync ahead of its snapshot, and dropped only once the node
    accepted it. While one is owed, the merge takes only that client's usage
    from the node, not its enable or limits. Deliveries to a node are
    serialized so a reset is not sent twice.
    
    Sidecar quota: BulkResetTraffic, ClientService.ResetAllTraffics and
    auto-renew zeroed the panel counters but not mtg's own quota counter, so
    the sidecar kept refusing a renewed or reset MTProto client. They now
    reset it too, scoped to the affected clients.
  • fix(runtime): drop depleted clients by email, not by stale inbound_id
    Invariant: a client whose stats row is switched off is served by no local
    runtime of any inbound it is attached to. client_traffics is email-keyed,
    and AddClientStat re-points its inbound_id at the last inbound attached,
    yet the runtime push builder and the MTProto, TUIC and AmneziaWG desired-
    instance builders looked the row up by inbound_id. On every other inbound
    of a multi-inbound client the depletion filter saw nothing, so a depleted
    client stayed served there whenever its settings entry still read enabled
    - the state the stale settings writes left in existing databases.
    
    All four now resolve the flag through trafficDisabledEmails, keyed by the
    emails the inbound actually lists. GetXrayConfig already backfills sibling
    rows by email (backfillClientStats) and is unchanged.
  • fix(inbounds): keep stored client lifecycle and counters on inbound save
    Invariant: saving an inbound's configuration never changes a client's
    enable, expiry, quota or renewal state, nor the inbound's own traffic
    counters. The inbound modal posts back the whole settings.clients list it
    loaded when it opened, and UpdateInbound stored it, synced it into the
    client records and wrote it into client_traffics. Any client renewed,
    depleted or reset while the modal was open was reverted - a renewed client
    came back disabled with its old expiry. The row itself was read before the
    serialized tx and saved whole, so traffic the poll added in between was
    rolled back and a depleted inbound could be re-enabled.
    
    UpdateInbound now re-reads the row inside the writer and, for clients the
    inbound already holds, keeps enable, expiryTime, totalGB, reset, resetDay,
    resetWeekday and resetMax from it; those change through the client
    endpoints. A master's node-sync push stays authoritative. Existing clients'
    lifecycle fields are no longer editable through the inbound JSON editor or
    /inbounds/update, which the API docs now state.
  • docs(media): refresh panel screenshots for v3.8.5
    The README screenshots still showed the v3.2.5 layout. Retake every panel
    page in light and dark on the current UI, and redo the annotated Telegram
    bot setup shot for the new sidebar layout, marking the enable toggle too.
  • fix(clients): zero traffic before re-enabling a client on reset
    Invariant: a traffic reset leaves a quota-disabled client enabled
    everywhere. ResetTrafficByEmail and BulkResetTraffic enabled the client
    first and zeroed its counters afterwards. A traffic tick landing between
    the two still saw the client depleted and switched it off again in
    client_traffics, the record and settings. Update's direct record write
    then set the record back to enabled and the reset zeroed the counters,
    leaving the settings entry disabled: the client showed enabled with zero
    usage but was dropped from the runtime. The periodic reset job goes through
    ResetTrafficByEmail for every depleted client on its cycle, and a node push
    inside Update widens the window to seconds.
    
    Zero first, then enable: with the counters at zero the depletion predicate
    no longer matches, so the tick has nothing to undo. UpdateInboundClient
    re-adds the enabled user to the runtime itself.
  • fix(clients): stop client ops from reverting a renewal committed mid-op
    Invariant: an operation on an inbound's clients writes back only what it
    changed, onto the settings as committed when it writes. Every client op
    (add, edit, delete, bulk adjust/detach/delete/set-enable) read the inbound
    outside the serial traffic writer and then tx.Save'd the whole row inside
    it. A traffic tick that committed in between - auto-renew re-enabling a
    client, the delayed-start conversion, a node adoption - was overwritten
    with the stale copy. A renewed neighbour ended up enable=false with its old
    expiry in settings while client_traffics said enabled, so the next runtime
    rebuild dropped a healthy client nobody had touched. The bulk ops then ran
    a full SyncInbound from those stale settings, copying enable=false into the
    client record too.
    
    Each site now commits through commitInboundClientSettings: inside the
    serialized tx it three-way merges the op's edit (read -> output, per client
    and per field) onto the committed settings and updates only the settings
    column, which also stops the stale up/down/enable inbound columns being
    written back. advancePushedInbound now records what the per-client push
    delivered rather than the merged settings, so the node's reconcile-skip
    fingerprint cannot claim a renewal it never received.
  • fix(inbounds): accept v2.x client fields on inbound import
    Panels up to v2.x stored a client's tgId as a string, "" when unset. The
    startup migration heals copies already in the database, but an exported
    inbound imported into a current panel goes straight to AddInbound, whose
    typed client parse failed with "cannot unmarshal string into Go struct
    field .0.tgId of type int64", so every such import was refused.
    
    AddInbound now runs the legacy normalizer the clients-table seeder already
    used (moved from database to model so both share it) over the incoming
    settings before parsing them. String numbers become integers and empty ones
    are dropped, and the settings are stored in that shape. The same applies to
    /inbounds/add callers still sending the old types.
    
    The seeder change is a pure move; the PostgreSQL lane was not run (no
    Docker on this host) and is left to CI.
    
    Closes #6663
  • fix(x-ui.sh): read the service state without scanning the journal
    check_status ran `systemctl status x-ui` and grepped its Active line. That
    command also prints the unit's latest journal lines, so it reads the journal
    every time the menu is drawn, before most actions, and on hosts with months
    of logs the script stalled for a long time before showing its options.
    
    `systemctl show --property=SubState` returns the same "running" state from
    the unit alone. The prefix is stripped by hand rather than with --value so it
    still works on systemd older than 230.
    
    No test harness covers x-ui.sh. To demonstrate on a host with a large journal:
      time systemctl status x-ui >/dev/null
      time systemctl show --property=SubState x-ui
    
    Refs #6629
  • fix(wireguard): reject allowedIPs that overlap another client's range
    xray's WireGuard inbound credits a packet to the first peer whose allowedIPs
    contain its source address, and routes replies by the same table. The panel
    only rejected an allowedIPs entry that was string-equal to another client's,
    so a pre-assigned address typed in interface notation (10.10.2.9/24, as other
    WireGuard tools export it) was accepted and claimed the whole /24: other
    clients' traffic and online IPs were credited to that one email, and replies
    went to a peer with no endpoint ("no known endpoint for peer").
    
    The collision check now compares masked ranges on every path that uses it:
    add, edit, the cross-inbound recheck inside the write transaction, and
    AmneziaWG. Auto-allocation skips any address inside a prefix another client
    holds. A /0 default route still claims nothing, as before, because legacy
    migrated peers carry one. Clients already saved with overlapping ranges keep
    working as they do today until edited. The API docs describing the error are
    updated, including the stale claim that cross-inbound duplicates are accepted.
    
    Closes #6623
  • fix(tgbot): build a client's individual links in-process
    The bot's "individual links" and QR actions fetched the client's own
    subscription over HTTP from the public URL it builds for display. With no
    sub or web domain set that URL falls back to the machine's hostname, which
    usually does not resolve (`lookup exhausted-reply: no such host`), and even
    a resolvable name fails behind NAT, a firewall or a disabled sub server.
    
    Both actions now ask InboundService.GetSubLinks, the in-process provider the
    panel's links API already uses, with the host taken from that same URL so the
    link addresses are unchanged. The now-unused pooled HTTP client goes too.
    
    Closes #6597
  • fix(i18n): scope the empty Min Client Ver hint to cores that honour it
    The REALITY Min Client Ver hint promised that an empty field accepts every
    client version. That is only true on Xray-core v26.9.8+, but the panel's
    core switcher still installs v26.7.11 to v26.9.7, where an empty field falls
    back to a built-in 26.3.27 minimum and silently diverts older and
    third-party clients (Mihomo, sing-box) to the REALITY target. Operators on
    those cores were told the field was not the cause.
    
    The hint now names the version boundary in all 13 locales, matching the
    docs site. Text-only: no test can reach it; the change is visible in the
    inbound form's REALITY tooltip after `npm run build`.
    
    Closes #6568
  • feat(panel): let a sponsor slot start at a scheduled time
    sponsors.json only had an end date, so a booked placement had to be
    added to the file on the day it started. An optional `from` now hides
    a sponsor (and its logo) until that instant; entries without it show
    immediately as before.
  • fix(amneziawg): let the wrapped bind build peer endpoints
    resolvingBind.ParseEndpoint resolved a hostname and then built a
    StdNetEndpoint itself. That matches StdNetBind, the default bind on
    Linux, but on Windows the default is WinRingBind, whose Send refuses any
    endpoint it did not parse ("endpoint type does not correspond with bind
    type"). Every handshake initiation failed there, so no AmneziaWG tunnel,
    inbound or outbound, could come up on the Windows builds. ParseEndpoint
    now hands the resolved literal to the wrapped bind's own parser, which
    returns the endpoint type that bind sends to; StdNetBind and pinnedBind
    build the same StdNetEndpoint as before.
    
    The resolvingBind tests now read endpoints through the Endpoint
    interface instead of asserting StdNetEndpoint, which had pinned the bug.
  • fix(amneziawg): fall back to a free egress port when 64900 is refused
    The panel's SOCKS5 egress for AmneziaWG outbounds bound the fixed
    127.0.0.1:64900, and every generated socks bridge dialed that constant.
    64900 sits inside Windows' dynamic port range, where the OS can reserve
    whole blocks (this host excludes 64885-64984), so on the Windows builds
    release.yml ships the listener could stay down and every AmneziaWG
    outbound with it. Listen now tries 64900 first and falls back to any
    free loopback port; bridges, the outbound probe and the port-conflict
    check use EgressPort(), the port actually held. Bridges are generated
    apart from the listener, so BuildSocksBridge records the port it wrote
    and the AmneziaWG job requests an Xray restart while the listener holds
    a different one. Where 64900 is free nothing changes.
    
    The job's restart request is two lines of wiring no test reaches; the
    staleness it acts on is pinned by
    TestBridgesStaleUntilRegeneratedForTheBoundPort.
  • style(settings): fold the Happ settings into four tabs
    Seven tabs, several holding one or two settings, made the page hard to
    scan. The encrypted-links switch moves above the tabs under
    auto-detection, the colour profile joins the banners under Appearance &
    Theme, and Android per-app proxy joins Network & TUN Engine. The QR
    modal's settings link no longer needs a happTab selector, and the three
    orphaned tab-label keys are dropped from every locale.
  • style(clients): put Traffic Reset and Auto renewal on one row
    The renewal block took a full-width column, pushing Traffic Reset onto
    its own line. Each now gets a half-width column like the other fields,
    with its follow-up inputs stacked under it.
  • fix(nodetoken): stop refusing every node-token key file on Windows
    FileKeySource rejected any key file whose mode had group or other bits,
    but Windows has no such bits: Stat reports every writable file as 0666.
    On the Windows builds release.yml ships, the key file therefore never
    loaded, not even one written 0600, and only XUI_NODE_TOKEN_KEY could
    supply a key. The mode check now applies off Windows only, the stance
    the DB permission tests already take; there the file's NTFS ACL guards
    it, and env-vars.mdx says so in all four locales.
    
    The load test is split so the half that must hold everywhere, an
    owner-only file loading, also runs on Windows, and the rejection half
    asserts the exact error instead of any error.
  • fix(panel): skip the proxy env forwarding test on Windows
    Windows env var names are case-insensitive, so https_proxy and
    HTTPS_PROXY resolve to the same variable there and updateProxyEnvVars
    forwards it under both names. The helper only runs on Linux - startUpdate
    refuses every other platform - so the test's case-sensitive expectations
    only hold, and only matter, on Linux.
  • fix(logger): reuse the open log rotator when InitLogger runs again
    Every InitLogger call built a new lumberjack rotator and dropped the old
    one without closing it, leaking a handle on 3xui.log per call, and
    loggers still writing through an old rotator kept it alive. On Windows
    the open handles block deleting the file, so
    TestInitLoggerConcurrentWithLogging failed its t.TempDir cleanup there.
    InitLogger now reuses the open rotator for the same path and closes it
    only when the path changes, and the test closes the logger it opened.
    Neither half is enough alone: with only one of them the test stays red
    on Windows.
  • fix(database): close the pool a second InitDB replaces
    InitDB assigned the new pool over the old one without closing it. The
    panel's own restore flows call CloseDB first, but any other re-init
    leaked the replaced pool and its handle on the database file. On Windows
    that handle blocks deleting the file, which is why the four GetApiToken
    CLI tests failed their t.TempDir cleanup there: dbtest.InitDB opened the
    store, then GetApiToken's own InitDB replaced it. InitDB now closes the
    previous pool itself; sql.DB.Close is idempotent, so the restore flows
    behave as before.
  • chore(git): check out every text file with LF, not only Go and scripts
    .gitattributes forced LF only for Go, shell, generated files, snapshots
    and deploy YAML, so a Windows clone with core.autocrlf=true got CRLF
    everywhere else. On that working copy `make format-check` flags 198
    frontend files, `msw-worker-check` sees mockServiceWorker.js differ from
    the installed copy, and TestAnalystContextNamesRealCIJobs and
    TestReviewNamesRealCIJobsAndGates find no ci.yml job at all, while Linux
    CI stays green. `* text=auto eol=lf` extends 5c5a5096 to every text
    file. No committed blob changes: the index already holds LF everywhere,
    and binary detection still leaves the 50 binary files alone.
    
    An existing Windows clone applies it with a fresh checkout on a clean
    tree: `git rm -rq --cached . && git reset -q --hard HEAD`.
  • refactor(logger): choose the console backend with build tags
    The runtime.GOOS switch compiled the syslog branch into Windows builds,
    where go-logging's syslog stub always returns an error. staticcheck
    therefore reported SA4023 at logger.go:95 on every Windows lint run,
    keeping `make lint-go` red on a clean main there while Linux CI never
    saw it. console_windows.go and console_other.go now pick the backend at
    build time, with each platform's behaviour unchanged.
    
    No test can observe build-tag selection: `golangci-lint run` on Windows
    goes from 1 issue to 0, and `GOOS=linux golangci-lint run
    ./internal/logger/...` stays clean.
  • feat(tgbot): access levels and /start account binding (#6518)
    * feat(tgbot): gate the bot behind three user levels
    
    Every Telegram account that found the bot could run /help, /status and
    /usage, and tap any client button it could forge: nothing separated an
    account no admin had bound from a customer.
    
    Each update now resolves to stranger, client or admin, and commands are
    allowlisted per level so a command added later stays admin-only until it
    is listed. A stranger may run /start and /id only, and /start answers with
    the ChatID an admin needs to bind it; a stranger's callbacks are answered
    and dropped. Client detection reads the same tgId lookup as
    clientOwnedByTgUser, so the level gate and the ownership check agree.
    
    The bot also ignores everything outside private chats: authorization keys
    on the sender while wizard state keys on the chat, and the two are the
    same identity only in a private chat.
    
    * feat(tgbot): bind Telegram accounts through /start deep links
    
    Linking a customer meant the customer sending /id and an admin copying
    the ChatID into the client by hand, which does not scale past a few
    customers and is easy to get wrong.
    
    The admin client card now offers an invite link, t.me/<bot>?start=<subId>,
    and the first account to open it is bound through the existing
    SetClientTelegramUserID. A subId already grants the subscription, so
    binding gives the holder nothing the token did not. A subscription that
    spans several clients binds all of them, and is refused if any part
    belongs to another account; re-opening your own link is idempotent.
    Unknown and already-claimed tokens share one reply, so the link cannot
    be used to probe for valid subIds.
    
    * fix(tgbot): harden invite claims after review
    
    Review of the access-level and binding change found five problems:
    
    - Concurrent claims of one link all read the client as unbound, all bound
      and all were told so, while only the last write held. Resolving and
      binding now share one lock, and a bind that fails part-way through a
      multi-client subscription undoes the bindings it already made.
    - A subId has no minimum strength and the bot needs only its public
      username, so /start was an unthrottled guessing oracle. Non-admin claim
      attempts are capped at five per account per hour, the first refused one
      notifies the admins, and the Subscription ID field now says it doubles
      as the bot invite code.
    - levelOf expanded every inbound's client JSON on every non-admin update.
      It now reads the indexed tg_id column of the clients table.
    - A button tapped in a group chat was dropped unanswered and kept
      spinning, with nothing logged. It is answered now, and each ignored chat
      is logged once.
    - The subId was pasted raw into the t.me link, so '#' or '&' truncated it
      and Telegram rejects anything outside A-Za-z0-9_-. The payload is now
      base64url, and a subId too long for the 64-character limit is refused.
    
    * fix(tgbot): answer group chats again and make the claim race test bite
    
    ignoredChat dropped every non-private chat because wizard state was
    keyed by chat while authorization keyed on the sender. #6604 on main
    re-keyed that state by (chat, user) so admins can drive the bot from a
    group, so after the merge the drop only took the whole bot away from
    those admins, report keyboards sent to a group included. The level gate
    already keys on the sender, so group chats need no special case.
    
    TestConcurrentClaimsBindOnlyOneAccount passed with inviteClaimMu
    removed: the first claimant took the pool's idle connection and bound
    before the rest had opened theirs, so no two ever raced. It now holds
    the inbound write the binds need until every claimant has resolved,
    and fails without the lock ("6 accounts told they bound").
    
    TestCommandAllowed restated the commandsByLevel map; TestGateCommand
    drives the same allowlist through gateCommand. TestIgnoredChat goes
    with the code it pinned.
    
    * docs(tgbot): document access levels and invite links
    
    The command table still said /help and /status answer anyone. An
    account no admin has linked now reaches only /start and /id, and a
    customer is linked through the client card's Invite Link, whose token
    is the Subscription ID. Updated in en, fa, ru and zh.
    
    ---------
    
    Co-authored-by: MHSanaei <ho3ein.sanaei@gmail.com>
  • feat(inbound): excludeFromSub hides links without disabling (#6463)
    * feat(inbound): excludeFromSub hides links without disabling
    
    Add a per-inbound flag that omits subscription output while keeping the
    inbound enabled for Xray, auth, and traffic accounting. Fixes #6435.
    
    * fix(inbound): excludeFromSub review follow-ups
    
    gofumpt model.go, sync docs OpenAPI, keep excludeFromSub master-authored
    on node mirror, and exercise the legacy add-column migration path in tests.
    
    * fix(sub): keep excluded inbounds' clients in the usage header
    
    The excludeFromSub filter sat in getInboundsBySubId's SQL, so an excluded
    inbound's clients never reached seenEmails in the raw, Clash or JSON
    renderer. A client that lives only on a hidden inbound (one client per
    inbound sharing a subId) dropped out of the Subscription-Userinfo usage,
    quota and expiry and out of the info-node state, while the inbound kept
    serving it and counting its traffic.
    
    The query returns every enabled inbound again; each renderer skips an
    excluded inbound's links but still counts its clients, the same rule the
    Clash renderer already applies to external links it cannot express.
    
    ---------
    
    Co-authored-by: mrchatam <mrchatam@users.noreply.github.com>
    Co-authored-by: MHSanaei <ho3ein.sanaei@gmail.com>
  • perf(tests): copy a migrated template DB instead of migrating per test
    Most tests opened a throwaway panel DB with database.InitDB, which runs the
    full AutoMigrate + seed on an empty file every time: ~230ms, and ~850ms under
    -race because GORM's reflection-heavy migration is what the detector slows
    most. internal/web/service does this in ~550 of its 830 tests, so the CI race
    job spent ~10 of its ~14.6 minutes re-migrating empty databases.
    
    internal/database/dbtest.InitDB migrates once per test process, then hands
    each test its own copy of that file (~130ms under -race) and registers the
    CloseDB cleanup. The copy then goes through InitDB like a panel restart, so
    every test still starts from the state a fresh install has. Tests that reopen
    an existing file, migrate a hand-built legacy DB or target Postgres keep
    calling database.InitDB.
    
    Locally under -race: internal/web/service 626s (last CI run) -> 114s,
    internal/sub 246s -> 35s.
  • feat(clients): preserve traffic counters in portable export/import (#6469)
    * feat(clients): preserve traffic counters in portable export/import
    
    ExportAll now attaches client_traffics up/down (plus resetCount and
    last-seen fields) on each portable payload, and ImportClients restores
    them only for newly created emails so skipped/existing clients keep
    their live counters. Fixes #5858.
    
    * fix(clients): restore imported traffic only onto rows the import created
    
    Review of the portable-traffic export/import (#5858) found four defects:
    
    - An orphan's restored row was hand-built, dropping reset_weekday and
      forcing enable=true; a row kept by a keepTraffic delete kept the old
      client's limits. depletedClientsClause then matched a weekly-renewing
      over-quota orphan and DelDepleted deleted it. Orphan rows now go
      through AddClientStat, whose upsert refreshes config and keeps counters,
      so the unused traffic.total field is dropped from the export.
    - Created clients were inferred from Skipped emails, so a duplicate email
      in the file left the created copy with zero counters. bulkCreate now
      reports which payloads inserted a record, and only those are restored.
    - Each client took its own serialized-writer commit: 2000 clients spent
      3.66s instead of 0.52s. Counters now apply in batched transactions
      (0.51s).
    - importClients discarded needRestart when the late restore step failed
      after clients were committed; it now flags and notifies first, as
      create already does.
    
    The /clients/export and /clients/import API docs now describe traffic.
    
    * fix(groups): keep imported traffic out of group totals
    
    Group totals keep a deleted client's usage (#5675), and the portable
    import restores that same usage onto the re-created client. Export,
    delete, re-import therefore counted it twice in ListGroups, and a fresh
    panel showed the migrated usage as consumption of its groups.
    
    Restored counters are usage from before the import, so the import now
    shifts each group's baseline up by what it restored, in the same
    transaction. A group total no longer moves at import time; only traffic
    consumed afterwards counts. The baseline shift reuses the #5675 helper,
    now signed.
    
    ---------
    
    Co-authored-by: Sanaei <ho3ein.sanaei@gmail.com>
  • chore(ci): stop release and CodeQL runs on PRs, drop deploy smoke tests
    The release matrix (7 Linux cross-builds + a CGO Windows build) ran on every
    PR and on every branch push, so a PR from a repo branch built everything
    twice. Release binaries now build only on main (dev channel) and version
    tags; any other branch can still be built via workflow_dispatch.
    
    CodeQL keeps its push-to-main and weekly scans but no longer runs per PR.
    
    The deploy smoke workflow fired on every Release completion only to skip
    its jobs; deploy/test/smoke-noninteractive.sh stays for manual runs.
  • feat(tgbot): add /broadcast to relay an admin message to all clients (#6510)
    * feat(tgbot): add /broadcast to relay an admin message to all clients
    
    Admins had no way to reach every client at once: notifications only
    cover exhausted quotas, so an operator had to copy a message to each
    client chat by hand. Add an admin-only /broadcast flow to the bot:
    
    - /broadcast asks for a message; any message the admin sends — text,
      rich text, photo, video, file, sticker or a whole album — becomes the
      broadcast by reference (admin chat + message ids), and a preview
      self-copy shows the admin exactly what recipients will get while
      rejecting content Telegram cannot copy before the run starts.
    - The draft references the original instead of parsing its content, so
      copyMessage/copyMessages deliver everything 1:1 on behalf of the bot
      with no forward header (the admin's identity stays private), no
      caption length pitfalls, and future Telegram message types work
      without new parsing.
    - A media group arrives as separate updates; its ids are buffered with
      a short debounce, sorted, and delivered as one copyMessages call so
      recipients see the original album.
    - Delivery runs in a background goroutine (common.GoRecover): sequential
      sends with a small pause, 429 retry_after honored per recipient,
      failures counted without stopping the run, progress edited into one
      card at most every 25 sends or 3 seconds, a cancel button checked
      between sends, and a final delivered/failed/skipped summary. The
      summary is edited into the card (only sent separately if the card is
      gone), so it is never duplicated.
    - Recipients repeat the notifyExhausted walk: clients with a linked
      tg_id, deduplicated, admins excluded — they already receive the
      reports. The message content is never logged.
    
    New i18n keys are added to all 13 locales.
    
    * fix(tgbot): harden broadcast composition per review
    
    - Key the composition per admin chat instead of one process-wide draft:
      two admins can now compose at once without dropping each other's
      drafts, and one admin's /broadcast no longer wipes another chat's
      half-collected album.
    - Bind each preview card to its own draft via a random token carried in
      the confirm callback, so a stale Send tap is answered with an error
      instead of delivering a newer, unapproved draft.
    - Ignore non-admin senders while a chat composes: the awaiting state is
      keyed by chat id, and in a group that chat is shared.
    - Check the cancel flag inside the flood-control retry loop, so a 429
      with a long retry_after no longer holds the single broadcast slot
      after the admin cancelled.
    - Scale the per-recipient pause by the copied batch size, so an album
      keeps the same per-second ceiling as a single message.
    - Trim the comment blocks that exceeded the two-line cap.
    
    * fix(tgbot): reset broadcast state on stop and classify 403 as skipped
    
    - Clear compositions and cancel the active run from StopBot, next to the
      per-chat draft resets: an album debounce timer, a confirmable token or
      a held runner slot must not outlive the receiver that created them.
    - Sleep flood-control waits in 5 s slices and re-check cancel and bot
      state between them, so a minutes-long retry_after no longer parks the
      single-runner slot after the admin cancelled or the bot stopped.
    - Count Telegram 403 (the chat never started the bot, or blocked it) as
      skipped instead of failed, log it at debug rather than one warning per
      recipient, and append one line to the summary naming the reason.
    - Trim the remaining comment blocks over the two-line cap.
    
    * fix(tgbot): count unreachable recipients in broadcast progress throttle
    
    The progress card refresh was keyed on sent+failed, which a 403 does not
    advance since unreachable chats were split out of the failure count. A
    streak of unreachable recipients while that sum sat on a multiple of
    broadcastProgressEvery (0 included, so from the very first recipient)
    edited the card once per chat, doubling the request rate the send delay
    is sized for and defeating the throttle. Count processed recipients.
    
    * fix(tgbot): key broadcast compositions by admin, not chat
    
    After #6604 moved conversation state to the admin (chatUser), the
    broadcast draft map stayed keyed by chat. Two admins composing in one
    group then shared a slot: the second admin's message dropped the first
    admin's draft, whose Send tap answered "went wrong" while only the other
    draft could go out - the same class #6604 fixed for the add-client
    wizard. Drafts, album buffers and confirm tokens now live under the
    admin who ran /broadcast.
    
    The router now hands handleBroadcastInput only the admin whose own
    /broadcast is awaiting input, so its sender re-check and the test that
    fed it a non-admin message directly (an input no route can deliver)
    are removed.
    
    ---------
    
    Co-authored-by: MHSanaei <ho3ein.sanaei@gmail.com>
  • feat(sub): add Incy app-management parameters (#6650)
    * feat(sub): add Incy app-management parameters
    
    The panel already pushes a set of Happ headers, but INCY documents its own
    lowercase header names and its own value domains, so a Happ-shaped payload gets
    ignored by the client (per-app mode is bypass|proxy, not on|bypass, and
    per-app-proxy-enable has no Happ counterpart at all). Add a sibling Incy path
    that emits exactly the documented headers.
    
    Covered, per https://docs.incy.cc/en/app-management/:
    - profile-description, sort-order, support-email, announce-url, premium-url
    - banner text/button/URL and the two hex colours
    - hide-url, hide-check, no-limit-enabled
    - per-app split tunnelling (enable/mode/list)
    - TCP fragmentation (enable/length/interval/packets)
    - UDP noise packets (enable/type/packet/delay)
    - DoH pre-resolution (enable/domain/IP)
    
    Each string setting is tri-state: an empty value omits the header, so an
    untouched panel never overrides the subscriber's own choice in the app. Values
    are validated against the documented domains and dropped when they do not
    match, and non-ASCII text is base64-wrapped the way the docs require for
    Cyrillic. INCY identifies itself as INCY/<version>/<platform>, which gates the
    headers behind the same auto-detect switch the Happ path uses.
    
    Headers the panel already emits for every client (Profile-Title, Support-Url,
    Profile-Web-Page-Url, Announce, Profile-Update-Interval, Subscription-Userinfo)
    and Incy's routing line are left as they are.
    
    The Premium API (theme, defaultPingProtocol, fallbackHosts, ...) is a separate
    encrypted endpoint and stays out of scope here.
    
    * fix(sub): keep Incy per-app list entries separate on the wire
    
    The Incy settings textarea takes one package per line, as Incy documents for
    per-app-proxy-list, but the header path ran the value through
    sanitizeHeaderValue, which deletes CR/LF. "com.google.chrome\norg.telegram.messenger"
    reached the client as the single bogus package
    "com.google.chromeorg.telegram.messenger", so per-app split tunnelling silently
    matched no app. Join comma- or line-separated entries as CSV instead.
    
    Also drop three tests that could not fail: TestIncyExcludesHappOnlyHeaders
    (ApplyIncyHeaders has no path that emits Happ headers, and the non-Happ UA
    gate is already pinned by TestApplyHappHeaders_Gating) and two UI tests that
    only asserted updateSetting received the key the JSX passes it.
    
    ---------
    
    Co-authored-by: DIMFLIX <dimflix@users.noreply.github.com>
    Co-authored-by: MHSanaei <ho3ein.sanaei@gmail.com>
  • feat(sub): make external subscription fetch User-Agent configurable (#6613)
    * feat(sub): make external subscription fetch User-Agent configurable
    
    Some providers reject fetches that do not send a known client User-Agent.
    Expose externalSubUserAgent as a panel setting (default v2rayNG/1.8.5)
    and use it when fetching client external subscription URLs.
    
    Fixes #6383
    
    * ci: retrigger frontend after npm registry maintenance
    
    The frontend job failed solely on `npm audit` while registry.npmjs.org
    returned 503 (Service Under Maintenance). Lint, typecheck, vitest, vite
    build, and storybook all passed. Local `npm audit --omit=dev
    --audit-level=high` now reports 0 vulnerabilities.
    
    * fix(sub): fall back to the default UA when the DB is not initialised
    
    externalSubUserAgent read the setting through SettingService.getSetting,
    which calls Model() on database.GetDB() and panics on a nil *gorm.DB.
    The fetch path's other DB read, service.ExternalSubscriptionHwid, already
    treats a nil DB as unreachable and sends no header; the new UA lookup
    did not, so any fetch before InitDB panicked instead of sending the
    historical v2rayNG/1.8.5.
    
    Production initialises the DB before the sub server starts, but the
    internal/sub fetch tests run without one: under make test-go's
    -shuffle=on, whenever one of them ran before the first InitDB test the
    panic aborted the whole package. Reproduced deterministically with
    go test -run '^TestDoFetchSubscriptionLinks_RejectsOversizedBody$'.
    
    ---------
    
    Co-authored-by: mrchatam <mrchatam@users.noreply.github.com>
    Co-authored-by: MHSanaei <ho3ein.sanaei@gmail.com>
  • feat(clients): add calendar weekly renewal and schedule previews (#6524)
    * feat(clients): add calendar weekly renewal and schedule previews
    
    Expose fixed-day, calendar-weekly, calendar-monthly, and disabled renewal
    through one shared selector in individual and bulk client forms. Store the
    weekly weekday separately (Monday 1 through Sunday 7) and use panel-local
    calendar dates rather than a fixed 168-hour duration. Resolve skipped or
    repeated midnights to the first valid instant of the selected date, and skip
    an entirely nonexistent calendar date rather than changing the weekday.
    
    Reuse the existing renewal writer and share its boundary alignment and
    per-period catch-up calculation with an authenticated, read-only preview.
    Keep monthly precedence for legacy records, fixed-day interval semantics,
    maximum renewal allowances, first-use durations, and operator-disabled
    settings unchanged. Selecting a mode does not rewrite an existing cutoff;
    an unset calendar cutoff requires an explicit action to choose the first.
    The last-valid-second preview uses the stored exclusive expiry, even when
    the billing calculation aligns a legacy last-second cutoff up to midnight.
    
    Carry weekly schedules through client persistence, paging, enable toggles,
    inbound settings, and node traffic reconciliation. Migrate missing or nullable
    weekday columns to disabled by default without altering existing limits, and
    include the new isolated-schema PostgreSQL regression in the live CI gate.
    
    Regenerate API contracts and reference documentation, add lifecycle and form
    regressions, and document timezone, quota-reset, and upgrade considerations.
    All participating nodes must be upgraded before weekly mode is enabled;
    older binaries ignore the new field. Independent periodic traffic resets and
    the optional month-end subscription-header display are not changed.
    
    * fix(clients): validate renewal schedules across inbound write paths
    
    Reject conflicting weekly/interval/monthly schedules and out-of-range
    weekdays on inbound creation and edits, legacy one-client apply paths,
    record/link synchronization, and traffic metadata writes. Validate imported
    traffic snapshots as well, before any inbound or client is persisted, so
    an inbound API cannot create a client that the clients page cannot toggle.
    
    Merge a weekly-related schedule as one timestamp-selected tuple rather
    than filling its zero fields from another renewal mode. Preserve empty
    migration snapshots and the existing non-weekly monthly/interval merge
    semantics. Renewal caps, counters, credentials, and deadlines are unchanged.
    
    Add regressions for nine write paths, unchanged records and runtime calls
    after rejection, valid inbound clients remaining editable, and duplicate
    record merges between individually valid renewal modes.
    
    * docs(clients): clarify depleted-client deletion risks on downgrade
    
    Explain in English and Chinese that older versions not only stop weekly
    renewal: their depleted-client cleanup can delete a weekly-only client once
    its expiry or quota is exhausted. This is conditional on cleanup, not an
    automatic deletion caused by downgrade itself.
    
    Recommend backing up and converting weekly schedules to a mode supported
    by every participating version before rollback, and avoiding cleanup while
    mixed versions or unconverted clients remain. Merely disabling weekly
    renewal does not restore the old binary's missing purge protection.
    
    * fix(clients): bound weekly renewal date searches
    
    Limit the search for a valid weekly calendar date to eight candidates so
    an unusual timezone cannot monopolize the single traffic writer. Exhaustion
    returns the original instant, allowing the existing catch-up forward-progress
    guard to stop without advancing expiry, consuming an allowance, resetting
    traffic, or falling back to a fixed-duration schedule that can drift.
    
    Reject a non-future calendar suggestion in the read-only preview instead of
    offering an immediately expired initial cutoff. Also report failed weekly
    catch-up as a search error when allowances remain, not as cap exhaustion.
    Existing preview errors use the form's current warning; no API schema or
    locale changes are needed.
    
    Exercise exhaustion with a synthetic valid TZif containing twelve skipped
    Sundays. This fault-injection case was red without the bound; it is not a
    claim that a production IANA timezone was observed hanging. Keep the Havana
    and Apia regressions for real skipped/repeated midnights and absent dates.
    
    * fix(tests): isolate weekly renewal preview timezone
    
    Stop the weekly search regression from replacing process-global time.Local.
    CI caught that assignment and its cleanup racing with background timer reads
    through time.Now, even though the top-level tests do not use t.Parallel.
    
    Pass the timezone and current instant into the unchanged preview calculation.
    The public service still validates the request and resolves the panel timezone;
    API responses, renewal accounting, and persisted client data are unchanged.
    
    Use fixed dates for both suggestion and catch-up exhaustion, removing the
    test's dependency on today's date and its unnecessary database setup. Keep a
    bounded-lifetime background clock reader to expose future global-timezone
    mutations under the existing race gate rather than disabling that check.
    
    * ci: retrigger PR checks
    
    Create an empty commit to request a fresh pull-request CI run after release dependency downloads failed with network errors.
    
    No source, dependency, or workflow changes are included. Retry the existing checks without bypassing them.
    
    * ci: retry PR checks and record deferred download hardening
    
    Request another CI run after the amd64 release job compiled successfully but failed during dependency fetching with exit code 4 (network failure).
    
    Record possible follow-up improvements for the Linux release fetch helper:
    - Print each download URL and destination, and preserve error details.
    - Reuse the existing curl configuration with up to five retries; add connection and per-attempt timeouts and a bounded retry window.
    - Download to a temporary file and promote it to the final filename only after a successful, non-empty transfer. Keep the job failing if downloads ultimately fail.
    - Validate successful downloads, recovery after a temporary failure, and correct failure after persistent errors before shipping such a change.
    
    These improvements are intentionally deferred, not implemented or tested by this commit. This commit is empty: renewal logic, dependencies, workflow configuration, check requirements, and TLS verification remain unchanged.
    
    ---------
    
    Co-authored-by: JacktheRanger <219502738+JacktheRanger@users.noreply.github.com>
  • feat(happ): add routing editor, optional ad blocking, and LAN bypass preset (#6545)
    * feat(happ): make ad blocking optional in routing presets
    
    Add an independent AdBlock toggle for Iran, China, and global presets, applied only when generating routing rules. Update the China preset to Bypass-CN and cover preset behavior and localized controls.
    
    * feat: add visual routing editor with JSON support and localization updates
    
    - Implemented a new modal for editing routing profiles with basic and advanced tabs.
    - Added functionality to load, parse, and generate routing profiles in JSON format.
    - Enhanced user experience with validation and error handling for JSON input.
    - Updated translations for Russian, Turkish, Ukrainian, Vietnamese, Chinese (Simplified and Traditional) to include new routing editor terms.
    - Created helper functions for managing routing profiles and generating deep links.
    - Added unit tests for routing editor functionalities and JSON handling.
    
    * feat: update routing editor to preserve null lists in profiles and enhance validation messages
  • chore(gen): regenerate types for addrFamily
    Regenerate frontend/src/generated/types.ts and zod.ts to include the new addrFamily enum type, produced by tools/openapigen from Go struct changes.
  • fix(amneziawg): sniff the relay with routeOnly; scope the v6 egress to IPv6 (#6654)
    * fix(amneziawg): sniff the relay with routeOnly
    
    The embedded AmneziaWG relay sniffed without routeOnly, so a sniffed SNI
    replaced the dial target. Telegram's FakeTLS recovery dials
    194.221.250.50:443 with SNI www.google.com; the rewrite sent it to real
    Google and the client looped on "TLS hash mismatch", stuck on "Connecting".
    
    Sniffing here exists only so domain routing rules can match; routeOnly
    keeps that and dials the IP the peer resolved. Fake-pool targets are
    still rewritten (the dispatcher ignores routeOnly for fakedns).
    
    Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
    
    * fix(amneziawg): send only IPv6 targets through the peer's v6 egress
    
    The per-peer IPv6 egress rule matched every flow of that peer, but its
    freedom outbound binds a v6 sendThrough and cannot dial an IPv4 target, so
    IPv4 DNS and any other unsniffed IPv4 traffic of such a peer failed.
    Sniffed TLS/HTTP only worked because the sniffed domain replaced the IP;
    with routeOnly on the relay that no longer happens.
    
    Limiting the rule to ::/0 keeps the peer's IPv6 identity for IPv6 targets
    and lets IPv4 targets take the regular outbound.
    
    Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
    
    ---------
    
    Co-authored-by: Kirill Rudenko <rudenko@npp-energy.ru>
    Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
    Co-authored-by: Sanaei <ho3ein.sanaei@gmail.com>
  • fix(xray): hot-apply Hysteria client changes without replacing the inbound (#6606)
    * fix(xray): hot-apply Hysteria client changes without replacing the inbound
    
    diffInboundUsers only allowed per-user AlterInbound ops for vless, vmess
    and trojan. For a hysteria inbound every client add/remove/update became
    DelInbound + AddInbound: the UDP listener was recreated and all QUIC
    sessions of that inbound were lost. quic-go sends no stateless reset, so
    every connected client stalled until its idle timeout (30s by default)
    after each unrelated client mutation.
    
    XrayAPI.AddUser already builds a hysteria account and Xray-core's
    hysteria server implements AddUser/RemoveUser, so adding the protocol to
    userDiffableProtocols is sufficient.
    
    Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
    
    * test(xray): say which branch each drop-guard protocol takes
    
    With hysteria in userDiffableProtocols its dropped client reaches the
    guard through the per-user diff, so the test named for protocols the
    diff cannot handle no longer described its hysteria case.
    
    ---------
    
    Co-authored-by: Claude Fable 5.1 <noreply@anthropic.com>
    Co-authored-by: MHSanaei <ho3ein.sanaei@gmail.com>
  • fix(sub): make Happ require auth on its local SOCKS/HTTP proxy (#6628)
    Happ ships its local SOCKS5 (127.0.0.1:10808) and HTTP inbounds with
    authorization disabled by default. Any app on the same device can then
    connect to that proxy, bypassing Android's per-app VPN routing, and learn
    the VPN server address - the leak publicly described in March-April 2026
    for Happ, v2rayNG and other VLESS clients. Happ fixed its Xray API
    exposure, but the unauthenticated local proxy remained.
    
    Happ exposes a standard subscription header for this (no Provider ID
    required): socks-auth-mode / http-auth-mode = auto|manual|from-json|
    disable. A new subscription setting, subHappLocalProxyAuth (default
    "auto"), sends both headers to Happ clients. Like every other Happ header
    it is emitted only when Happ auto-detect is enabled and the User-Agent is
    Happ, so panels that never opted into the Happ integration see no change.
    An empty value sends nothing and keeps the client's own setting.
    
    Verified on Happ Android 4.4.1 (Xray 26.7.28): a subscription carrying
    socks-auth-mode manual + a test user/password switched the client's
    Inbounds screen to Manual with those credentials on "refresh subscription",
    and "auto" switched it to Auto with generated credentials.
    
    Co-authored-by: Kirill Rudenko <rudenko@npp-energy.ru>
    Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
    Co-authored-by: Sanaei <ho3ein.sanaei@gmail.com>
  • fix(amneziawg): bound S1-S3 by the receive buffer, reject overlapping H (#6642)
    * fix(amneziawg): bound S1-S3 by the receive buffer, reject overlapping H
    
    The native AmneziaWG validator, both Zod schemas, both forms and the docs now
    follow the rules amneziawg-go actually enforces.
    
    S1-S3. A padded handshake message is 148+S1, 92+S2 or 64+S3 bytes
    (device/send.go). The peer reads each datagram into a [MaxMessageSize]byte
    buffer, where MaxMessageSize = MaxSegmentSize (device/pools.go,
    constants.go). MaxSegmentSize is 65535 on Linux/Android, 2016 on Windows and
    1700 on iOS (device/queueconstants_*.go). The limits are therefore
    S1 <= 1552, S2 <= 1608 and S3 <= 1636. Before, S1/S2 allowed 65535, which
    iOS peers silently drop, and S3 was capped at 64, a number inherited from the
    coinman-dev/3ax-ui port in #6105 with no stated reason. That cap blocked real
    configs such as Amnezia Premium's S3=1045. RandomTrailers only tops a packet
    up to 500 bytes (DefaultUdpWindow), so it never pushes a message past these
    limits.
    
    H1-H4. amneziawg-go refuses the whole device when the header ranges overlap
    ("headers must not overlap", device/uapi.go mergeWithDevice), and so does the
    kernel module (src/netlink.c). The panel did not check this, so an inbound
    with overlapping ranges saved and then failed to apply. A blank H is never
    sent, so the engine keeps its default, WireGuard's own type 1-4; the check
    treats blank fields that way. The docs said 1-4 "must not be used". They are
    valid and are the engine default, only unobfuscated without a
    HeaderProtectionKey. The docs also said amneziawg-go rejects S1+56 == S2. It
    does not (IpcSet accepts it). The panel keeps that rule as a fingerprint
    guard, and the docs now say so.
    
    Tests: the new params_test cases and the Zod bounds fail on the old code.
    TestValidatedObfuscationAlwaysApplies runs every accepted set through a real
    amneziawg-go IpcSet and now covers overlap, blank-H defaults, H=1-4, the
    exact S bounds and the full Amnezia Premium set. Before this fix it failed
    with "headers must not overlap".
    
    Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
    
    * fix(amneziawg): bound only inbound padding by the iOS receive buffer
    
    The 1700-byte iOS buffer limits what an inbound's clients can receive,
    but ValidateObfuscation also runs for outbounds, and the Xray template
    save re-validates every AmneziaWG outbound. An outbound whose remote
    server uses S1 above 1552 would have blocked every Xray settings save,
    though its values come from that server and are received on Linux.
    
    ValidateObfuscation keeps amneziawg-go's uint16 UAPI width for S1-S3;
    ValidateServerObfuscation adds the receive-buffer bounds and is what
    inbounds call. The outbound schema and form follow the same split.
    
    ---------
    
    Co-authored-by: Kirill Rudenko <rudenko@npp-energy.ru>
    Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
    Co-authored-by: Sanaei <ho3ein.sanaei@gmail.com>
  • fix: allow IPv4 and IPv6 inbounds to share a port (#6603)
    * fix: distinguish IPv4 and IPv6 listen conflicts
    
    * fix(ports): let an IPv4 address share a port only with a v6only wildcard
    
    xray listens on tcp/udp, and Go opens every wildcard listen, 0.0.0.0
    included, as one dual-stack socket unless sockopt.v6only is set. Treating
    :: and 0.0.0.0 as separate families let the panel save pairs the core
    then fails to bind, and it broke main's own TestListenOverlaps.
    
    listenOverlaps now takes the inbound's sockopt.v6only: a wildcard claims
    both families, or only IPv6 with v6only, so :: with v6only may share its
    port with an IPv4 address while a plain :: or 0.0.0.0 still may not.
    
    ---------
    
    Co-authored-by: MHSanaei <ho3ein.sanaei@gmail.com>