feature/recipe_implementation #5

Merged
gmgauthier merged 54 commits from feature/recipe_implementation into master 2026-03-07 23:17:54 +00:00
Showing only changes of commit 7e4bdbc21c - Show all commits

View File

@ -12,18 +12,35 @@ import (
)
// Global safe read-only whitelist
var safeReadOnlyCommands = map[string]bool{
"ls": true,
"pwd": true,
"cat": true,
"tree": true,
var safeCommands = map[string]bool{
//GNU Utilities
"ls": true,
"pwd": true,
"cat": true,
"tree": true,
"find": true,
"grep": true,
"which": true,
//Git and Gitea
"git status": true,
"git log": true,
"find": true,
"grep": true,
"cndump -s": true,
"git diff": true,
"git branch": true,
"tea repos list -o csv -lm 100": true,
"tea repos search -o csv": true,
//Miscellaneous Utilities
"cndump -s": true,
// Safe test runners
"go test": true,
"make test": true,
"make lint": true,
"pytest": true,
"poetry run pytest": true,
"ctest": true,
"python -m pytest": true,
"go vet": true,
"go fmt": true,
"go mod tidy": true,
}
var (
@ -47,11 +64,21 @@ func Load(path string, userParams map[string]any) (*Recipe, error) {
return nil, fmt.Errorf("yaml parse: %w", err)
}
// === SAFETY CHECK: reject dangerous allowed_shell_commands ===
// === SAFETY CHECK: reject truly dangerous commands ===
for _, cmd := range r.AllowedShellCommands {
trimmed := strings.TrimSpace(strings.ToLower(cmd))
if !safeReadOnlyCommands[trimmed] && !strings.HasPrefix(trimmed, "git status") && !strings.HasPrefix(trimmed, "git log") {
return nil, fmt.Errorf("\u001B[31mRecipe contains unsafe shell command: %q. Remove or replace the dangerous command in your recipe.\u001B[0m", cmd)
// Allow exact matches or common prefixed commands
allowed := false
for safe := range safeCommands {
if strings.HasPrefix(trimmed, safe) {
allowed = true
break
}
}
if !allowed {
return nil, fmt.Errorf("\u001B[31mRecipe contains unsafe shell command: %q. "+
"Remove or replace the dangerous command in your recipe.\u001B[0m", cmd)
}
}