# php_escape_shell_cmd

- Thread: https://externals.io/message/1406
- Original archive: https://news-web.php.net/php.internals/1406
- Started by Jamison Charlesworth on 2003-05-09T09:50:42+00:00
- Messages: 1
- Reply by email to internals@lists.php.net
- More for agents: search with https://externals.io/search.md?q={query} · JSON API at https://externals.io/api · documentation at https://externals.io/llms.txt

---

## #1406 — Jamison Charlesworth — 2003-05-09T09:50:42+00:00

URL: https://externals.io/message/1406#1406

I guess this would also require two new Boolean keywords to control its
operation:

 

safe_mode_allow_redirect_under_docroot

safe_mode_allow_redirect_under_safe_exec_dir

 

-----Original Message-----
From: Jamison Charlesworth [mailto:jc@firststopinternet.com] 
Sent: 09 May 2003 10:33
To: 'internals@lists.php.net'
Subject: RE: php_escape_shell_cmd

 

I have done this now in the form of a patch and it follows the following
logic:

 

Just before php_escape_shell_cmd returns it calls a new function
'php_remove_escape_if_safe()'

 

This scans the shell command for any '|', '>' or '<' (called redirects
for the purpose of this message).

 

If the cmd contains '..' anywhere in the string, the function does
nothing.

 

If the text following the redirect starts with DOCUMENT_ROOT or
safe_mode_exec_dir then it is allowed (the preceeding '\' is set to
space).

 

Unless the redirect is '>' and the redirect starts with
safe_mode_exec_dir, to prevent overwriting or creation of execs in this
directory.

 

 

Is anyone interested in putting forward this idea as a general mod? -
This would help those of us running PHP on virtual servers..

 

I have also added a new keyword 'safe_mode_include_docroot' which acts
like 'safe_mode_include_dir', only its dynamic and allows reading by
other uid's and gid's when the file(s) are beneath DOCUMENT_ROOT.

 

This also helps virtual servers.

 

-----Original Message-----
From: Jamison Charlesworth [mailto:jc@firststopinternet.com] 
Sent: 08 May 2003 14:31
To: 'php-dev@lists.php.net'
Subject: php_escape_shell_cmd

 

Hi

 

I am thinking of making a mod to this to help people using scripts on my
virtual servers.

 

At present when in SAFE_MODE the pipe '|' and redirect '<' '>'  entries
are escaped, and the reasons for this are well understood.

 

However, I am thinking that if the executable is in safe_mode_exec_dir
and the command being 'piped' to is also in the safe_mode_exec_dir then
this would be safe to allow.

 

Also, if a file beinf redirected via < or > is within the DOCUMENT_ROOT
then this should also be allowed.

 

Any views on this?

 

Regards, Jamie.
