disable inline lua

This commit is contained in:
Meo597
2026-10-14 10:18:40 +08:00
parent 19842ed0c2
commit 4c0f3a94c5
2 changed files with 13 additions and 5 deletions
+3
View File
@@ -8,6 +8,7 @@ import (
"time"
"github.com/xtls/xray-core/common/base64"
"github.com/xtls/xray-core/common/errors"
"github.com/xtls/xray-core/common/platform"
glua "github.com/yuin/gopher-lua"
"github.com/yuin/gopher-lua/parse"
@@ -30,6 +31,8 @@ func Compile(script string) (*Program, error) {
name := "[inline]"
privileged := false
if strings.HasPrefix(script, base64.GzipPrefix) || strings.HasPrefix(script, base64.Prefix) {
// TODO: Restore inline script support and re-enable the related tests.
return nil, errors.New("currently unavailable")
code, err = base64.Decode(script)
} else if name, err = platform.ResolveLuaFile(script); err == nil {
if code, err = os.ReadFile(name); err == nil {
+10 -5
View File
@@ -2,7 +2,6 @@ package lua
import (
"bytes"
"compress/gzip"
"context"
"crypto/ed25519"
"crypto/sha256"
@@ -18,7 +17,6 @@ import (
"time"
"weak"
xbase64 "github.com/xtls/xray-core/common/base64"
glua "github.com/yuin/gopher-lua"
)
@@ -90,6 +88,8 @@ func TestNewStateClosesFailedValidation(t *testing.T) {
}
}
// TODO: Re-enable these tests and their helper when Compile supports inline scripts again.
/*
func compressSource(t *testing.T, code string) []byte {
t.Helper()
var data bytes.Buffer
@@ -189,6 +189,7 @@ func TestCompileInlineDiagnostics(t *testing.T) {
}
}
}
*/
func TestCompileRejectsReadFailure(t *testing.T) {
path := filepath.Join(t.TempDir(), "unreadable.lua")
@@ -209,7 +210,7 @@ func TestCompileRejectsReadFailure(t *testing.T) {
func compileTestProgram(t *testing.T, code string) *Program {
t.Helper()
program, err := Compile(xbase64.Prefix + base64.StdEncoding.EncodeToString([]byte(code)))
program, err := Compile(writeTestScript(t, code))
if err != nil {
t.Fatal(err)
}
@@ -464,6 +465,8 @@ func TestProgramSignedBodyTampering(t *testing.T) {
}
}
// TODO: Re-enable this test when Compile supports inline scripts again.
/*
func TestProgramInlineSignaturesCannotAuthorize(t *testing.T) {
for _, key := range []string{"", privilegedTestPublicKey} {
setTestPrivilegedPublicKey(t, key)
@@ -490,6 +493,7 @@ func TestProgramInlineSignaturesCannotAuthorize(t *testing.T) {
}
}
}
*/
func TestProgramSignedDiagnostics(t *testing.T) {
setTestPrivilegedPublicKey(t, privilegedTestPublicKey)
@@ -773,8 +777,9 @@ file:close()`
privileged bool
}{
{"file", path, true},
{"base64", xbase64.Prefix + base64.StdEncoding.EncodeToString([]byte(code)), false},
{"gzip", xbase64.GzipPrefix + base64.StdEncoding.EncodeToString(compressSource(t, code)), false},
// TODO: Re-enable these cases when Compile supports inline scripts again.
// {"base64", xbase64.Prefix + base64.StdEncoding.EncodeToString([]byte(code)), false},
// {"gzip", xbase64.GzipPrefix + base64.StdEncoding.EncodeToString(compressSource(t, code)), false},
} {
t.Run(tc.name, func(t *testing.T) {
program, err := Compile(tc.script)