mirror of
https://github.com/XTLS/Xray-core.git
synced 2026-05-14 10:00:34 +00:00
fix: restrict xhttp browser dialer mode and remove added tests
Agent-Logs-Url: https://github.com/XTLS/Xray-core/sessions/071df77b-69fb-4b1f-a14d-9dab447e1efa Co-authored-by: RPRX <63339210+RPRX@users.noreply.github.com>
This commit is contained in:
committed by
GitHub
parent
a54c54a559
commit
5906445c68
@@ -1980,6 +1980,22 @@ func (c *StreamConfig) Build() (*internet.StreamConfig, error) {
|
|||||||
if strings.EqualFold(c.Security, "reality") {
|
if strings.EqualFold(c.Security, "reality") {
|
||||||
return nil, errors.New("sockopt.browserDialer does not support REALITY")
|
return nil, errors.New("sockopt.browserDialer does not support REALITY")
|
||||||
}
|
}
|
||||||
|
if config.ProtocolName == "splithttp" {
|
||||||
|
splitHTTPSettings := c.SplitHTTPSettings
|
||||||
|
if c.XHTTPSettings != nil {
|
||||||
|
splitHTTPSettings = c.XHTTPSettings
|
||||||
|
}
|
||||||
|
if splitHTTPSettings != nil {
|
||||||
|
splitHTTPSettingsCopy := *splitHTTPSettings
|
||||||
|
hs, err := splitHTTPSettingsCopy.Build()
|
||||||
|
if err != nil {
|
||||||
|
return nil, errors.New("Failed to build XHTTP config.").Base(err)
|
||||||
|
}
|
||||||
|
if splitHTTPConfig, ok := hs.(*splithttp.Config); ok && splitHTTPConfig.Mode != "auto" && splitHTTPConfig.Mode != "packet-up" {
|
||||||
|
return nil, errors.New("sockopt.browserDialer only supports XHTTP mode auto or packet-up")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
switch strings.ToLower(c.Security) {
|
switch strings.ToLower(c.Security) {
|
||||||
|
|||||||
@@ -1,10 +1,6 @@
|
|||||||
package browser_dialer
|
package browser_dialer
|
||||||
|
|
||||||
import (
|
import "testing"
|
||||||
"net/http"
|
|
||||||
"strings"
|
|
||||||
"testing"
|
|
||||||
)
|
|
||||||
|
|
||||||
func TestParseBrowserDialerAddressRequireUUIDPath(t *testing.T) {
|
func TestParseBrowserDialerAddressRequireUUIDPath(t *testing.T) {
|
||||||
valid := "127.0.0.1:8080/123e4567-e89b-12d3-a456-426614174000"
|
valid := "127.0.0.1:8080/123e4567-e89b-12d3-a456-426614174000"
|
||||||
@@ -24,61 +20,3 @@ func TestParseBrowserDialerAddressRequireUUIDPath(t *testing.T) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestGetDialerByAddressReusesExistingServerForSameListenAddress(t *testing.T) {
|
|
||||||
listenAddr := "127.0.0.1:39000"
|
|
||||||
server := &dialerServer{
|
|
||||||
server: &http.Server{Addr: listenAddr},
|
|
||||||
pageRoutes: make(map[string]*dialerInstance),
|
|
||||||
}
|
|
||||||
|
|
||||||
mu.Lock()
|
|
||||||
oldDialers, oldServers := sockoptDialers, dialerServers
|
|
||||||
sockoptDialers = make(map[string]*dialerInstance)
|
|
||||||
dialerServers = map[string]*dialerServer{listenAddr: server}
|
|
||||||
mu.Unlock()
|
|
||||||
t.Cleanup(func() {
|
|
||||||
mu.Lock()
|
|
||||||
sockoptDialers = oldDialers
|
|
||||||
dialerServers = oldServers
|
|
||||||
mu.Unlock()
|
|
||||||
})
|
|
||||||
|
|
||||||
if _, err := getDialerByAddress(listenAddr + "/123e4567-e89b-12d3-a456-426614174000"); err != nil {
|
|
||||||
t.Fatalf("failed to create first dialer: %v", err)
|
|
||||||
}
|
|
||||||
if _, err := getDialerByAddress(listenAddr + "/123e4567-e89b-12d3-a456-426614174001"); err != nil {
|
|
||||||
t.Fatalf("failed to create second dialer on same listener: %v", err)
|
|
||||||
}
|
|
||||||
if len(dialerServers) != 1 {
|
|
||||||
t.Fatalf("expected one shared listener, got %d", len(dialerServers))
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func TestGetDialerByAddressRejectsSamePortDifferentAddress(t *testing.T) {
|
|
||||||
listenAddr := "127.0.0.1:39001"
|
|
||||||
server := &dialerServer{
|
|
||||||
server: &http.Server{Addr: listenAddr},
|
|
||||||
pageRoutes: make(map[string]*dialerInstance),
|
|
||||||
}
|
|
||||||
|
|
||||||
mu.Lock()
|
|
||||||
oldDialers, oldServers := sockoptDialers, dialerServers
|
|
||||||
sockoptDialers = make(map[string]*dialerInstance)
|
|
||||||
dialerServers = map[string]*dialerServer{listenAddr: server}
|
|
||||||
mu.Unlock()
|
|
||||||
t.Cleanup(func() {
|
|
||||||
mu.Lock()
|
|
||||||
sockoptDialers = oldDialers
|
|
||||||
dialerServers = oldServers
|
|
||||||
mu.Unlock()
|
|
||||||
})
|
|
||||||
|
|
||||||
_, err := getDialerByAddress("127.0.0.2:39001/123e4567-e89b-12d3-a456-426614174011")
|
|
||||||
if err == nil {
|
|
||||||
t.Fatal("expected error for same port with different listen address")
|
|
||||||
}
|
|
||||||
if !strings.Contains(err.Error(), "cannot use the same port with a different listen address") {
|
|
||||||
t.Fatalf("unexpected error: %v", err)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|||||||
Reference in New Issue
Block a user