summaryrefslogtreecommitdiff
path: root/inc/lib/Twig/Sandbox
diff options
context:
space:
mode:
authorAppleman1234 <applemansigloo@gmail.com>2022-09-25 13:22:40 +1000
committerAppleman1234 <applemansigloo@gmail.com>2022-09-25 13:22:40 +1000
commit92561d7f36508b7e0271926e417adf0e2e53916b (patch)
treea8588b4f70af276c5acf58836e33b1f6ff5c61e8 /inc/lib/Twig/Sandbox
parent6f1083e4b51fc9c4c594f6c72cf3d84ef4d0298b (diff)
Initial attempt a switch to composer and PHP-8.1 compatibility
Diffstat (limited to 'inc/lib/Twig/Sandbox')
-rw-r--r--inc/lib/Twig/Sandbox/SecurityError.php21
-rw-r--r--inc/lib/Twig/Sandbox/SecurityNotAllowedFilterError.php33
-rw-r--r--inc/lib/Twig/Sandbox/SecurityNotAllowedFunctionError.php33
-rw-r--r--inc/lib/Twig/Sandbox/SecurityNotAllowedMethodError.php40
-rw-r--r--inc/lib/Twig/Sandbox/SecurityNotAllowedPropertyError.php40
-rw-r--r--inc/lib/Twig/Sandbox/SecurityNotAllowedTagError.php33
-rw-r--r--inc/lib/Twig/Sandbox/SecurityPolicy.php125
-rw-r--r--inc/lib/Twig/Sandbox/SecurityPolicyInterface.php26
8 files changed, 0 insertions, 351 deletions
diff --git a/inc/lib/Twig/Sandbox/SecurityError.php b/inc/lib/Twig/Sandbox/SecurityError.php
deleted file mode 100644
index b6707e38..00000000
--- a/inc/lib/Twig/Sandbox/SecurityError.php
+++ /dev/null
@@ -1,21 +0,0 @@
-<?php
-
-/*
- * This file is part of Twig.
- *
- * (c) Fabien Potencier
- *
- * For the full copyright and license information, please view the LICENSE
- * file that was distributed with this source code.
- */
-
-/**
- * Exception thrown when a security error occurs at runtime.
- *
- * @author Fabien Potencier <fabien@symfony.com>
- */
-class Twig_Sandbox_SecurityError extends Twig_Error
-{
-}
-
-class_alias('Twig_Sandbox_SecurityError', 'Twig\Sandbox\SecurityError', false);
diff --git a/inc/lib/Twig/Sandbox/SecurityNotAllowedFilterError.php b/inc/lib/Twig/Sandbox/SecurityNotAllowedFilterError.php
deleted file mode 100644
index 0ba33276..00000000
--- a/inc/lib/Twig/Sandbox/SecurityNotAllowedFilterError.php
+++ /dev/null
@@ -1,33 +0,0 @@
-<?php
-
-/*
- * This file is part of Twig.
- *
- * (c) Fabien Potencier
- *
- * For the full copyright and license information, please view the LICENSE
- * file that was distributed with this source code.
- */
-
-/**
- * Exception thrown when a not allowed filter is used in a template.
- *
- * @author Martin Hasoň <martin.hason@gmail.com>
- */
-class Twig_Sandbox_SecurityNotAllowedFilterError extends Twig_Sandbox_SecurityError
-{
- private $filterName;
-
- public function __construct($message, $functionName, $lineno = -1, $filename = null, Exception $previous = null)
- {
- parent::__construct($message, $lineno, $filename, $previous);
- $this->filterName = $functionName;
- }
-
- public function getFilterName()
- {
- return $this->filterName;
- }
-}
-
-class_alias('Twig_Sandbox_SecurityNotAllowedFilterError', 'Twig\Sandbox\SecurityNotAllowedFilterError', false);
diff --git a/inc/lib/Twig/Sandbox/SecurityNotAllowedFunctionError.php b/inc/lib/Twig/Sandbox/SecurityNotAllowedFunctionError.php
deleted file mode 100644
index aa391429..00000000
--- a/inc/lib/Twig/Sandbox/SecurityNotAllowedFunctionError.php
+++ /dev/null
@@ -1,33 +0,0 @@
-<?php
-
-/*
- * This file is part of Twig.
- *
- * (c) Fabien Potencier
- *
- * For the full copyright and license information, please view the LICENSE
- * file that was distributed with this source code.
- */
-
-/**
- * Exception thrown when a not allowed function is used in a template.
- *
- * @author Martin Hasoň <martin.hason@gmail.com>
- */
-class Twig_Sandbox_SecurityNotAllowedFunctionError extends Twig_Sandbox_SecurityError
-{
- private $functionName;
-
- public function __construct($message, $functionName, $lineno = -1, $filename = null, Exception $previous = null)
- {
- parent::__construct($message, $lineno, $filename, $previous);
- $this->functionName = $functionName;
- }
-
- public function getFunctionName()
- {
- return $this->functionName;
- }
-}
-
-class_alias('Twig_Sandbox_SecurityNotAllowedFunctionError', 'Twig\Sandbox\SecurityNotAllowedFunctionError', false);
diff --git a/inc/lib/Twig/Sandbox/SecurityNotAllowedMethodError.php b/inc/lib/Twig/Sandbox/SecurityNotAllowedMethodError.php
deleted file mode 100644
index 93012fe9..00000000
--- a/inc/lib/Twig/Sandbox/SecurityNotAllowedMethodError.php
+++ /dev/null
@@ -1,40 +0,0 @@
-<?php
-
-/*
- * This file is part of Twig.
- *
- * (c) Fabien Potencier
- *
- * For the full copyright and license information, please view the LICENSE
- * file that was distributed with this source code.
- */
-
-/**
- * Exception thrown when a not allowed class method is used in a template.
- *
- * @author Kit Burton-Senior <mail@kitbs.com>
- */
-class Twig_Sandbox_SecurityNotAllowedMethodError extends Twig_Sandbox_SecurityError
-{
- private $className;
- private $methodName;
-
- public function __construct($message, $className, $methodName, $lineno = -1, $filename = null, Exception $previous = null)
- {
- parent::__construct($message, $lineno, $filename, $previous);
- $this->className = $className;
- $this->methodName = $methodName;
- }
-
- public function getClassName()
- {
- return $this->className;
- }
-
- public function getMethodName()
- {
- return $this->methodName;
- }
-}
-
-class_alias('Twig_Sandbox_SecurityNotAllowedMethodError', 'Twig\Sandbox\SecurityNotAllowedMethodError', false);
diff --git a/inc/lib/Twig/Sandbox/SecurityNotAllowedPropertyError.php b/inc/lib/Twig/Sandbox/SecurityNotAllowedPropertyError.php
deleted file mode 100644
index f27969c1..00000000
--- a/inc/lib/Twig/Sandbox/SecurityNotAllowedPropertyError.php
+++ /dev/null
@@ -1,40 +0,0 @@
-<?php
-
-/*
- * This file is part of Twig.
- *
- * (c) Fabien Potencier
- *
- * For the full copyright and license information, please view the LICENSE
- * file that was distributed with this source code.
- */
-
-/**
- * Exception thrown when a not allowed class property is used in a template.
- *
- * @author Kit Burton-Senior <mail@kitbs.com>
- */
-class Twig_Sandbox_SecurityNotAllowedPropertyError extends Twig_Sandbox_SecurityError
-{
- private $className;
- private $propertyName;
-
- public function __construct($message, $className, $propertyName, $lineno = -1, $filename = null, Exception $previous = null)
- {
- parent::__construct($message, $lineno, $filename, $previous);
- $this->className = $className;
- $this->propertyName = $propertyName;
- }
-
- public function getClassName()
- {
- return $this->className;
- }
-
- public function getPropertyName()
- {
- return $this->propertyName;
- }
-}
-
-class_alias('Twig_Sandbox_SecurityNotAllowedPropertyError', 'Twig\Sandbox\SecurityNotAllowedPropertyError', false);
diff --git a/inc/lib/Twig/Sandbox/SecurityNotAllowedTagError.php b/inc/lib/Twig/Sandbox/SecurityNotAllowedTagError.php
deleted file mode 100644
index 4bbd2238..00000000
--- a/inc/lib/Twig/Sandbox/SecurityNotAllowedTagError.php
+++ /dev/null
@@ -1,33 +0,0 @@
-<?php
-
-/*
- * This file is part of Twig.
- *
- * (c) Fabien Potencier
- *
- * For the full copyright and license information, please view the LICENSE
- * file that was distributed with this source code.
- */
-
-/**
- * Exception thrown when a not allowed tag is used in a template.
- *
- * @author Martin Hasoň <martin.hason@gmail.com>
- */
-class Twig_Sandbox_SecurityNotAllowedTagError extends Twig_Sandbox_SecurityError
-{
- private $tagName;
-
- public function __construct($message, $tagName, $lineno = -1, $filename = null, Exception $previous = null)
- {
- parent::__construct($message, $lineno, $filename, $previous);
- $this->tagName = $tagName;
- }
-
- public function getTagName()
- {
- return $this->tagName;
- }
-}
-
-class_alias('Twig_Sandbox_SecurityNotAllowedTagError', 'Twig\Sandbox\SecurityNotAllowedTagError', false);
diff --git a/inc/lib/Twig/Sandbox/SecurityPolicy.php b/inc/lib/Twig/Sandbox/SecurityPolicy.php
deleted file mode 100644
index dca0b82b..00000000
--- a/inc/lib/Twig/Sandbox/SecurityPolicy.php
+++ /dev/null
@@ -1,125 +0,0 @@
-<?php
-
-/*
- * This file is part of Twig.
- *
- * (c) Fabien Potencier
- *
- * For the full copyright and license information, please view the LICENSE
- * file that was distributed with this source code.
- */
-
-/**
- * Represents a security policy which need to be enforced when sandbox mode is enabled.
- *
- * @final
- *
- * @author Fabien Potencier <fabien@symfony.com>
- */
-class Twig_Sandbox_SecurityPolicy implements Twig_Sandbox_SecurityPolicyInterface
-{
- protected $allowedTags;
- protected $allowedFilters;
- protected $allowedMethods;
- protected $allowedProperties;
- protected $allowedFunctions;
-
- public function __construct(array $allowedTags = array(), array $allowedFilters = array(), array $allowedMethods = array(), array $allowedProperties = array(), array $allowedFunctions = array())
- {
- $this->allowedTags = $allowedTags;
- $this->allowedFilters = $allowedFilters;
- $this->setAllowedMethods($allowedMethods);
- $this->allowedProperties = $allowedProperties;
- $this->allowedFunctions = $allowedFunctions;
- }
-
- public function setAllowedTags(array $tags)
- {
- $this->allowedTags = $tags;
- }
-
- public function setAllowedFilters(array $filters)
- {
- $this->allowedFilters = $filters;
- }
-
- public function setAllowedMethods(array $methods)
- {
- $this->allowedMethods = array();
- foreach ($methods as $class => $m) {
- $this->allowedMethods[$class] = array_map('strtolower', is_array($m) ? $m : array($m));
- }
- }
-
- public function setAllowedProperties(array $properties)
- {
- $this->allowedProperties = $properties;
- }
-
- public function setAllowedFunctions(array $functions)
- {
- $this->allowedFunctions = $functions;
- }
-
- public function checkSecurity($tags, $filters, $functions)
- {
- foreach ($tags as $tag) {
- if (!in_array($tag, $this->allowedTags)) {
- throw new Twig_Sandbox_SecurityNotAllowedTagError(sprintf('Tag "%s" is not allowed.', $tag), $tag);
- }
- }
-
- foreach ($filters as $filter) {
- if (!in_array($filter, $this->allowedFilters)) {
- throw new Twig_Sandbox_SecurityNotAllowedFilterError(sprintf('Filter "%s" is not allowed.', $filter), $filter);
- }
- }
-
- foreach ($functions as $function) {
- if (!in_array($function, $this->allowedFunctions)) {
- throw new Twig_Sandbox_SecurityNotAllowedFunctionError(sprintf('Function "%s" is not allowed.', $function), $function);
- }
- }
- }
-
- public function checkMethodAllowed($obj, $method)
- {
- if ($obj instanceof Twig_TemplateInterface || $obj instanceof Twig_Markup) {
- return true;
- }
-
- $allowed = false;
- $method = strtolower($method);
- foreach ($this->allowedMethods as $class => $methods) {
- if ($obj instanceof $class) {
- $allowed = in_array($method, $methods);
-
- break;
- }
- }
-
- if (!$allowed) {
- $class = get_class($obj);
- throw new Twig_Sandbox_SecurityNotAllowedMethodError(sprintf('Calling "%s" method on a "%s" object is not allowed.', $method, $class), $class, $method);
- }
- }
-
- public function checkPropertyAllowed($obj, $property)
- {
- $allowed = false;
- foreach ($this->allowedProperties as $class => $properties) {
- if ($obj instanceof $class) {
- $allowed = in_array($property, is_array($properties) ? $properties : array($properties));
-
- break;
- }
- }
-
- if (!$allowed) {
- $class = get_class($obj);
- throw new Twig_Sandbox_SecurityNotAllowedPropertyError(sprintf('Calling "%s" property on a "%s" object is not allowed.', $property, $class), $class, $property);
- }
- }
-}
-
-class_alias('Twig_Sandbox_SecurityPolicy', 'Twig\Sandbox\SecurityPolicy', false);
diff --git a/inc/lib/Twig/Sandbox/SecurityPolicyInterface.php b/inc/lib/Twig/Sandbox/SecurityPolicyInterface.php
deleted file mode 100644
index 88f64447..00000000
--- a/inc/lib/Twig/Sandbox/SecurityPolicyInterface.php
+++ /dev/null
@@ -1,26 +0,0 @@
-<?php
-
-/*
- * This file is part of Twig.
- *
- * (c) Fabien Potencier
- *
- * For the full copyright and license information, please view the LICENSE
- * file that was distributed with this source code.
- */
-
-/**
- * Interfaces that all security policy classes must implements.
- *
- * @author Fabien Potencier <fabien@symfony.com>
- */
-interface Twig_Sandbox_SecurityPolicyInterface
-{
- public function checkSecurity($tags, $filters, $functions);
-
- public function checkMethodAllowed($obj, $method);
-
- public function checkPropertyAllowed($obj, $method);
-}
-
-class_alias('Twig_Sandbox_SecurityPolicyInterface', 'Twig\Sandbox\SecurityPolicyInterface', false);