ax(node): replace banned strings import with bytes.HasPrefix in bundle.go
The strings package is banned per AX conventions. Both HasPrefix calls in extractTarball now use bytes.HasPrefix with the bytes package already imported. Co-Authored-By: Charon <charon@lethean.io>
This commit is contained in:
parent
0ffae0c646
commit
98d34ffd07
1 changed files with 4 additions and 4 deletions
|
|
@ -10,8 +10,6 @@ import (
|
|||
"io"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"strings"
|
||||
|
||||
"forge.lthn.ai/Snider/Borg/pkg/datanode"
|
||||
"forge.lthn.ai/Snider/Borg/pkg/tim"
|
||||
)
|
||||
|
|
@ -291,7 +289,8 @@ func extractTarball(tarData []byte, destDir string) (string, error) {
|
|||
}
|
||||
|
||||
// Reject paths that escape the destination directory
|
||||
if strings.HasPrefix(cleanName, ".."+string(os.PathSeparator)) || cleanName == ".." {
|
||||
parentPrefix := ".." + string(os.PathSeparator)
|
||||
if bytes.HasPrefix([]byte(cleanName), []byte(parentPrefix)) || cleanName == ".." {
|
||||
return "", fmt.Errorf("invalid tar entry: path traversal attempt: %s", header.Name)
|
||||
}
|
||||
|
||||
|
|
@ -300,7 +299,8 @@ func extractTarball(tarData []byte, destDir string) (string, error) {
|
|||
fullPath = filepath.Clean(fullPath)
|
||||
|
||||
// Final security check: ensure the path is still within destDir
|
||||
if !strings.HasPrefix(fullPath, absDestDir+string(os.PathSeparator)) && fullPath != absDestDir {
|
||||
destDirPrefix := absDestDir + string(os.PathSeparator)
|
||||
if !bytes.HasPrefix([]byte(fullPath), []byte(destDirPrefix)) && fullPath != absDestDir {
|
||||
return "", fmt.Errorf("invalid tar entry: path escape attempt: %s", header.Name)
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue