MCPcopy Index your code
hub / github.com/cheat/cheat / FuzzValidate

Function FuzzValidate

internal/sheet/validate_fuzz_test.go:11–130  ·  view source on GitHub ↗

FuzzValidate tests the Validate function with fuzzing to ensure it properly prevents path traversal and other security issues

(f *testing.F)

Source from the content-addressed store, hash-verified

9// FuzzValidate tests the Validate function with fuzzing
10// to ensure it properly prevents path traversal and other security issues
11func FuzzValidate(f *testing.F) {
12 // Add seed corpus with various valid and malicious inputs
13 // Valid names
14 f.Add("docker")
15 f.Add("docker/compose")
16 f.Add("lang/go/slice")
17 f.Add("my-cheat_sheet")
18 f.Add("file.txt")
19 f.Add("a")
20 f.Add("123")
21
22 // Path traversal attempts
23 f.Add("..")
24 f.Add("../etc/passwd")
25 f.Add("foo/../bar")
26 f.Add("foo/../../etc/passwd")
27 f.Add("..\\windows\\system32")
28 f.Add("foo\\..\\..\\windows")
29
30 // Encoded traversal attempts
31 f.Add("%2e%2e")
32 f.Add("%2e%2e%2f")
33 f.Add("..%2f")
34 f.Add("%2e.")
35 f.Add(".%2e")
36 f.Add("\x2e\x2e")
37 f.Add("\\x2e\\x2e")
38
39 // Unicode and special characters
40 f.Add("€test")
41 f.Add("test€")
42 f.Add("中文")
43 f.Add("🎉emoji")
44 f.Add("\x00null")
45 f.Add("test\x00null")
46 f.Add("\nnewline")
47 f.Add("test\ttab")
48
49 // Absolute paths
50 f.Add("/etc/passwd")
51 f.Add("C:\\Windows\\System32")
52 f.Add("\\\\server\\share")
53 f.Add("//server/share")
54
55 // Home directory
56 f.Add("~")
57 f.Add("~/config")
58 f.Add("~user/file")
59
60 // Hidden files
61 f.Add(".hidden")
62 f.Add("dir/.hidden")
63 f.Add(".git/config")
64
65 // Edge cases
66 f.Add("")
67 f.Add(" ")
68 f.Add(" ")

Callers

nothing calls this directly

Calls 1

ValidateFunction · 0.85

Tested by

no test coverage detected