mirror of
https://github.com/v2fly/v2ray-core.git
synced 2025-02-20 23:47:21 -05:00
show warning for asset directory transversal to prepare for network api based reload in v5
This commit is contained in:
parent
736379d22d
commit
a720d1e2d6
9
common/platform/errors.generated.go
Normal file
9
common/platform/errors.generated.go
Normal file
@ -0,0 +1,9 @@
|
|||||||
|
package platform
|
||||||
|
|
||||||
|
import "github.com/v2fly/v2ray-core/v4/common/errors"
|
||||||
|
|
||||||
|
type errPathObjHolder struct{}
|
||||||
|
|
||||||
|
func newError(values ...interface{}) *errors.Error {
|
||||||
|
return errors.New(values...).WithPathObj(errPathObjHolder{})
|
||||||
|
}
|
@ -7,6 +7,7 @@ import (
|
|||||||
"io/fs"
|
"io/fs"
|
||||||
"os"
|
"os"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
|
"strings"
|
||||||
)
|
)
|
||||||
|
|
||||||
func ExpandEnv(s string) string {
|
func ExpandEnv(s string) string {
|
||||||
@ -25,6 +26,10 @@ func GetToolLocation(file string) string {
|
|||||||
|
|
||||||
// GetAssetLocation search for `file` in certain locations
|
// GetAssetLocation search for `file` in certain locations
|
||||||
func GetAssetLocation(file string) string {
|
func GetAssetLocation(file string) string {
|
||||||
|
filepathCleaned := filepath.Clean(file)
|
||||||
|
if strings.HasPrefix("..", filepathCleaned) {
|
||||||
|
newError("directory transversal is not allowed for assets. This will be forbidden in v5.").AtWarning().WriteToLog()
|
||||||
|
}
|
||||||
const name = "v2ray.location.asset"
|
const name = "v2ray.location.asset"
|
||||||
assetPath := NewEnvFlag(name).GetValue(getExecutableDir)
|
assetPath := NewEnvFlag(name).GetValue(getExecutableDir)
|
||||||
defPath := filepath.Join(assetPath, file)
|
defPath := filepath.Join(assetPath, file)
|
||||||
|
@ -7,6 +7,8 @@ import (
|
|||||||
"strings"
|
"strings"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
//go:generate go run github.com/v2fly/v2ray-core/v4/common/errors/errorgen
|
||||||
|
|
||||||
type EnvFlag struct {
|
type EnvFlag struct {
|
||||||
Name string
|
Name string
|
||||||
AltName string
|
AltName string
|
||||||
|
@ -19,8 +19,12 @@ func GetToolLocation(file string) string {
|
|||||||
return filepath.Join(toolPath, file+".exe")
|
return filepath.Join(toolPath, file+".exe")
|
||||||
}
|
}
|
||||||
|
|
||||||
// GetAssetLocation search for `file` in the excutable dir
|
// GetAssetLocation search for `file` in the executable dir
|
||||||
func GetAssetLocation(file string) string {
|
func GetAssetLocation(file string) string {
|
||||||
|
filepathCleaned := filepath.Clean(file)
|
||||||
|
if strings.HasPrefix("..", filepathCleaned) {
|
||||||
|
newError("directory transversal is not allowed for assets. This will be forbidden in v5.").AtWarning().WriteToLog()
|
||||||
|
}
|
||||||
const name = "v2ray.location.asset"
|
const name = "v2ray.location.asset"
|
||||||
assetPath := NewEnvFlag(name).GetValue(getExecutableDir)
|
assetPath := NewEnvFlag(name).GetValue(getExecutableDir)
|
||||||
return filepath.Join(assetPath, file)
|
return filepath.Join(assetPath, file)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user