From: Eli Zaretskii <eliz@gnu.org>
To: taylanbayirli@gmail.com (Taylan Ulrich Bayırlı/Kammer)
Cc: 21702@debbugs.gnu.org
Subject: bug#21702: shell-quote-argument semantics and safety
Date: Sun, 18 Oct 2015 20:16:54 +0300 [thread overview]
Message-ID: <83pp0chzax.fsf@gnu.org> (raw)
In-Reply-To: <871tcstkuk.fsf@T420.taylan>
> From: taylanbayirli@gmail.com (Taylan Ulrich
> Bayırlı/Kammer)
> Date: Sun, 18 Oct 2015 14:36:03 +0200
>
> The documentation of shell-quote-argument only says
>
> Quote ARGUMENT for passing as argument to an inferior shell.
>
> It's unclear for which shells this is supposed to work.
I fixed the doc string to clarify that this function works correctly
with the system's standard shell.
> In a recent thread in emacs-devel, it has been demonstrated that if
> the result is passed to csh, it can allow an attacker to execute an
> arbitrary shell command
As I understand it, csh is not the standard shell on Posix systems, so
the fixed doc string now says not to expect it to work with csh.
> The function should clearly document
>
> 1) for which shells will the quoting work absolutely, i.e. lead to
> the given string to appear *verbatim* in an element of the ARGV of
> the called command,
>
> 2) optionally, for which shells will the quoting at least prevent
> code injection,
>
> 3) optionally, for which shells and character sets for ARGUMENT will
> the quoting work absolutely,
>
> 4) optionally, for which shells and character sets for ARGUMENT will
> the quoting at least prevent code injection,
>
> 5) optionally, for which shells will the quoting work at all even if
> it provides no clear semantics, such that one can at least use it
> with data coming from trusted sources (e.g. other parts of Emacs's
> source code, or the user sitting in front of Emacs), where it's the
> user's/programmer's responsibility to stick to values for ARGUMENT
> that are intuitively known to be unproblematic even if the character
> set isn't well-defined.
>
> Currently #5 seems to be implied for all shells, for lack of further
> documentation. Possibly, the function was never meant to be used with
> untrusted data, but there's no warning against doing so either.
I thin 1) is now covered, and the rest are optional. In particular,
our way to provide better safety is not by documenting APIs that could
be maliciously abused, but by marking the related variables as unsafe
unless they have special predefined values. So I don't think we
should extend this particular doc string with safety information.
> (defun shell-quote-argument (argument)
> - "Quote ARGUMENT for passing as argument to an inferior shell."
> + "Quote ARGUMENT for passing as argument to an inferior shell.
> +
> +This is safe for shells conforming to POSIX sh. No guarantees
> +regarding code injection are made for other shells, but csh,
> +MS-DOS and Windows NT are supported for simple cases as well."
Thanks, but I think this is no longer needed, after the change I made.
next prev parent reply other threads:[~2015-10-18 17:16 UTC|newest]
Thread overview: 13+ messages / expand[flat|nested] mbox.gz Atom feed top
2015-10-18 12:36 bug#21702: shell-quote-argument semantics and safety Taylan Ulrich Bayırlı/Kammer
[not found] ` <handler.21702.B.144517177511995.ack@debbugs.gnu.org>
2015-10-18 15:26 ` Taylan Ulrich Bayırlı/Kammer
2015-10-18 17:16 ` Eli Zaretskii [this message]
2015-10-18 19:12 ` Taylan Ulrich Bayırlı/Kammer
2015-10-18 19:48 ` Eli Zaretskii
2015-10-19 7:34 ` Taylan Ulrich Bayırlı/Kammer
2015-10-19 7:47 ` Eli Zaretskii
2015-10-19 9:22 ` Taylan Ulrich Bayırlı/Kammer
2015-10-19 9:32 ` Eli Zaretskii
2015-10-19 9:50 ` Taylan Ulrich Bayırlı/Kammer
2015-10-19 10:19 ` Eli Zaretskii
2015-10-19 10:25 ` Taylan Ulrich Bayırlı/Kammer
2015-10-22 3:49 ` Paul Eggert
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
List information: https://www.gnu.org/software/emacs/
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=83pp0chzax.fsf@gnu.org \
--to=eliz@gnu.org \
--cc=21702@debbugs.gnu.org \
--cc=taylanbayirli@gmail.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
Code repositories for project(s) associated with this public inbox
https://git.savannah.gnu.org/cgit/emacs.git
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).