Apply fixes from StyleCI

This commit is contained in:
StyleCI Bot 2023-10-11 10:14:38 +00:00
parent 6fb043e109
commit 2b8580727f
No known key found for this signature in database
GPG Key ID: E4A5316DFBB23575
3 changed files with 34 additions and 33 deletions

View File

@ -23,12 +23,9 @@ use CachetHQ\Cachet\Models\Meta;
use CachetHQ\Cachet\Services\Dates\DateFactory; use CachetHQ\Cachet\Services\Dates\DateFactory;
use Carbon\Carbon; use Carbon\Carbon;
use Illuminate\Contracts\Auth\Guard; use Illuminate\Contracts\Auth\Guard;
use Twig\Environment as Twig_Environment; use Twig\Environment as Twig_Environment;
use Twig\Loader\ArrayLoader as Twig_Loader_Array; use Twig\Loader\ArrayLoader as Twig_Loader_Array;
/** /**
* This is the create incident command handler. * This is the create incident command handler.
* *
@ -67,7 +64,7 @@ class CreateIncidentCommandHandler
$this->auth = $auth; $this->auth = $auth;
$this->dates = $dates; $this->dates = $dates;
$this->twigConfig = config("cachet.twig"); $this->twigConfig = config('cachet.twig');
} }
/** /**
@ -138,31 +135,34 @@ class CreateIncidentCommandHandler
return $incident; return $incident;
} }
protected function sandboxedTwigTemplateData(String $templateData) { protected function sandboxedTwigTemplateData(string $templateData)
{
if (!$templateData) { if (!$templateData) {
return ""; return '';
} }
$policy = new \Twig\Sandbox\SecurityPolicy($this->twigConfig["tags"], $policy = new \Twig\Sandbox\SecurityPolicy(
$this->twigConfig["filters"], $this->twigConfig['tags'],
$this->twigConfig["methods"], $this->twigConfig['filters'],
$this->twigConfig["props"], $this->twigConfig['methods'],
$this->twigConfig["functions"]); $this->twigConfig['props'],
$this->twigConfig['functions']
);
$sandbox = new \Twig\Extension\SandboxExtension($policy); $sandbox = new \Twig\Extension\SandboxExtension($policy);
$templateBasicLoader = new Twig_Loader_Array([ $templateBasicLoader = new Twig_Loader_Array([
'firstStageLoader' => $templateData 'firstStageLoader' => $templateData,
]); ]);
$sandBoxBasicLoader = new Twig_Loader_Array([ $sandBoxBasicLoader = new Twig_Loader_Array([
'secondStageLoader' => '{% sandbox %}{% include "firstStageLoader" %} {% endsandbox %}' 'secondStageLoader' => '{% sandbox %}{% include "firstStageLoader" %} {% endsandbox %}',
]); ]);
$hardenedLoader = new \Twig\Loader\ChainLoader([$templateBasicLoader, $sandBoxBasicLoader]); $hardenedLoader = new \Twig\Loader\ChainLoader([$templateBasicLoader, $sandBoxBasicLoader]);
$twig = new Twig_Environment($hardenedLoader); $twig = new Twig_Environment($hardenedLoader);
$twig->addExtension($sandbox); $twig->addExtension($sandbox);
return $twig; return $twig;
} }

View File

@ -21,8 +21,6 @@ use CachetHQ\Cachet\Models\Incident;
use CachetHQ\Cachet\Models\IncidentTemplate; use CachetHQ\Cachet\Models\IncidentTemplate;
use CachetHQ\Cachet\Services\Dates\DateFactory; use CachetHQ\Cachet\Services\Dates\DateFactory;
use Illuminate\Contracts\Auth\Guard; use Illuminate\Contracts\Auth\Guard;
use Twig\Environment as Twig_Environment;
use Twig\Loader\ArrayLoader as Twig_Loader_Array;
/** /**
* This is the update incident command handler. * This is the update incident command handler.
@ -65,7 +63,7 @@ class UpdateIncidentCommandHandler
$this->auth = $auth; $this->auth = $auth;
$this->dates = $dates; $this->dates = $dates;
$this->twigConfig = $twigConfig = config("cachet.twig"); $this->twigConfig = $twigConfig = config('cachet.twig');
} }
/** /**
@ -147,25 +145,29 @@ class UpdateIncidentCommandHandler
}); });
} }
protected function sandboxedTwigTemplateData(String $templateData) { protected function sandboxedTwigTemplateData(string $templateData)
$policy = new \Twig\Sandbox\SecurityPolicy($this->twigConfig["tags"], {
$this->twigConfig["filters"], $policy = new \Twig\Sandbox\SecurityPolicy(
$this->twigConfig["methods"], $this->twigConfig['tags'],
$this->twigConfig["props"], $this->twigConfig['filters'],
$this->twigConfig["functions"]); $this->twigConfig['methods'],
$this->twigConfig['props'],
$this->twigConfig['functions']
);
$sandbox = new \Twig\Extension\SandboxExtension($policy); $sandbox = new \Twig\Extension\SandboxExtension($policy);
$templateBasicLoader = new \Twig\Loader\ArrayLoader([ $templateBasicLoader = new \Twig\Loader\ArrayLoader([
'firstStageLoader' => $templateData 'firstStageLoader' => $templateData,
]); ]);
$sandBoxBasicLoader = new \Twig\Loader\ArrayLoader([ $sandBoxBasicLoader = new \Twig\Loader\ArrayLoader([
'secondStageLoader' => '{% sandbox %}{% include "firstStageLoader" %} {% endsandbox %}' 'secondStageLoader' => '{% sandbox %}{% include "firstStageLoader" %} {% endsandbox %}',
]); ]);
$hardenedLoader = new \Twig\Loader\ChainLoader([$templateBasicLoader, $sandBoxBasicLoader]); $hardenedLoader = new \Twig\Loader\ChainLoader([$templateBasicLoader, $sandBoxBasicLoader]);
$twig = new \Twig\Environment($hardenedLoader); $twig = new \Twig\Environment($hardenedLoader);
$twig->addExtension($sandbox); $twig->addExtension($sandbox);
return $twig; return $twig;
} }

View File

@ -46,7 +46,6 @@ return [
'beacon' => env('CACHET_BEACON', true), 'beacon' => env('CACHET_BEACON', true),
/* /*
|-------------------------------------------------------------------------- |--------------------------------------------------------------------------
| Templates configurations | Templates configurations
@ -58,10 +57,10 @@ return [
| |
*/ */
'twig' => [ 'twig' => [
'methods' => [], 'methods' => [],
'functions' => [], 'functions' => [],
'filters' => ['escape'], 'filters' => ['escape'],
'tags' => ['if'], 'tags' => ['if'],
'props' => [], 'props' => [],
] ],
]; ];