Skip to content

fix: validate scaffolded name on the CLI-arg path, not just the prompt#31

Open
Jaro-c wants to merge 1 commit into
newcore-network:developfrom
Jaro-c:fix/validate-scaffold-name
Open

fix: validate scaffolded name on the CLI-arg path, not just the prompt#31
Jaro-c wants to merge 1 commit into
newcore-network:developfrom
Jaro-c:fix/validate-scaffold-name

Conversation

@Jaro-c

@Jaro-c Jaro-c commented Jul 18, 2026

Copy link
Copy Markdown

I traced getNameFromArgsOrPrompt and noticed it returned args[0] without calling any validator when the name comes in as a CLI argument — the (weak, empty/space-only) validator in validateCreateName only ran on the interactive huh prompt path. A name like ../../etc/foo would reach filepath.Join in create_resource.go, create_standalone.go, init.go, and templates/embed.go unchecked.

Replaced the space-only check with an allow-list regex (^[a-zA-Z0-9_-]+$) and applied it on both paths — the CLI-arg path now validates before returning the name, same as the prompt path already did.

Added tests for validateCreateName (valid/invalid names, including traversal attempts) and for getNameFromArgsOrPrompt rejecting a traversal name passed as an argument.

go build, go vet, gofmt -l, and go test ./... all pass.

Closes #24.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant