tenseleyflow/shithub / d85e683

Browse files

storage: silence gosec G122 on RepairSharedPerms walk (operator-only path)

Authored by espadonne
SHA
d85e683278a13ddb22a82d758c9b50db519dcc6d
Parents
a63ddb4
Tree
ed8e9c0

1 changed file

StatusFile+-
M internal/infra/storage/reposfs.go 9 4
internal/infra/storage/reposfs.gomodified
@@ -260,9 +260,14 @@ func (r *RepoFS) RepairSharedPerms(ctx context.Context, path string) error {
260260
 		return fmt.Errorf("storage: repofs: git config sharedRepository: %w (output: %s)", err, strings.TrimSpace(string(out)))
261261
 	}
262262
 	// Walk the tree once: directories get +g+s, files get +g+w.
263
-	// We use filepath.Walk over an exec.Command(find ...) so the
264
-	// behavior is identical across Linux and macOS test harnesses.
265
-	if err := filepath.Walk(path, func(p string, info os.FileInfo, err error) error {
263
+	// path is verified contained-in-root above; no symlinks span out
264
+	// of the repo (bare repos don't ship with symlinks under .git/).
265
+	// G122: filepath.Walk + os.Chmod is race-prone in adversarial
266
+	// trees, but our writer (this process running as root or shithub)
267
+	// is also the only writer for these paths, and the trees are not
268
+	// user-influenced beyond the validated owner/name slugs. Operator-
269
+	// only command, not user-triggered.
270
+	if err := filepath.Walk(path, func(p string, info os.FileInfo, err error) error { //nolint:gosec
266271
 		if err != nil {
267272
 			return err
268273
 		}
@@ -274,7 +279,7 @@ func (r *RepoFS) RepairSharedPerms(ctx context.Context, path string) error {
274279
 		if newMode == mode {
275280
 			return nil
276281
 		}
277
-		return os.Chmod(p, newMode)
282
+		return os.Chmod(p, newMode) //nolint:gosec
278283
 	}); err != nil {
279284
 		return fmt.Errorf("storage: repofs: walk chmod: %w", err)
280285
 	}