Why it matters
An entry named ../../x is written outside the destination.
How to fix it
Reject the entry unless filepath.IsLocal(name) is true, or check that the joined path still has the destination as its prefix.
Example
The rule's own test fixtures, verbatim: the test suite requires the rule to report the first and not the second.
package fixture
import (
"archive/zip"
"os"
"path/filepath"
)
func unpack(reader *zip.Reader, dest string) error {
for _, entry := range reader.File {
target := filepath.Join(dest, entry.Name)
if err := os.MkdirAll(filepath.Dir(target), 0o750); err != nil {
return err
}
}
return nil
}package fixture
import (
"archive/zip"
"errors"
"os"
"path/filepath"
)
func unpack(reader *zip.Reader, dest string) error {
for _, entry := range reader.File {
if !filepath.IsLocal(entry.Name) {
return errors.New("archive entry escapes the destination")
}
target := filepath.Join(dest, entry.Name)
if err := os.MkdirAll(filepath.Dir(target), 0o750); err != nil {
return err
}
}
return nil
}What TrustIvan reads
Runs on repository scans of Go source once static analysis is turned on (SAST_RULES and the separately built analyzer image); it is off by default.
Weakness classes and references
Related checks
- World writable file mode (Go)
GoSeverity: Medium
trustivan-go-world-writable-file-mode - JWT parse unverified (Go)
GoSeverity: High
trustivan-go-jwt-parse-unverified - HTTP server without timeouts (Go)
GoSeverity: Medium
trustivan-go-http-server-without-timeouts - Hardcoded password connection string (Go)
GoSeverity: High
trustivan-go-hardcoded-password-connection-string - SSH host key not verified (Go)
GoSeverity: High
trustivan-go-ssh-host-key-not-verified - Cookie without HttpOnly (Go)
GoSeverity: Medium
trustivan-go-cookie-without-httponly
Terms: SAST (static application security testing), Taint analysis, CWE (Common Weakness Enumeration), OWASP Top 10
All static analysis (SAST) checks · The whole catalogue · How this works in TrustIvan · Documentation