Skip to content

Commit e5bfea6

Browse files
committed
Disable rsh/ssh functionality in imap by default (bug #77153)
1 parent 81f2305 commit e5bfea6

File tree

5 files changed

+53
-0
lines changed

5 files changed

+53
-0
lines changed

NEWS

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,10 @@ PHP NEWS
22
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
33
?? ??? 2018, PHP 5.6.39
44

5+
- IMAP:
6+
. Fixed bug #77153 (imap_open allows to run arbitrary shell commands via
7+
mailbox parameter). (Stas)
8+
59
13 Sep 2018, PHP 5.6.38
610

711
- Apache2

UPGRADING

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,13 @@ PHP 5.6 UPGRADE NOTES
6464
- cURL:
6565
Uploads using the @file syntax are now unsupported by default.
6666

67+
- IMAP:
68+
Starting with 5.6.38, rsh/ssh logins are disabled by default. Use
69+
imap.enable_insecure_rsh if you want to enable them. Note that the IMAP
70+
library does not filter mailbox names before passing them to rsh/ssh
71+
command, thus passing untrusted data to this function with rsh/ssh enabled
72+
is insecure.
73+
6774
========================================
6875
2. New Features
6976
========================================

ext/imap/php_imap.c

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -562,6 +562,15 @@ static const zend_module_dep imap_deps[] = {
562562
};
563563
/* }}} */
564564

565+
566+
/* {{{ PHP_INI
567+
*/
568+
PHP_INI_BEGIN()
569+
STD_PHP_INI_BOOLEAN("imap.enable_insecure_rsh", "0", PHP_INI_SYSTEM, OnUpdateBool, enable_rsh, zend_imap_globals, imap_globals)
570+
PHP_INI_END()
571+
/* }}} */
572+
573+
565574
/* {{{ imap_module_entry
566575
*/
567576
zend_module_entry imap_module_entry = {
@@ -835,6 +844,8 @@ PHP_MINIT_FUNCTION(imap)
835844
{
836845
unsigned long sa_all = SA_MESSAGES | SA_RECENT | SA_UNSEEN | SA_UIDNEXT | SA_UIDVALIDITY;
837846

847+
REGISTER_INI_ENTRIES();
848+
838849
#ifndef PHP_WIN32
839850
mail_link(&unixdriver); /* link in the unix driver */
840851
mail_link(&mhdriver); /* link in the mh driver */
@@ -1052,6 +1063,12 @@ PHP_MINIT_FUNCTION(imap)
10521063
GC_TEXTS texts
10531064
*/
10541065

1066+
if (!IMAPG(enable_rsh)) {
1067+
/* disable SSH and RSH, see https://bugs.php.net/bug.php?id=77153 */
1068+
mail_parameters (NIL, SET_RSHTIMEOUT, 0);
1069+
mail_parameters (NIL, SET_SSHTIMEOUT, 0);
1070+
}
1071+
10551072
le_imap = zend_register_list_destructors_ex(mail_close_it, NULL, "imap", module_number);
10561073
return SUCCESS;
10571074
}

ext/imap/php_imap.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -214,6 +214,7 @@ ZEND_BEGIN_MODULE_GLOBALS(imap)
214214
#endif
215215
/* php_stream for php_mail_gets() */
216216
php_stream *gets_stream;
217+
zend_bool enable_rsh;
217218
ZEND_END_MODULE_GLOBALS(imap)
218219

219220
#ifdef ZTS

ext/imap/tests/bug77153.phpt

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
--TEST--
2+
Bug #77153 (imap_open allows to run arbitrary shell commands via mailbox parameter)
3+
--SKIPIF--
4+
<?php
5+
if (!extension_loaded("imap")) {
6+
die("skip imap extension not available");
7+
}
8+
?>
9+
--FILE--
10+
<?php
11+
$payload = "echo 'BUG'> " . __DIR__ . '/__bug';
12+
$payloadb64 = base64_encode($payload);
13+
$server = "x -oProxyCommand=echo\t$payloadb64|base64\t-d|sh}";
14+
@imap_open('{'.$server.':143/imap}INBOX', '', '');
15+
// clean
16+
imap_errors();
17+
var_dump(file_exists(__DIR__ . '/__bug'));
18+
?>
19+
--EXPECT--
20+
bool(false)
21+
--CLEAN--
22+
<?php
23+
if(file_exists(__DIR__ . '/__bug')) unlink(__DIR__ . '/__bug');
24+
?>

0 commit comments

Comments
 (0)