Skip to content

Commit d20cef5

Browse files
committed
fix(lint): deterministic staging dir via os.Mkdir 0755 instead of MkdirTemp+Chmod
Installs are mutex-serialized and leftovers are swept pre-install, so a random suffix bought nothing; CI's gosec also rejected the Chmod (G302) that MkdirTemp's 0700 forced.
1 parent 2521cd1 commit d20cef5

1 file changed

Lines changed: 5 additions & 7 deletions

File tree

environment/environment.go

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1112,15 +1112,13 @@ func (e *Environment) SyncSkill(ctx context.Context, args *protocol.SyncSkillArg
11121112
_ = os.RemoveAll(d)
11131113
}
11141114
}
1115-
tmpDir, err := os.MkdirTemp(parentDir, ".installing-"+args.SkillName+"-")
1116-
if err != nil {
1117-
return nil, fmt.Errorf("failed to create staging directory: %w", err)
1115+
// Deterministic staging name is safe: installs are serialized by
1116+
// skillInstallMu and the sweep above just cleared any leftover.
1117+
tmpDir := filepath.Join(parentDir, ".installing-"+args.SkillName)
1118+
if mkErr := os.Mkdir(tmpDir, 0o755); mkErr != nil {
1119+
return nil, fmt.Errorf("failed to create staging directory: %w", mkErr)
11181120
}
11191121
defer func() { _ = os.RemoveAll(tmpDir) }() // no-op after a successful rename
1120-
// MkdirTemp creates 0700; restore the 0755 the install dir always had.
1121-
if chmodErr := os.Chmod(tmpDir, 0o755); chmodErr != nil { // #nosec G302 -- skill dirs are world-traversable by design (G301 excluded for the same reason)
1122-
return nil, fmt.Errorf("failed to chmod staging directory: %w", chmodErr)
1123-
}
11241122
if err := e.unzipSkill(zipData, tmpDir); err != nil {
11251123
return nil, fmt.Errorf("failed to unzip skill: %w", err)
11261124
}

0 commit comments

Comments
 (0)