Skip to content

Commit 336d208

Browse files
committed
Disable rsh/ssh functionality in imap by default (bug #77153)
1 parent e7acb29 commit 336d208

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
@@ -17,6 +17,10 @@ PHP NEWS
1717
. Fixed bug #77147 (Fixing 60494 ignored ICONV_MIME_DECODE_CONTINUE_ON_ERROR).
1818
(cmb)
1919

20+
- IMAP:
21+
. Fixed bug #77153 (imap_open allows to run arbitrary shell commands via
22+
mailbox parameter). (Stas)
23+
2024
- ODBC:
2125
. Fixed bug #77079 (odbc_fetch_object has incorrect type signature).
2226
(Jon Allen)

UPGRADING

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,13 @@ PHP 7.2 UPGRADE NOTES
9999
from PHP 7.1 on 64-bit machines. This change was necessary to resolve a
100100
modulo bias bug in the implementation.
101101

102+
- IMAP:
103+
Starting with 7.2.13, rsh/ssh logins are disabled by default. Use
104+
imap.enable_insecure_rsh if you want to enable them. Note that the IMAP
105+
library does not filter mailbox names before passing them to rsh/ssh
106+
command, thus passing untrusted data to this function with rsh/ssh enabled
107+
is insecure.
108+
102109
========================================
103110
2. New Features
104111
========================================

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 = {
@@ -832,6 +841,8 @@ PHP_MINIT_FUNCTION(imap)
832841
{
833842
unsigned long sa_all = SA_MESSAGES | SA_RECENT | SA_UNSEEN | SA_UIDNEXT | SA_UIDVALIDITY;
834843

844+
REGISTER_INI_ENTRIES();
845+
835846
#ifndef PHP_WIN32
836847
mail_link(&unixdriver); /* link in the unix driver */
837848
mail_link(&mhdriver); /* link in the mh driver */
@@ -1049,6 +1060,12 @@ PHP_MINIT_FUNCTION(imap)
10491060
GC_TEXTS texts
10501061
*/
10511062

1063+
if (!IMAPG(enable_rsh)) {
1064+
/* disable SSH and RSH, see https://bugs.php.net/bug.php?id=77153 */
1065+
mail_parameters (NIL, SET_RSHTIMEOUT, 0);
1066+
mail_parameters (NIL, SET_SSHTIMEOUT, 0);
1067+
}
1068+
10521069
le_imap = zend_register_list_destructors_ex(mail_close_it, NULL, "imap", module_number);
10531070
return SUCCESS;
10541071
}

ext/imap/php_imap.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -231,6 +231,7 @@ ZEND_BEGIN_MODULE_GLOBALS(imap)
231231
#endif
232232
/* php_stream for php_mail_gets() */
233233
php_stream *gets_stream;
234+
zend_bool enable_rsh;
234235
ZEND_END_MODULE_GLOBALS(imap)
235236

236237
#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)