mirror of
https://github.com/MHSanaei/3x-ui.git
synced 2026-04-16 20:45:50 +00:00
1. **Fixed XPadding Placement Dropdown**: - Added the missing `cookie` and `query` options to `xPaddingPlacement` (`stream_xhttp.html`). - *Why:* Previously, users wanting `cookie` obfuscation were forced to use the `header` placement string. This caused Xray-core to blindly intercept the entire monolithic HTTP Cookie header, failing internal padding-length validations and causing the inbound to silently drop the connection. 2. **Fixed Uplink Data Placement Validation**: - Replaced the unsupported `query` option with `cookie` in `uplinkDataPlacement`. - *Why:* Xray-core's `transport_internet.go` explicitly forbids `query` as an uplink placement option. Selecting it from the UI previously sent a payload that would cause Xray-core to instantly throw an `unsupported uplink data placement: query` panic. Adding `cookie` perfectly aligns the UI with Xray-core restrictions. ### Related Issues - Resolves #3992
73 lines
1.7 KiB
Go
73 lines
1.7 KiB
Go
package encoding
|
|
|
|
import (
|
|
"encoding/binary"
|
|
"io"
|
|
|
|
"github.com/xtls/xray-core/common"
|
|
"github.com/xtls/xray-core/common/buf"
|
|
"github.com/xtls/xray-core/common/errors"
|
|
"github.com/xtls/xray-core/common/protocol"
|
|
)
|
|
|
|
var (
|
|
ErrCommandTooLarge = errors.New("Command too large.")
|
|
ErrCommandTypeMismatch = errors.New("Command type mismatch.")
|
|
ErrInvalidAuth = errors.New("Invalid auth.")
|
|
ErrInsufficientLength = errors.New("Insufficient length.")
|
|
ErrUnknownCommand = errors.New("Unknown command.")
|
|
)
|
|
|
|
func MarshalCommand(command interface{}, writer io.Writer) error {
|
|
if command == nil {
|
|
return ErrUnknownCommand
|
|
}
|
|
|
|
var cmdID byte
|
|
var factory CommandFactory
|
|
switch command.(type) {
|
|
default:
|
|
return ErrUnknownCommand
|
|
}
|
|
|
|
buffer := buf.New()
|
|
defer buffer.Release()
|
|
|
|
err := factory.Marshal(command, buffer)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
|
|
auth := Authenticate(buffer.Bytes())
|
|
length := buffer.Len() + 4
|
|
if length > 255 {
|
|
return ErrCommandTooLarge
|
|
}
|
|
|
|
common.Must2(writer.Write([]byte{cmdID, byte(length), byte(auth >> 24), byte(auth >> 16), byte(auth >> 8), byte(auth)}))
|
|
common.Must2(writer.Write(buffer.Bytes()))
|
|
return nil
|
|
}
|
|
|
|
func UnmarshalCommand(cmdID byte, data []byte) (protocol.ResponseCommand, error) {
|
|
if len(data) <= 4 {
|
|
return nil, ErrInsufficientLength
|
|
}
|
|
expectedAuth := Authenticate(data[4:])
|
|
actualAuth := binary.BigEndian.Uint32(data[:4])
|
|
if expectedAuth != actualAuth {
|
|
return nil, ErrInvalidAuth
|
|
}
|
|
|
|
var factory CommandFactory
|
|
switch cmdID {
|
|
default:
|
|
return nil, ErrUnknownCommand
|
|
}
|
|
return factory.Unmarshal(data[4:])
|
|
}
|
|
|
|
type CommandFactory interface {
|
|
Marshal(command interface{}, writer io.Writer) error
|
|
Unmarshal(data []byte) (interface{}, error)
|
|
}
|