Skip to content

Commit

Permalink
Fix MakeViewVariableOptionalSolution to disallow stream wrappers and …
Browse files Browse the repository at this point in the history
…files that do not end in .blade.php

This is already fixed in 2.5.2, See facade#334

I could not update to 2.5.2 due to some dependent package required php 7.3, currently clients site is running in php 7.2

On branch 2.4.1-branch
Changes to be committed:
	modified:   src/Solutions/MakeViewVariableOptionalSolution.php
  • Loading branch information
anasmirza534 committed Feb 18, 2021
1 parent 9fc6c3d commit 11ffca1
Showing 1 changed file with 18 additions and 0 deletions.
18 changes: 18 additions & 0 deletions src/Solutions/MakeViewVariableOptionalSolution.php
Expand Up @@ -4,6 +4,7 @@

use Facade\IgnitionContracts\RunnableSolution;
use Illuminate\Support\Facades\Blade;
use Illuminate\Support\Str;

class MakeViewVariableOptionalSolution implements RunnableSolution
{
Expand Down Expand Up @@ -70,8 +71,25 @@ public function run(array $parameters = [])
}
}

protected function isSafePath(string $path): bool
{
if (!Str::startsWith($path, ['/', './'])) {
return false;
}

if (!Str::endsWith($path, '.blade.php')) {
return false;
}

return true;
}

public function makeOptional(array $parameters = [])
{
if (!$this->isSafePath($parameters['viewFile'])) {
return false;
}

$originalContents = file_get_contents($parameters['viewFile']);
$newContents = str_replace('$'.$parameters['variableName'], '$'.$parameters['variableName']." ?? ''", $originalContents);

Expand Down

0 comments on commit 11ffca1

Please sign in to comment.