]> granicus.if.org Git - php/commitdiff
Disable rsh/ssh functionality in imap by default (bug #77153)
authorStanislav Malyshev <stas@php.net>
Mon, 19 Nov 2018 01:10:43 +0000 (17:10 -0800)
committerStanislav Malyshev <stas@php.net>
Tue, 20 Nov 2018 19:14:07 +0000 (11:14 -0800)
NEWS
UPGRADING
ext/imap/php_imap.c
ext/imap/php_imap.h
ext/imap/tests/bug77153.phpt [new file with mode: 0644]

diff --git a/NEWS b/NEWS
index 1b39a26e2bd590a1b823fe7266285ce55af4739e..2baed79dfb42f54d3fa6b06cf8d50b751292109c 100644 (file)
--- a/NEWS
+++ b/NEWS
@@ -2,7 +2,9 @@ PHP                                                                        NEWS
 |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
 ?? ??? 2018 PHP 7.0.33
 
-
+- IMAP:
+  . Fixed bug #77153 (imap_open allows to run arbitrary shell commands via
+    mailbox parameter). (Stas)
 
 13 Sep 2018 PHP 7.0.32
 
index c9e5a021eb409dda47177d52f7444273b784d05c..35e82b94ec2dd2b314a11949081a26e11cc86ea8 100644 (file)
--- a/UPGRADING
+++ b/UPGRADING
@@ -526,6 +526,13 @@ Other
   . Removed xsl.security_prefs ini option. Use XsltProcessor::setSecurityPrefs()
     instead.
 
+- IMAP:
+  Starting with 7.0.33, 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
 ========================================
index 9799112e0112c006c9e11056acda1cfed86c91fe..164af9d0f425ec2cffabf89d5387a3c83b7c94f2 100644 (file)
@@ -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 = {
@@ -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 */
@@ -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;
 }
index b4b4360860ee9085a03ba6031f8756eb250f623c..f7083d13f9e577fe8ceaa0bb1b599c93cbd93d46 100644 (file)
@@ -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
diff --git a/ext/imap/tests/bug77153.phpt b/ext/imap/tests/bug77153.phpt
new file mode 100644 (file)
index 0000000..63590ae
--- /dev/null
@@ -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');
+?>
\ No newline at end of file