Skip to content
This repository was archived by the owner on Sep 5, 2018. It is now read-only.

Commit 4a30e96

Browse files
committed
- Addressed issue #18 where arrays may potentially allow for compromising the sandbox by encapsulating unsandboxed callables
1 parent 7c42b12 commit 4a30e96

File tree

8 files changed

+35
-6
lines changed

8 files changed

+35
-6
lines changed

CHANGELOG.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
#CHANGELOG
22

3+
##02/27/2015
4+
- Addressed issue #18 where arrays may potentially allow for compromising the sandbox by encapsulating unsandboxed callables
5+
36
##07/24/2014
47
- Fixed bug with prepare_vars()
58

src/Error.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
* @namespace PHPSandbox
1212
*
1313
* @author Elijah Horton <fieryprophet@yahoo.com>
14-
* @version 1.3.9
14+
* @version 1.3.10
1515
*/
1616
class Error extends \Exception {
1717
/* START ERROR CODES */

src/PHPSandbox.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
* @namespace PHPSandbox
1515
*
1616
* @author Elijah Horton <fieryprophet@yahoo.com>
17-
* @version 1.3.9
17+
* @version 1.3.10
1818
*/
1919
class PHPSandbox implements \IteratorAggregate {
2020
/**

src/SandboxWhitelistVisitor.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
* @namespace PHPSandbox
1414
*
1515
* @author Elijah Horton <fieryprophet@yahoo.com>
16-
* @version 1.3.9
16+
* @version 1.3.10
1717
*/
1818
class SandboxWhitelistVisitor extends \PHPParser_NodeVisitorAbstract {
1919
/** The PHPSandbox instance to check against

src/SandboxedString.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
* @namespace PHPSandbox
1212
*
1313
* @author Elijah Horton <fieryprophet@yahoo.com>
14-
* @version 1.3.9
14+
* @version 1.3.10
1515
*/
1616
class SandboxedString implements \ArrayAccess, \IteratorAggregate {
1717
/**

src/ValidatorVisitor.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
* @namespace PHPSandbox
1414
*
1515
* @author Elijah Horton <fieryprophet@yahoo.com>
16-
* @version 1.3.9
16+
* @version 1.3.10
1717
*/
1818
class ValidatorVisitor extends \PHPParser_NodeVisitorAbstract {
1919
/** The PHPSandbox instance to check against

src/WhitelistVisitor.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
* @namespace PHPSandbox
1414
*
1515
* @author Elijah Horton <fieryprophet@yahoo.com>
16-
* @version 1.3.9
16+
* @version 1.3.10
1717
*/
1818
class WhitelistVisitor extends \PHPParser_NodeVisitorAbstract {
1919
/** The PHPSandbox instance to check against

src/functions.php

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,19 @@ function wrap($value, $sandbox){
1212
if(!($value instanceof SandboxedString) && is_object($value) && method_exists($value, '__toString')){
1313
$strval = $value->__toString();
1414
return is_callable($strval) ? new SandboxedString($strval, $sandbox) : $value;
15+
} else if(is_array($value) && count($value)){
16+
//save current array pointer
17+
$current_key = key($value);
18+
foreach($value as $key => &$_value) {
19+
$value[$key] = wrap($_value, $sandbox);
20+
}
21+
//rewind array pointer
22+
reset($value);
23+
//advance array to previous array key
24+
while(key($value) !== $current_key){
25+
next($value);
26+
}
27+
return $value;
1528
} else if(is_string($value) && is_callable($value)){
1629
return new SandboxedString($value, $sandbox);
1730
}
@@ -29,6 +42,19 @@ function &wrapByRef(&$value, $sandbox){
2942
if(!($value instanceof SandboxedString) && is_object($value) && method_exists($value, '__toString')){
3043
$strval = $value->__toString();
3144
return is_callable($strval) ? new SandboxedString($strval, $sandbox) : $value;
45+
} else if(is_array($value) && count($value)){
46+
//save current array pointer
47+
$current_key = key($value);
48+
foreach($value as $key => &$_value) {
49+
$value[$key] = wrap($_value, $sandbox);
50+
}
51+
//rewind array pointer
52+
reset($value);
53+
//advance array to saved array pointer
54+
while(key($value) !== $current_key){
55+
next($value);
56+
}
57+
return $value;
3258
} else if(is_string($value) && is_callable($value)){
3359
return new SandboxedString($value, $sandbox);
3460
}

0 commit comments

Comments
 (0)