mirror of
https://github.com/XTLS/Xray-core.git
synced 2026-09-23 01:27:04 +00:00
Config: Fix some issues (#6640)
https://github.com/XTLS/Xray-core/pull/6640#issuecomment-5420106315 Fixes https://github.com/XTLS/Xray-core/issues/6636 Fixes https://github.com/XTLS/Xray-core/issues/6600 ...
This commit is contained in:
@@ -207,6 +207,7 @@ func getConfig() string {
|
|||||||
"tag": "XHTTP_IN",
|
"tag": "XHTTP_IN",
|
||||||
"streamSettings": {
|
"streamSettings": {
|
||||||
"network": "xhttp",
|
"network": "xhttp",
|
||||||
|
"security": "tls",
|
||||||
"xhttpSettings": {
|
"xhttpSettings": {
|
||||||
"host": "bing.com",
|
"host": "bing.com",
|
||||||
"path": "/xhttp_client_upload",
|
"path": "/xhttp_client_upload",
|
||||||
|
|||||||
@@ -65,6 +65,9 @@ func (v *Address) UnmarshalJSON(data []byte) error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (v *Address) Build() *net.IPOrDomain {
|
func (v *Address) Build() *net.IPOrDomain {
|
||||||
|
if v == nil {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
return net.NewIPOrDomain(v.Address)
|
return net.NewIPOrDomain(v.Address)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
+6
-6
@@ -140,7 +140,7 @@ func (c *InboundDetourConfig) Build() (*core.InboundHandlerConfig, error) {
|
|||||||
// TUN inbound doesn't need port configuration as it uses network interface instead
|
// TUN inbound doesn't need port configuration as it uses network interface instead
|
||||||
if strings.ToLower(c.Protocol) == "tun" {
|
if strings.ToLower(c.Protocol) == "tun" {
|
||||||
// Skip port validation for TUN
|
// Skip port validation for TUN
|
||||||
} else if c.ListenOn == nil {
|
} else if c.ListenOn == nil || len(c.ListenOn.String()) == 0 {
|
||||||
// Listen on anyip, must set PortList
|
// Listen on anyip, must set PortList
|
||||||
if c.PortList == nil {
|
if c.PortList == nil {
|
||||||
return nil, errors.New("Listen on AnyIP but no Port(s) set in InboundDetour.")
|
return nil, errors.New("Listen on AnyIP but no Port(s) set in InboundDetour.")
|
||||||
@@ -251,13 +251,13 @@ func validateOutboundTransportSecurity(rawConfig interface{}, senderSettings *pr
|
|||||||
if vlessCfg.Encryption != "" && vlessCfg.Encryption != "none" {
|
if vlessCfg.Encryption != "" && vlessCfg.Encryption != "none" {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
if requiresTransportSecurity(vlessCfg.Address) {
|
if requiresTransportSecurity(vlessCfg.Vnext[0].Address) {
|
||||||
return errors.New("vless without TLS or other encryption is prohibited unless the server address is a private IP or domain")
|
return errors.New("vless without TLS or other encryption is prohibited unless the server address is a private IP or domain")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if tjCfg, ok := rawConfig.(*TrojanClientConfig); ok {
|
if tjCfg, ok := rawConfig.(*TrojanClientConfig); ok {
|
||||||
if requiresTransportSecurity(tjCfg.Address) {
|
if requiresTransportSecurity(tjCfg.Servers[0].Address) {
|
||||||
return errors.New("trojan without TLS is prohibited unless the server address is a private IP or domain")
|
return errors.New("trojan without TLS is prohibited unless the server address is a private IP or domain")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -358,13 +358,13 @@ func (c *OutboundDetourConfig) Build() (*core.OutboundHandlerConfig, error) {
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, errors.New("failed to load outbound detour config for protocol ", c.Protocol).Base(err)
|
return nil, errors.New("failed to load outbound detour config for protocol ", c.Protocol).Base(err)
|
||||||
}
|
}
|
||||||
if err := validateOutboundTransportSecurity(rawConfig, senderSettings); err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
ts, err := rawConfig.(Buildable).Build()
|
ts, err := rawConfig.(Buildable).Build()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, errors.New("failed to build outbound handler for protocol ", c.Protocol).Base(err)
|
return nil, errors.New("failed to build outbound handler for protocol ", c.Protocol).Base(err)
|
||||||
}
|
}
|
||||||
|
if err := validateOutboundTransportSecurity(rawConfig, senderSettings); err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
return &core.OutboundHandlerConfig{
|
return &core.OutboundHandlerConfig{
|
||||||
SenderSettings: serial.ToTypedMessage(senderSettings),
|
SenderSettings: serial.ToTypedMessage(senderSettings),
|
||||||
|
|||||||
@@ -173,15 +173,18 @@ func fillRequestHeader(ctx context.Context, header []*Header) ([]*Header, error)
|
|||||||
outbounds := session.OutboundsFromContext(ctx)
|
outbounds := session.OutboundsFromContext(ctx)
|
||||||
ob := outbounds[len(outbounds)-1]
|
ob := outbounds[len(outbounds)-1]
|
||||||
|
|
||||||
if inbound == nil || ob == nil {
|
var src net.Destination
|
||||||
return nil, errors.New("missing inbound or outbound metadata from context")
|
if inbound != nil {
|
||||||
|
src = inbound.Source
|
||||||
|
} else {
|
||||||
|
src = net.TCPDestination(net.AnyIP, 0)
|
||||||
}
|
}
|
||||||
|
|
||||||
data := struct {
|
data := struct {
|
||||||
Source net.Destination
|
Source net.Destination
|
||||||
Target net.Destination
|
Target net.Destination
|
||||||
}{
|
}{
|
||||||
Source: inbound.Source,
|
Source: src,
|
||||||
Target: ob.Target,
|
Target: ob.Target,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -42,9 +42,6 @@ func ListenTCP(ctx context.Context, address net.Address, port net.Port, streamSe
|
|||||||
var listener net.Listener
|
var listener net.Listener
|
||||||
var err error
|
var err error
|
||||||
if port == net.Port(0) { // unix
|
if port == net.Port(0) { // unix
|
||||||
if !address.Family().IsDomain() {
|
|
||||||
return nil, errors.New("invalid unix listen: ", address).AtError()
|
|
||||||
}
|
|
||||||
listener, err = internet.ListenSystem(ctx, &net.UnixAddr{
|
listener, err = internet.ListenSystem(ctx, &net.UnixAddr{
|
||||||
Name: address.Domain(),
|
Name: address.Domain(),
|
||||||
Net: "unix",
|
Net: "unix",
|
||||||
|
|||||||
@@ -65,6 +65,9 @@ func ListenTCP(ctx context.Context, address net.Address, port net.Port, settings
|
|||||||
if address.Family().IsDomain() {
|
if address.Family().IsDomain() {
|
||||||
return nil, errors.New("domain address is not allowed for listening: ", address.Domain())
|
return nil, errors.New("domain address is not allowed for listening: ", address.Domain())
|
||||||
}
|
}
|
||||||
|
if port == 0 {
|
||||||
|
return nil, errors.New("port 0 is not allowed for listening on TCP")
|
||||||
|
}
|
||||||
|
|
||||||
protocol := settings.ProtocolName
|
protocol := settings.ProtocolName
|
||||||
listenFunc := transportListenerCache[protocol]
|
listenFunc := transportListenerCache[protocol]
|
||||||
|
|||||||
Reference in New Issue
Block a user