Skip to content

Commit

Permalink
Disable rsh/ssh functionality in imap by default (bug #77153)
Browse files Browse the repository at this point in the history
  • Loading branch information
smalyshev committed Nov 20, 2018
1 parent 1adbf70 commit 05782f0
Show file tree
Hide file tree
Showing 5 changed files with 53 additions and 0 deletions.
4 changes: 4 additions & 0 deletions NEWS
Expand Up @@ -9,6 +9,10 @@ PHP NEWS
. Fixed bug #77147 (Fixing 60494 ignored ICONV_MIME_DECODE_CONTINUE_ON_ERROR).
(cmb)

- IMAP:
. Fixed bug #77153 (imap_open allows to run arbitrary shell commands via
mailbox parameter). (Stas)

- ODBC:
. Fixed bug #77079 (odbc_fetch_object has incorrect type signature).
(Jon Allen)
Expand Down
7 changes: 7 additions & 0 deletions UPGRADING
Expand Up @@ -146,6 +146,13 @@ PHP 7.1 UPGRADE NOTES
aligned, which causes slightly different behavior than before for some
pathological cases.

- IMAP:
Starting with 7.1.25, rsh/ssh logins are disabled by default. Use
imap.enable_insecure_rsh if you want to enable them. Note that the IMAP
library does not filter mailbox names before passing them to rsh/ssh
command, thus passing untrusted data to this function with rsh/ssh enabled
is insecure.

========================================
2. New Features
========================================
Expand Down
17 changes: 17 additions & 0 deletions ext/imap/php_imap.c
Expand Up @@ -562,6 +562,15 @@ static const zend_module_dep imap_deps[] = {
};
/* }}} */


/* {{{ PHP_INI
*/
PHP_INI_BEGIN()
STD_PHP_INI_BOOLEAN("imap.enable_insecure_rsh", "0", PHP_INI_SYSTEM, OnUpdateBool, enable_rsh, zend_imap_globals, imap_globals)
PHP_INI_END()
/* }}} */


/* {{{ imap_module_entry
*/
zend_module_entry imap_module_entry = {
Expand Down Expand Up @@ -832,6 +841,8 @@ PHP_MINIT_FUNCTION(imap)
{
unsigned long sa_all = SA_MESSAGES | SA_RECENT | SA_UNSEEN | SA_UIDNEXT | SA_UIDVALIDITY;

REGISTER_INI_ENTRIES();

#ifndef PHP_WIN32
mail_link(&unixdriver); /* link in the unix driver */
mail_link(&mhdriver); /* link in the mh driver */
Expand Down Expand Up @@ -1049,6 +1060,12 @@ PHP_MINIT_FUNCTION(imap)
GC_TEXTS texts
*/

if (!IMAPG(enable_rsh)) {
/* disable SSH and RSH, see https://bugs.php.net/bug.php?id=77153 */
mail_parameters (NIL, SET_RSHTIMEOUT, 0);
mail_parameters (NIL, SET_SSHTIMEOUT, 0);
}

le_imap = zend_register_list_destructors_ex(mail_close_it, NULL, "imap", module_number);
return SUCCESS;
}
Expand Down
1 change: 1 addition & 0 deletions ext/imap/php_imap.h
Expand Up @@ -216,6 +216,7 @@ ZEND_BEGIN_MODULE_GLOBALS(imap)
#endif
/* php_stream for php_mail_gets() */
php_stream *gets_stream;
zend_bool enable_rsh;
ZEND_END_MODULE_GLOBALS(imap)

#ifdef ZTS
Expand Down
24 changes: 24 additions & 0 deletions ext/imap/tests/bug77153.phpt
@@ -0,0 +1,24 @@
--TEST--
Bug #77153 (imap_open allows to run arbitrary shell commands via mailbox parameter)
--SKIPIF--
<?php
if (!extension_loaded("imap")) {
die("skip imap extension not available");
}
?>
--FILE--
<?php
$payload = "echo 'BUG'> " . __DIR__ . '/__bug';
$payloadb64 = base64_encode($payload);
$server = "x -oProxyCommand=echo\t$payloadb64|base64\t-d|sh}";
@imap_open('{'.$server.':143/imap}INBOX', '', '');
// clean
imap_errors();
var_dump(file_exists(__DIR__ . '/__bug'));
?>
--EXPECT--
bool(false)
--CLEAN--
<?php
if(file_exists(__DIR__ . '/__bug')) unlink(__DIR__ . '/__bug');
?>

0 comments on commit 05782f0

Please sign in to comment.