[PR #4086] [MERGED] hysteria: accept "hysteria2" as a protocol string (#4081) #5596

Closed
opened 2026-10-31 20:48:04 +07:00 by bsakaguchi · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/MHSanaei/3x-ui/pull/4086
Author: @pwnnex
Created: 4/22/2026
Status: ✅ Merged
Merged: 4/22/2026
Merged by: @pwnnex

Base: main ← Head: fix/hysteria2-protocol-aliases


📝 Commits (2)

  • eb4791a hysteria: also accept "hysteria2" protocol string
  • 17f67ef sub: dont panic on bad externalProxy entry in genHysteriaLink

📊 Changes

7 files changed (+60 additions, -21 deletions)

View changed files

📝 database/model/model.go (+13 -1)
➕ database/model/model_test.go (+22 -0)
📝 sub/subClashService.go (+4 -7)
📝 sub/subJsonService.go (+1 -1)
📝 sub/subService.go (+15 -7)
📝 web/service/inbound.go (+4 -4)
📝 xray/api.go (+1 -1)

📄 Description

Closes #4081.

The panel UI stores both Hysteria v1 and v2 as protocol = "hysteria" with settings.version telling them apart, so everywhere we compare protocol to model.Hysteria works for both variants on UI-created inbounds.

For inbounds that came in from somewhere else (imports, manual inserts, migrations from other panels) the stored protocol string can be literally "hysteria2". Every switch/filter we have misses that:

  • getInboundsBySubId SQL filters protocol in (...) without hysteria2
  • getLink switch has only case "hysteria"
  • genHysteriaLink returns "" on anything but model.Hysteria
  • buildProxy in clash dispatches on model.Hysteria only
  • subJsonService switch same
  • inbound.go validation and client-key lookups, xray/api.go AddUser same

Result: no link in subscription, no entry in the clash yaml, no error logged. The reporter describes it exactly.

Fix

Add Hysteria2 constant + IsHysteria(p Protocol) bool helper in database/model/model.go, use it (or a two-valued case) in the places listed above. No migration, no change to how the UI stores things. Existing "hysteria" inbounds hit the exact same code paths they did before.

Second commit is unrelated to the issue but touches the same function: int(ep["port"].(float64)) in the externalProxy fanout (from #4073) was a bare type assertion, which panics the subscription handler if any entry is missing port or has the wrong JSON type. Added an ok-check to skip malformed entries.

Test plan

  • go build ./... + go vet ./... clean
  • go test ./database/model/ — TestIsHysteria passes (6 cases including hysteria, hysteria2, empty, wrong-case, other protocols)
  • Manual: created a Hysteria2 inbound via the UI, subscription link still generated (no regression on the common path)

🔄 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/4086 **Author:** [@pwnnex](https://github.com/pwnnex) **Created:** 4/22/2026 **Status:** ✅ Merged **Merged:** 4/22/2026 **Merged by:** [@pwnnex](https://github.com/pwnnex) **Base:** `main` ← **Head:** `fix/hysteria2-protocol-aliases` --- ### 📝 Commits (2) - [`eb4791a`](https://github.com/MHSanaei/3x-ui/commit/eb4791a1cdabebbf0b0d5a81a40ecc7d88924656) hysteria: also accept "hysteria2" protocol string - [`17f67ef`](https://github.com/MHSanaei/3x-ui/commit/17f67ef3a51537cbb32b2fcd3884c26434f4ee62) sub: dont panic on bad externalProxy entry in genHysteriaLink ### 📊 Changes **7 files changed** (+60 additions, -21 deletions) <details> <summary>View changed files</summary> 📝 `database/model/model.go` (+13 -1) ➕ `database/model/model_test.go` (+22 -0) 📝 `sub/subClashService.go` (+4 -7) 📝 `sub/subJsonService.go` (+1 -1) 📝 `sub/subService.go` (+15 -7) 📝 `web/service/inbound.go` (+4 -4) 📝 `xray/api.go` (+1 -1) </details> ### 📄 Description Closes #4081. The panel UI stores both Hysteria v1 and v2 as `protocol = "hysteria"` with `settings.version` telling them apart, so everywhere we compare protocol to `model.Hysteria` works for both variants on UI-created inbounds. For inbounds that came in from somewhere else (imports, manual inserts, migrations from other panels) the stored protocol string can be literally `"hysteria2"`. Every switch/filter we have misses that: - `getInboundsBySubId` SQL filters `protocol in (...)` without hysteria2 - `getLink` switch has only `case "hysteria"` - `genHysteriaLink` returns `""` on anything but `model.Hysteria` - `buildProxy` in clash dispatches on `model.Hysteria` only - `subJsonService` switch same - `inbound.go` validation and client-key lookups, `xray/api.go` AddUser same Result: no link in subscription, no entry in the clash yaml, no error logged. The reporter describes it exactly. ## Fix Add `Hysteria2` constant + `IsHysteria(p Protocol) bool` helper in `database/model/model.go`, use it (or a two-valued `case`) in the places listed above. No migration, no change to how the UI stores things. Existing `"hysteria"` inbounds hit the exact same code paths they did before. Second commit is unrelated to the issue but touches the same function: `int(ep["port"].(float64))` in the externalProxy fanout (from #4073) was a bare type assertion, which panics the subscription handler if any entry is missing port or has the wrong JSON type. Added an ok-check to skip malformed entries. ## Test plan - `go build ./...` + `go vet ./...` clean - `go test ./database/model/` — `TestIsHysteria` passes (6 cases including `hysteria`, `hysteria2`, empty, wrong-case, other protocols) - Manual: created a Hysteria2 inbound via the UI, subscription link still generated (no regression on the common path) --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
bsakaguchi 2026-10-31 20:48:04 +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#5596
No description provided.