validateShellConfig checks that a shell config file is safe to source. It rejects symlinks (which could point to malicious files) and world-writable files (which could be tampered with).
(path string)
| 274 | // It rejects symlinks (which could point to malicious files) and |
| 275 | // world-writable files (which could be tampered with). |
| 276 | func (e *CommandExecutor) validateShellConfig(path string) error { |
| 277 | if path == "" { |
| 278 | return nil |
| 279 | } |
| 280 | |
| 281 | info, err := os.Lstat(path) |
| 282 | if err != nil { |
| 283 | return err |
| 284 | } |
| 285 | |
| 286 | if info.Mode()&os.ModeSymlink != 0 { |
| 287 | return fmt.Errorf("shell config %q is a symlink — refusing to source", path) |
| 288 | } |
| 289 | |
| 290 | if runtime.GOOS != "windows" && info.Mode().Perm()&0002 != 0 { |
| 291 | return fmt.Errorf("shell config %q is world-writable — refusing to source", path) |
| 292 | } |
| 293 | |
| 294 | return nil |
| 295 | } |
| 296 | |
| 297 | // CaptureOutput executa comando e captura apenas a saída (para uso interno) |
| 298 | func (e *CommandExecutor) CaptureOutput(ctx context.Context, shell string, args []string) ([]byte, error) { |
no test coverage detected