Details
Option 3: Drop root privileges in the Dashboard container
Run the Dashboard process as a non-root user to reduce the impact of container-level arbitrary file writes.
---
Remediation
Add a path boundary check in writeFunctionSourceCodeToTempFile after constructing sourceFilePath:
// pkg/processor/build/builder.go — fix for writeFunctionSourceCodeToTempFile
sourceFilePath := path.Join(tempDir, moduleFileName)
// Verify resolved path is within tempDir
absPath, err := filepath.Abs(sourceFilePath)
if err != nil {
return "", errors.Wrap(err, "Failed to resolve absolute path")
}
absTempDir, err := filepath.Abs(tempDir)
if err != nil {
return "", errors.Wrap(err, "Failed to resolve absolute tempDir")
}
if !strings.HasPrefix(absPath, absTempDir+string(os.PathSeparator)) {
return "", errors.Errorf(
"handler module path escapes build directory: %s", moduleFileName)
}
b.logger.DebugWith("Writing function source code to temporary file", "functionPath", absPath)
if err := os.WriteFile(absPath, decodedFunctionSourceCode, os.FileMode(0644)); err != nil {
Alternatively, reject any handler module name containing path separator characters before the build pipeline is invoked (at API request validation time).
---
Resources
- Vulnerable file:
pkg/processor/build/builder.go— functionwriteFunctionSourceCodeToTempFile, line 654 - Parser:
pkg/functionconfig/handler.go— functionParseHandler, line 25 - Go
path.Joinbehavior: https://pkg.go.dev/path#Join - CWE-22: https://cwe.mitre.org/data/definitions/22.html
- OWASP Path Traversal: https://owasp.org/www-community/attacks/Path_Traversal