Skip to content

High-performance browser automation bridge and multi-instance orchestrator with advanced stealth injection and real-time dashboard.

fix(security): guard state file paths with filepath.IsLocal before joining and stop echoing the request selector in the snapshot hint, clearing the CodeQL path-injection and reflected-xss alerts

Luigi Agosti1dce00dd2627
diff --git a/internal/handlers/snapshot.go b/internal/handlers/snapshot.go
index 9d268989..4754125f 100644
--- a/internal/handlers/snapshot.go
+++ b/internal/handlers/snapshot.go
@@ -218,9 +218,9 @@ func (h *Handlers) HandleSnapshot(w http.ResponseWriter, r *http.Request) {
}
}
if elemInfo != "" {
- scopedEmptyHint = fmt.Sprintf("Element exists in DOM (%s) but has no accessible nodes. Use `text --selector %s` or `eval` to extract content.", elemInfo, selector)
+ scopedEmptyHint = fmt.Sprintf("Element exists in DOM (%s) but has no accessible nodes. Use `text` with the same selector, or `eval`, to extract content.", elemInfo)
} else if descErr == nil {
- scopedEmptyHint = fmt.Sprintf("Element exists in DOM but has no accessible nodes. Use `text --selector %s` or `eval` to extract content.", selector)
+ scopedEmptyHint = "Element exists in DOM but has no accessible nodes. Use `text` with the same selector, or `eval`, to extract content."
}
}
diff --git a/internal/state/state.go b/internal/state/state.go
index 70f252a7..316b2197 100644
--- a/internal/state/state.go
+++ b/internal/state/state.go
@@ -177,7 +177,11 @@ var stateExtensions = []string{".json.enc", ".json"}
// statePathWithin joins a state file path and reports whether it stayed inside
// dir, so every caller applies the same containment rule.
func statePathWithin(dir, base, ext string) (string, bool) {
- path := filepath.Clean(filepath.Join(dir, base+ext))
+ name := base + ext
+ if !filepath.IsLocal(name) {
+ return "", false
+ }
+ path := filepath.Clean(filepath.Join(dir, name))
return path, strings.HasPrefix(path, filepath.Clean(dir)+string(os.PathSeparator))
}