Given a string from an untrusted source, e.g.
MALICIOUS_INPUT="$(awk -F = '/^VERSION=/ {print $2}' /path/to/compromised/etc/os-release | head -n 1)"
is it possible to just apply pure shell quote removal (see Shell Command Language (IEEE Std 1003.1-2017) and Bash manual) to that string i.e. without doing variable expansions, arithmetic expansions, command substitution and similar?
This is needed, for example to parse strings from os-release files without source
-ing the files.
Input | Expected result |
---|---|
'\"' |
\" |
"\"" |
" |
'$foo${foo}$(pwd)$((1+2))' |
$foo${foo}$(pwd)$((1+2)) |
"$foo${foo}$(pwd)$((1+2))" |
$foo${foo}$(pwd)$((1+2)) |