Skip to content

Commit 038ae47

Browse files
committed
Check more escape sequences
1 parent 436328a commit 038ae47

File tree

2 files changed

+14
-2
lines changed

2 files changed

+14
-2
lines changed

webview-ui/src/utils/__tests__/command-validation.spec.ts

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -246,6 +246,17 @@ ls -la || echo "Failed"`
246246
expect(containsDangerousSubstitution('echo "${var=\\xFF}"')).toBe(true)
247247
})
248248

249+
it("detects parameter assignments with unicode escape sequences", () => {
250+
// Unicode \u0060 is backtick
251+
expect(containsDangerousSubstitution('echo "${var=\\u0060whoami\\u0060}"')).toBe(true)
252+
expect(containsDangerousSubstitution('echo "${var:=\\u0060ls\\u0060}"')).toBe(true)
253+
expect(containsDangerousSubstitution('echo "${var+\\u0060pwd\\u0060}"')).toBe(true)
254+
expect(containsDangerousSubstitution('echo "${var:-\\u0060date\\u0060}"')).toBe(true)
255+
// Test various unicode patterns
256+
expect(containsDangerousSubstitution('echo "${var=\\u0000\\u0060\\u0061}"')).toBe(true)
257+
expect(containsDangerousSubstitution('echo "${var=\\uFFFF}"')).toBe(true)
258+
})
259+
249260
it("detects indirect variable references", () => {
250261
// ${!var} performs indirect expansion which can be dangerous
251262
expect(containsDangerousSubstitution("echo ${!var}")).toBe(true)

webview-ui/src/utils/command-validation.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ type ShellToken = string | { op: string } | { command: string }
6868
* - ${var@E} - Escape sequence expansion
6969
* - ${var@A} - Assignment statement
7070
* - ${var@a} - Attribute flags
71-
* - ${var=value} with escape sequences - Can embed commands via \140 (backtick) or \x60
71+
* - ${var=value} with escape sequences - Can embed commands via \140 (backtick), \x60, or \u0060
7272
* - ${!var} - Indirect variable references
7373
* - <<<$(...) or <<<`...` - Here-strings with command substitution
7474
*
@@ -89,7 +89,8 @@ export function containsDangerousSubstitution(source: string): boolean {
8989
// Also check for ${var+value}, ${var:-value}, ${var:+value}, ${var:?value}
9090
const parameterAssignmentWithEscapes =
9191
/\$\{[^}]*[=+\-?][^}]*\\[0-7]{3}[^}]*\}/.test(source) || // octal escapes
92-
/\$\{[^}]*[=+\-?][^}]*\\x[0-9a-fA-F]{2}[^}]*\}/.test(source) // hex escapes
92+
/\$\{[^}]*[=+\-?][^}]*\\x[0-9a-fA-F]{2}[^}]*\}/.test(source) || // hex escapes
93+
/\$\{[^}]*[=+\-?][^}]*\\u[0-9a-fA-F]{4}[^}]*\}/.test(source) // unicode escapes
9394

9495
// Check for indirect variable references that could execute commands
9596
// ${!var} performs indirect expansion which can be dangerous with crafted variable names

0 commit comments

Comments
 (0)