Skip to content

Commit 0289db9

Browse files
committed
fix: dependency_updater security and error wrapping
1 parent 7b53e38 commit 0289db9

1 file changed

Lines changed: 15 additions & 2 deletions

File tree

dependency_updater/dependency_updater.go

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -86,12 +86,25 @@ func updater(token string, repoPath string, commit bool, githubAction bool) erro
8686
// Sanitize repoPath to prevent path traversal (CWE-22)
8787
repoPath, err = filepath.Abs(filepath.Clean(repoPath))
8888
if err != nil {
89-
return fmt.Errorf("error resolving repo path: %s", err)
89+
return fmt.Errorf("error resolving repo path: %w", err)
90+
}
91+
92+
// Ensure the resolved path stays within the workspace (CWE-22)
93+
base := os.Getenv("GITHUB_WORKSPACE")
94+
if base != "" {
95+
absBase, err := filepath.Abs(base)
96+
if err != nil {
97+
return fmt.Errorf("error resolving workspace base path: %w", err)
98+
}
99+
rel, err := filepath.Rel(absBase, repoPath)
100+
if err != nil || strings.HasPrefix(rel, "..") {
101+
return fmt.Errorf("security error: repo path '%s' is outside of workspace '%s'", repoPath, absBase)
102+
}
90103
}
91104

92105
f, err := os.ReadFile(filepath.Join(repoPath, "versions.json"))
93106
if err != nil {
94-
return fmt.Errorf("error reading versions JSON: %s", err)
107+
return fmt.Errorf("error reading versions JSON: %w", err)
95108
}
96109

97110
client := github.NewClient(nil).WithAuthToken(token)

0 commit comments

Comments
 (0)