-
-
Notifications
You must be signed in to change notification settings - Fork 154
fix(security): 2 improvements across 2 files #662
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
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -18,6 +18,7 @@ package shell | |
|
|
||
| import ( | ||
| "fmt" | ||
| "strings" | ||
|
|
||
| "github.com/version-fox/vfox/internal/env" | ||
| ) | ||
|
|
@@ -48,5 +49,16 @@ func (b clink) Export(envs env.Vars) (out string) { | |
| } | ||
|
|
||
| func (b clink) set(key, value string) string { | ||
| return fmt.Sprintf("set \"%s=%s\"\n", key, value) | ||
| return fmt.Sprintf("set \"%s=%s\"\n", escapeCmdSet(key), escapeCmdSet(value)) | ||
| } | ||
|
|
||
| func escapeCmdSet(value string) string { | ||
| value = strings.ReplaceAll(value, "\r", " ") | ||
| value = strings.ReplaceAll(value, "\n", " ") | ||
| return strings.NewReplacer( | ||
| "^", "^^", | ||
| "\"", "^\"", | ||
| "%", "%%", | ||
| "!", "^!", | ||
| ).Replace(value) | ||
|
Comment on lines
+55
to
+63
|
||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -17,8 +17,6 @@ | |
| package shell | ||
|
|
||
| import ( | ||
| "fmt" | ||
|
|
||
| "github.com/version-fox/vfox/internal/env" | ||
| ) | ||
|
|
||
|
|
@@ -76,10 +74,6 @@ func (z zsh) Export(envs env.Vars) (out string) { | |
| } | ||
|
|
||
| func (z zsh) export(key, value string) string { | ||
| // Use double quotes for PATH-like variables to avoid unnecessary ANSI-C quoting | ||
| if key == "PATH" { | ||
| return fmt.Sprintf("export %s=\"%s\";", key, value) | ||
| } | ||
| return "export " + z.escape(key) + "=" + z.escape(value) + ";" | ||
| } | ||
|
Comment on lines
76
to
78
|
||
|
|
||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
clink.set()previously interpolatedkeyandvaluedirectly intoset "KEY=VALUE", which is a common injection vector in cmd/batch contexts (quotes/newlines/%/delayed expansion). Please add unit tests coveringescapeCmdSet()for cases like embedded",%VAR%,!VAR!(delayed expansion), and CR/LF to ensure the generated activation script can't be broken out of.