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

Commit

Permalink
- Addressed issue #18 where arrays may potentially allow for compromi…
Browse files Browse the repository at this point in the history
…sing the sandbox by encapsulating unsandboxed callables
  • Loading branch information
fieryprophet committed Feb 27, 2015
1 parent 7c42b12 commit 4a30e96
Show file tree
Hide file tree
Showing 8 changed files with 35 additions and 6 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
#CHANGELOG

##02/27/2015
- Addressed issue #18 where arrays may potentially allow for compromising the sandbox by encapsulating unsandboxed callables

##07/24/2014
- Fixed bug with prepare_vars()

Expand Down
2 changes: 1 addition & 1 deletion src/Error.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
* @namespace PHPSandbox
*
* @author Elijah Horton <[email protected]>
* @version 1.3.9
* @version 1.3.10
*/
class Error extends \Exception {
/* START ERROR CODES */
Expand Down
2 changes: 1 addition & 1 deletion src/PHPSandbox.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
* @namespace PHPSandbox
*
* @author Elijah Horton <[email protected]>
* @version 1.3.9
* @version 1.3.10
*/
class PHPSandbox implements \IteratorAggregate {
/**
Expand Down
2 changes: 1 addition & 1 deletion src/SandboxWhitelistVisitor.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
* @namespace PHPSandbox
*
* @author Elijah Horton <[email protected]>
* @version 1.3.9
* @version 1.3.10
*/
class SandboxWhitelistVisitor extends \PHPParser_NodeVisitorAbstract {
/** The PHPSandbox instance to check against
Expand Down
2 changes: 1 addition & 1 deletion src/SandboxedString.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
* @namespace PHPSandbox
*
* @author Elijah Horton <[email protected]>
* @version 1.3.9
* @version 1.3.10
*/
class SandboxedString implements \ArrayAccess, \IteratorAggregate {
/**
Expand Down
2 changes: 1 addition & 1 deletion src/ValidatorVisitor.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
* @namespace PHPSandbox
*
* @author Elijah Horton <[email protected]>
* @version 1.3.9
* @version 1.3.10
*/
class ValidatorVisitor extends \PHPParser_NodeVisitorAbstract {
/** The PHPSandbox instance to check against
Expand Down
2 changes: 1 addition & 1 deletion src/WhitelistVisitor.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
* @namespace PHPSandbox
*
* @author Elijah Horton <[email protected]>
* @version 1.3.9
* @version 1.3.10
*/
class WhitelistVisitor extends \PHPParser_NodeVisitorAbstract {
/** The PHPSandbox instance to check against
Expand Down
26 changes: 26 additions & 0 deletions src/functions.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,19 @@ function wrap($value, $sandbox){
if(!($value instanceof SandboxedString) && is_object($value) && method_exists($value, '__toString')){
$strval = $value->__toString();
return is_callable($strval) ? new SandboxedString($strval, $sandbox) : $value;
} else if(is_array($value) && count($value)){
//save current array pointer
$current_key = key($value);
foreach($value as $key => &$_value) {
$value[$key] = wrap($_value, $sandbox);
}
//rewind array pointer
reset($value);
//advance array to previous array key
while(key($value) !== $current_key){
next($value);
}
return $value;
} else if(is_string($value) && is_callable($value)){
return new SandboxedString($value, $sandbox);
}
Expand All @@ -29,6 +42,19 @@ function &wrapByRef(&$value, $sandbox){
if(!($value instanceof SandboxedString) && is_object($value) && method_exists($value, '__toString')){
$strval = $value->__toString();
return is_callable($strval) ? new SandboxedString($strval, $sandbox) : $value;
} else if(is_array($value) && count($value)){
//save current array pointer
$current_key = key($value);
foreach($value as $key => &$_value) {
$value[$key] = wrap($_value, $sandbox);
}
//rewind array pointer
reset($value);
//advance array to saved array pointer
while(key($value) !== $current_key){
next($value);
}
return $value;
} else if(is_string($value) && is_callable($value)){
return new SandboxedString($value, $sandbox);
}
Expand Down

0 comments on commit 4a30e96

Please sign in to comment.