Skip to content

Commit 44b08a9

Browse files
committed
Disable rsh/ssh functionality in imap by default (bug #77153)
1 parent 03a3a04 commit 44b08a9

File tree

3 files changed

+42
-0
lines changed

3 files changed

+42
-0
lines changed

ext/imap/php_imap.c

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

564+
565+
/* {{{ PHP_INI
566+
*/
567+
PHP_INI_BEGIN()
568+
STD_PHP_INI_BOOLEAN("imap.enable_insecure_rsh", "0", PHP_INI_SYSTEM, OnUpdateBool, enable_rsh, zend_imap_globals, imap_globals)
569+
PHP_INI_END()
570+
/* }}} */
571+
572+
564573
/* {{{ imap_module_entry
565574
*/
566575
zend_module_entry imap_module_entry = {
@@ -831,6 +840,8 @@ PHP_MINIT_FUNCTION(imap)
831840
{
832841
unsigned long sa_all = SA_MESSAGES | SA_RECENT | SA_UNSEEN | SA_UIDNEXT | SA_UIDVALIDITY;
833842

843+
REGISTER_INI_ENTRIES();
844+
834845
#ifndef PHP_WIN32
835846
mail_link(&unixdriver); /* link in the unix driver */
836847
mail_link(&mhdriver); /* link in the mh driver */
@@ -1048,6 +1059,12 @@ PHP_MINIT_FUNCTION(imap)
10481059
GC_TEXTS texts
10491060
*/
10501061

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

ext/imap/php_imap.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -229,6 +229,7 @@ ZEND_BEGIN_MODULE_GLOBALS(imap)
229229
#endif
230230
/* php_stream for php_mail_gets() */
231231
php_stream *gets_stream;
232+
zend_bool enable_rsh;
232233
ZEND_END_MODULE_GLOBALS(imap)
233234

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