Skip to content

Commit 628df47

Browse files
committed
Disable rsh/ssh functionality in imap by default (bug #77153)
1 parent cba6055 commit 628df47

File tree

5 files changed

+52
-1
lines changed

5 files changed

+52
-1
lines changed

NEWS

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,9 @@ PHP NEWS
22
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
33
?? ??? 2018 PHP 7.0.33
44

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

79
13 Sep 2018 PHP 7.0.32
810

UPGRADING

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -526,6 +526,13 @@ Other
526526
. Removed xsl.security_prefs ini option. Use XsltProcessor::setSecurityPrefs()
527527
instead.
528528

529+
- IMAP:
530+
Starting with 7.0.33, rsh/ssh logins are disabled by default. Use
531+
imap.enable_insecure_rsh if you want to enable them. Note that the IMAP
532+
library does not filter mailbox names before passing them to rsh/ssh
533+
command, thus passing untrusted data to this function with rsh/ssh enabled
534+
is insecure.
535+
529536
========================================
530537
2. New Features
531538
========================================

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
@@ -216,6 +216,7 @@ ZEND_BEGIN_MODULE_GLOBALS(imap)
216216
#endif
217217
/* php_stream for php_mail_gets() */
218218
php_stream *gets_stream;
219+
zend_bool enable_rsh;
219220
ZEND_END_MODULE_GLOBALS(imap)
220221

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