summaryrefslogtreecommitdiff
path: root/tests/e2e/fuzz_args_test.go
diff options
context:
space:
mode:
authorJames O'Doherty <james@theodohertyfamily.com>2026-05-22 10:46:02 -0400
committerJames O'Doherty <james@theodohertyfamily.com>2026-05-22 10:46:02 -0400
commit9131b0004e7c640cc028179e1d049a4c62210d94 (patch)
tree7efb5612b61240105851cb5d8ac8f05263644db4 /tests/e2e/fuzz_args_test.go
parent401683a6b11e5a7810c949147a12f2c4bbfba48a (diff)
Security hardening: prevent shell injection and null-byte crashes, implement 8-bit clean argument fuzzing and portable E2E binary discovery
Diffstat (limited to 'tests/e2e/fuzz_args_test.go')
-rw-r--r--tests/e2e/fuzz_args_test.go52
1 files changed, 52 insertions, 0 deletions
diff --git a/tests/e2e/fuzz_args_test.go b/tests/e2e/fuzz_args_test.go
new file mode 100644
index 0000000..0d4a45b
--- /dev/null
+++ b/tests/e2e/fuzz_args_test.go
@@ -0,0 +1,52 @@
+package e2e
+
+import (
+ "fmt"
+ "os/exec"
+ "strings"
+ "testing"
+)
+
+func FuzzArgumentIntegrity(f *testing.F) {
+ binaryPath := GetBinaryPath()
+
+ f.Add("; rm -rf /")
+ f.Add("$(whoami)")
+ f.Add(" spaced ")
+ f.Add("\"'\"'\"")
+ f.Add("\x00null\x00")
+
+ f.Fuzz(func(t *testing.T, payload string) {
+ out, err := exec.Command(binaryPath, "test-args", payload).CombinedOutput()
+
+ if strings.Contains(payload, "\x00") {
+ if err != nil || strings.Contains(string(out), "contains null byte") {
+ return
+ }
+ }
+
+ if err != nil {
+ // If we hit a system limit (like disk quota in /tmp during heavy fuzzing),
+ // it's an environmental issue, not a bug in our binary.
+ if strings.Contains(string(out), "disk quota exceeded") ||
+ strings.Contains(string(out), "no space left on device") {
+ return
+ }
+ t.Fatalf("Binary crashed for payload %q: %v\nOutput: %s", payload, err, string(out))
+ }
+
+ lines := strings.Split(strings.TrimSpace(string(out)), "\n")
+ if len(lines) < 3 {
+ t.Fatalf("Unexpected output format for payload %q\nOutput: %s", payload, string(out))
+ }
+
+ parts := strings.Split(lines[len(lines)-1], ":")
+ if len(parts) < 2 {
+ t.Fatalf("Malformed hex line for payload %q: %s", payload, lines[len(lines)-1])
+ }
+
+ if parts[1] != fmt.Sprintf("%x", payload) {
+ t.Errorf("8-bit mismatch!\nSent Hex: %s\nRecv Hex: %s\nPayload: %q", fmt.Sprintf("%x", payload), parts[1], payload)
+ }
+ })
+}