Skip to content

Commit 24939dd

Browse files
committed
fix: implement security check for repo path to prevent directory traversal
1 parent 665eb1b commit 24939dd

1 file changed

Lines changed: 13 additions & 0 deletions

File tree

dependency_updater/dependency_updater.go

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,19 @@ func updater(token string, repoPath string, commit bool, githubAction bool) erro
8989
return fmt.Errorf("error resolving repo path: %s", err)
9090
}
9191

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+
}
103+
}
104+
92105
f, err := os.ReadFile(filepath.Join(repoPath, "versions.json"))
93106
if err != nil {
94107
return fmt.Errorf("error reading versions JSON: %s", err)

0 commit comments

Comments
 (0)