

0 / 2 embers
0 / 3000 xp
click for more info
Complete a lesson to start your streak
click for more info
Still calibrating
click for more info
Not enough gems
Cost: 6 gems
1: Injection
incomplete
2: Fixing SQL Injection
incomplete
3: Injection Beyond SQL
incomplete
4: Safe Validation and Sanitization
incomplete
5: When to Sanitize
incomplete
6: Unsafe Archive Extraction
incomplete
7: Safe Archive Extraction
incomplete
8: LLM Prompt Injection
incomplete
9: Limiting Tool Calls
incomplete
10: Narrow Tool Interfaces
incomplete
11: File Upload Security
incomplete
Back
ctrl+,
Next
ctrl+.
This lesson's interactive features are locked, please to keep using them
Archive extraction needs to validate each entry against a trusted root. In Go, filepath.Rel describes how to reach a candidate destination from that root:
relativePath, err := filepath.Rel(root, destination)
if err != nil ||
relativePath == "" ||
relativePath == ".." ||
strings.HasPrefix(relativePath, ".."+string(filepath.Separator)) ||
filepath.IsAbs(relativePath) {
return errors.New("archive entry escapes the extraction directory")
}
Rejecting the root, its parent, paths beneath its parent, and absolute relative results keeps accepted destinations inside the intended directory. Entry names also need platform-aware checks: an absolute name, a Windows-style backslash path, or a symbolic link should not be treated as an ordinary document path.
Validate every entry before extracting any of them. If the fifth entry is malicious but the first four have already been written, the rejected archive still leaves partial data behind.
Path safety is only one archive boundary. Compressed input can expand dramatically, so production systems should also limit the number of entries and their total uncompressed size. Otherwise, a zip bomb can exhaust memory or disk space and cause a denial of service.
Bearly Secure plans every ZIP entry before writing it, but it does not validate the planned paths. Reject the entire archive when any entry could escape or redirect extraction.
With Bearly Secure still running, run and submit the CLI tests from the project root.