Sanitize contract name when calling stellar contract init --name.#2449
Merged
Sanitize contract name when calling stellar contract init --name.#2449
stellar contract init --name.#2449Conversation
Contributor
There was a problem hiding this comment.
Pull request overview
This PR tightens input validation for stellar contract init --name by reusing the existing “safe name” validation logic, preventing path traversal and other invalid contract names from being used as filesystem path components.
Changes:
- Introduces a
ContractNamenewtype that validates names via the existingvalidate_namerules. - Updates
contract initto accept--nameasContractName(instead ofString) and uses it when creating the contract directory and templatingCargo.toml. - Adds an integration test asserting
contract init --name ../evilfails with an “Invalid name” error.
Reviewed changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated 1 comment.
| File | Description |
|---|---|
| cmd/soroban-cli/src/config/address.rs | Adds ContractName and unit tests to validate allowed/rejected inputs. |
| cmd/soroban-cli/src/commands/contract/init.rs | Switches --name parsing to ContractName and uses it safely for directory creation and templating. |
| cmd/crates/soroban-test/tests/it/config.rs | Adds an integration test ensuring contract init rejects path traversal in --name. |
leighmcculloch
approved these changes
Mar 12, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What
Sanitize contract name when calling
stellar contract init --name.Why
https://hackerone.com/reports/3587907
Known limitations
N/A