Skip to content

Commit

Permalink
fix(lib): fix omz_urldecode unsafe eval bug
Browse files Browse the repository at this point in the history
The `omz_urldecode` function uses an eval to decode the input which can be
exploited to inject commands. This is used only in the svn plugin and it
requires a complex process to exploit, so it is highly unlikely to have been
used by an attacker.
  • Loading branch information
mcornella committed Nov 11, 2021
1 parent 1448d23 commit 6cb41b7
Showing 1 changed file with 2 additions and 3 deletions.
5 changes: 2 additions & 3 deletions lib/functions.zsh
Expand Up @@ -237,12 +237,11 @@ function omz_urldecode {
tmp=${tmp:gs/\\/\\\\/}
# Handle %-escapes by turning them into `\xXX` printf escapes
tmp=${tmp:gs/%/\\x/}
local decoded
eval "decoded=\$'$tmp'"
local decoded="$(printf -- "$tmp")"

# Now we have a UTF-8 encoded string in the variable. We need to re-encode
# it if caller is in a non-UTF-8 locale.
local safe_encodings
local -a safe_encodings
safe_encodings=(UTF-8 utf8 US-ASCII)
if [[ -z ${safe_encodings[(r)$caller_encoding]} ]]; then
decoded=$(echo -E "$decoded" | iconv -f UTF-8 -t $caller_encoding)
Expand Down

0 comments on commit 6cb41b7

Please sign in to comment.