mirror of
https://github.com/anomalyco/opencode.git
synced 2026-11-26 23:28:43 +00:00
fix(core): stop repeated zsh q flags from freezing the shell scanner (#60791)
Co-authored-by: yangguan-xue <184704694+yangguan-xue@users.noreply.github.com> Co-authored-by: Daniel Smolsky <dannysmo@gmail.com>
This commit is contained in:
parent
3ca0739383
commit
e0300a9bfc
2 changed files with 8 additions and 1 deletions
|
|
@ -114,7 +114,7 @@ const FUNCTION_BODY_RE =
|
|||
const DO_AHEAD_RE = /(?:[ \t\n;]|\\\n|#[^\n]*(?:\n|$))*(?:do(?=(?:\\\n)*(?:[ \t\n;{(]|$))|\{(?=(?:\\\n)*[ \t\n]))/y
|
||||
const NOFORK_OPEN_RE = /\$\{(?:\\\n)*(?:[ \t\n]|\|)/y
|
||||
// Zsh flags that neither evaluate nor glob a value; s and j take an argument between repeated delimiters.
|
||||
const ZSH_SAFE_FLAGS_RE = /\$\{\((?:[@AaBbCcDEfFikLMmNnOopPqStUuVvWwXZz0-]|q[-+]?|[js]([^({[<\\])(?:(?!\1)[^)])*\1)*\)/y
|
||||
const ZSH_SAFE_FLAGS_RE = /\$\{\((?:[@AaBbCcDEfFikLMmNnOopPqStUuVvWwXZz0-]|q[+]|[js]([^({[<\\])(?:(?!\1)[^)])*\1)*\)/y
|
||||
const ZSH_QUOTED_FLAG_ARG_RE = /[js]([^({[<\\])(?:(?!\1)[^)])*\1/g
|
||||
const ZSH_GLOB_MODIFIER_RE = /(?:[\^=~#+]|\\\n)*~/y
|
||||
// Trailing Zsh glob qualifiers without code execution (e, +cmd), delimiters (f, u, g, P), modifiers (:), or math expressions.
|
||||
|
|
|
|||
|
|
@ -77,6 +77,13 @@ describe("ShellScan adversarial corpus", () => {
|
|||
expect(performance.now() - start).toBeLessThan(500)
|
||||
})
|
||||
|
||||
test("scans repeated zsh q flags in bounded time", () => {
|
||||
const start = performance.now()
|
||||
ShellScan.scan("echo ${(" + "q".repeat(40) + "!x}", "zsh")
|
||||
ShellScan.scan("echo ${(" + "q-".repeat(40) + "!x}", "zsh")
|
||||
expect(performance.now() - start).toBeLessThan(500)
|
||||
})
|
||||
|
||||
test.each([
|
||||
['pwsh --command "Remove-Item victim.txt"', ["pwsh"]],
|
||||
["Import-Module ./evil.psm1", ["Import-Module"]],
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue