-
Notifications
You must be signed in to change notification settings - Fork 7
fix(security): prevent command injection vulnerability in package managers (Issue #23) #25
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
d424843
security: remove incorrectly committed .swo file
bluet 37ac642
chore: add vim swap files to .gitignore
bluet 86b9b97
feat(security): implement input validation to prevent command injecti…
bluet 3cbcb19
feat(security): apply input validation to all package managers (Issue…
bluet 6d40709
chore: fix trailing whitespace in CLAUDE.md
bluet d738c76
refactor: simplify test helper function in security_test.go
bluet b8f7aa6
refactor: remove unnecessary contains() wrapper function
bluet 2ea9805
docs: clean up CLAUDE.md and mark security tasks as completed
bluet 3c8e89a
chore: add TODO.md to .gitignore
bluet 7af34b5
docs: add @TODO.md reference to CLAUDE.md
bluet File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
Binary file not shown.
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
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
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
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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,83 @@ | ||
| // Package manager provides security utilities for package manager operations | ||
| package manager | ||
|
|
||
| import ( | ||
| "errors" | ||
| "regexp" | ||
| ) | ||
|
|
||
| // packageNameRegex defines the allowed pattern for package names | ||
| // This pattern allows: | ||
| // - Letters (a-z, A-Z) | ||
| // - Numbers (0-9) | ||
| // - Dash/hyphen (-) | ||
| // - Underscore (_) | ||
| // - Period/dot (.) | ||
| // - Plus sign (+) | ||
| // - Colon (:) for architecture specifiers (e.g., package:amd64) | ||
| // - Forward slash (/) for repository specifiers (e.g., repo/package) | ||
| // The pattern requires at least one valid character | ||
| var packageNameRegex = regexp.MustCompile(`^[a-zA-Z0-9\-_.+:/]+$`) | ||
|
|
||
| // ErrInvalidPackageName is returned when a package name contains invalid characters | ||
| var ErrInvalidPackageName = errors.New("invalid package name: contains potentially dangerous characters") | ||
|
|
||
| // ValidatePackageName validates that a package name only contains safe characters | ||
| // to prevent command injection attacks. | ||
| // | ||
| // Valid package names may contain: | ||
| // - Alphanumeric characters (a-z, A-Z, 0-9) | ||
| // - Dash/hyphen (-) | ||
| // - Underscore (_) | ||
| // - Period/dot (.) | ||
| // - Plus sign (+) | ||
| // - Colon (:) for architecture specifiers | ||
| // - Forward slash (/) for repository specifiers | ||
| // | ||
| // This function rejects any package names containing: | ||
| // - Shell metacharacters (;, |, &, $, `, \, ", ', <, >, (, ), {, }, [, ], *, ?, ~) | ||
| // - Whitespace characters | ||
| // - Control characters | ||
| // - Null bytes | ||
| // | ||
| // Example valid names: | ||
| // - "vim" | ||
| // - "libssl1.1" | ||
| // - "gcc-9-base" | ||
| // - "python3.8" | ||
| // - "package:amd64" | ||
| // - "repo/package" | ||
| // | ||
| // Example invalid names: | ||
| // - "package; rm -rf /" | ||
| // - "package && malicious-command" | ||
| // - "package`evil`" | ||
| // - "package$(bad)" | ||
| func ValidatePackageName(name string) error { | ||
| // Check for empty string | ||
| if name == "" { | ||
| return errors.New("package name cannot be empty") | ||
| } | ||
|
|
||
| // Check length limit (most package managers have reasonable limits) | ||
| if len(name) > 255 { | ||
| return errors.New("package name too long (max 255 characters)") | ||
| } | ||
|
|
||
| // Validate against regex pattern | ||
| if !packageNameRegex.MatchString(name) { | ||
| return ErrInvalidPackageName | ||
| } | ||
|
|
||
| return nil | ||
| } | ||
|
|
||
| // ValidatePackageNames validates multiple package names | ||
| func ValidatePackageNames(names []string) error { | ||
| for _, name := range names { | ||
| if err := ValidatePackageName(name); err != nil { | ||
| return err | ||
| } | ||
| } | ||
| return nil | ||
| } | ||
Oops, something went wrong.
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.
Uh oh!
There was an error while loading. Please reload this page.