fix(plugin): accept relative root paths in safety checks
This commit is contained in:
1 parent
352aa2f4a0
commit
3b80efad89
3 files changed
+42
-11
No files matched your search
@@ -1116,7 +1116,11 @@ func validateDiskContributions(m Manifest, rootDir string) error {
|
||||
}
|
||||
|
||||
func safeJoin(root, rel string) (string, error) {
|
||||
cleanRoot := filepath.Clean(root)
|
||||
absRoot, err := filepath.Abs(root)
|
||||
if err != nil {
|
||||
return "", fmt.Errorf("resolve root path: %w", err)
|
||||
}
|
||||
cleanRoot := filepath.Clean(absRoot)
|
||||
joined := filepath.Clean(filepath.Join(cleanRoot, filepath.FromSlash(rel)))
|
||||
if !pathWithinRoot(cleanRoot, joined) {
|
||||
return "", fmt.Errorf("path traversal blocked: %q", rel)
|
||||
|
||||
@@ -0,0 +1,27 @@
|
||||
package plugin
|
||||
|
||||
import (
|
||||
"path/filepath"
|
||||
"testing"
|
||||
)
|
||||
|
||||
func TestSafeJoinRelativeRoot(t *testing.T) {
|
||||
want, err := filepath.Abs("path_test.go")
|
||||
if err != nil {
|
||||
t.Fatalf("resolve expected path: %v", err)
|
||||
}
|
||||
|
||||
got, err := safeJoin(".", "path_test.go")
|
||||
if err != nil {
|
||||
t.Fatalf("safeJoin rejected a path inside a relative root: %v", err)
|
||||
}
|
||||
if filepath.Clean(got) != filepath.Clean(want) {
|
||||
t.Fatalf("safeJoin path = %q, want %q", got, want)
|
||||
}
|
||||
}
|
||||
|
||||
func TestSafeJoinRelativeRootRejectsTraversal(t *testing.T) {
|
||||
if _, err := safeJoin(".", filepath.Join("..", "go.mod")); err == nil {
|
||||
t.Fatal("safeJoin accepted a path outside a relative root")
|
||||
}
|
||||
}
|
||||
+10
-10
@@ -123,16 +123,16 @@ var (
|
||||
reSVGJavascriptURI = regexp.MustCompile(`(?i)javascript\s*:`)
|
||||
reSVGForeignObject = regexp.MustCompile(`(?i)<\s*foreignobject\b`)
|
||||
|
||||
reJSWailsGo = regexp.MustCompile(`(?i)\b(?:window|globalThis|self|parent|top)\s*(?:\.\s*go\b|\[\s*['"]go['"]\s*\])`)
|
||||
reJSWailsRuntime = regexp.MustCompile(`(?i)\b(?:window|globalThis|self|parent|top)\s*(?:\.\s*runtime\b|\[\s*['"]runtime['"]\s*\])`)
|
||||
reJSEval = regexp.MustCompile(`\beval\s*\(`)
|
||||
reJSNewFunction = regexp.MustCompile(`\bnew\s+Function\s*\(`)
|
||||
reJSFunctionCall = regexp.MustCompile(`(?:^|[^.\w$])Function\s*\(`)
|
||||
reJSDocCookie = regexp.MustCompile(`\bdocument\s*\.\s*cookie\b`)
|
||||
reJSDocWrite = regexp.MustCompile(`\bdocument\s*\.\s*write(?:ln)?\s*\(`)
|
||||
reJSScriptTag = regexp.MustCompile(`(?i)<\s*script\b`)
|
||||
reJSCreateScript = regexp.MustCompile(`(?i)\bcreateElement\s*\(\s*['"]script['"]\s*\)`)
|
||||
reJSNetworkCall = regexp.MustCompile(`\b(?:fetch\s*\(|XMLHttpRequest\b|WebSocket\b|EventSource\b|navigator\s*\.\s*sendBeacon\s*\()`)
|
||||
reJSWailsGo = regexp.MustCompile(`(?i)\b(?:window|globalThis|self|parent|top)\s*(?:\.\s*go\b|\[\s*['"]go['"]\s*\])`)
|
||||
reJSWailsRuntime = regexp.MustCompile(`(?i)\b(?:window|globalThis|self|parent|top)\s*(?:\.\s*runtime\b|\[\s*['"]runtime['"]\s*\])`)
|
||||
reJSEval = regexp.MustCompile(`\beval\s*\(`)
|
||||
reJSNewFunction = regexp.MustCompile(`\bnew\s+Function\s*\(`)
|
||||
reJSFunctionCall = regexp.MustCompile(`(?:^|[^.\w$])Function\s*\(`)
|
||||
reJSDocCookie = regexp.MustCompile(`\bdocument\s*\.\s*cookie\b`)
|
||||
reJSDocWrite = regexp.MustCompile(`\bdocument\s*\.\s*write(?:ln)?\s*\(`)
|
||||
reJSScriptTag = regexp.MustCompile(`(?i)<\s*script\b`)
|
||||
reJSCreateScript = regexp.MustCompile(`(?i)\bcreateElement\s*\(\s*['"]script['"]\s*\)`)
|
||||
reJSNetworkCall = regexp.MustCompile(`\b(?:fetch\s*\(|XMLHttpRequest\b|WebSocket\b|EventSource\b|navigator\s*\.\s*sendBeacon\s*\()`)
|
||||
)
|
||||
|
||||
// ScanArchive extracts archivePath into a temporary directory under tmpParentDir
|
||||
|
||||
Reference in new issue
Block a user