aboutsummaryrefslogtreecommitdiff
path: root/internal/admin/api_helpers.go
diff options
context:
space:
mode:
authorhistoria <[not public]>2026-09-16 02:14:02 -0400
committerhistoria <[not public]>2026-09-16 02:14:02 -0400
commitad60843fbf577eda80105e3916822d663aaefcb3 (patch)
tree68092a6403fdb2992ef92cfe0e2dd62b479935aa /internal/admin/api_helpers.go
parent61881fd0c1a7066293f552be1a747143f70d03ff (diff)
downloadthehouseoficarus-ad60843fbf577eda80105e3916822d663aaefcb3.tar.gz
fix: economy recovery double-refund/erased-liability/cap-drops, entity editor path traversal
Diffstat (limited to 'internal/admin/api_helpers.go')
-rw-r--r--internal/admin/api_helpers.go15
1 files changed, 15 insertions, 0 deletions
diff --git a/internal/admin/api_helpers.go b/internal/admin/api_helpers.go
index 3224598..11ad958 100644
--- a/internal/admin/api_helpers.go
+++ b/internal/admin/api_helpers.go
@@ -4,10 +4,25 @@ import (
"bytes"
"fmt"
"os"
+ "strings"
"gopkg.in/yaml.v3"
)
+// validEntityID reports whether an entity ID can be safely joined into a
+// file path under its data directory. IDs come from URL path segments and
+// JSON bodies, so an unchecked join could otherwise escape the data
+// directory ("../") or touch dot files.
+func validEntityID(id string) bool {
+ if id == "" || id == "." || id == ".." {
+ return false
+ }
+ if strings.ContainsAny(id, `/\`) || strings.ContainsRune(id, 0) {
+ return false
+ }
+ return true
+}
+
func yamlToMap(data []byte) (map[string]any, error) {
var v any
if err := yaml.Unmarshal(data, &v); err != nil {