MCPcopy Create free account
hub / github.com/diillson/chatcli / validateShellConfig

Method validateShellConfig

cli/agent/command_executor.go:276–295  ·  view source on GitHub ↗

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)

Source from the content-addressed store, hash-verified

274// It rejects symlinks (which could point to malicious files) and
275// world-writable files (which could be tampered with).
276func (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)
298func (e *CommandExecutor) CaptureOutput(ctx context.Context, shell string, args []string) ([]byte, error) {

Callers 1

executeInteractiveMethod · 0.95

Implementers 2

MockCommandExecutorutils/git_utils_test.go
OSCommandExecutorutils/exec_utils.go

Calls 2

ErrorfMethod · 0.80
ModeMethod · 0.65

Tested by

no test coverage detected