Skip to content

Commit 1e87181

Browse files
Fix CVE-2021-43808 issue in laravel/framework
1 parent 822fb85 commit 1e87181

File tree

4 files changed

+441
-0
lines changed

4 files changed

+441
-0
lines changed

composer.json

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -140,6 +140,9 @@
140140
"Illuminate\\Cache\\Console\\": "overrides/laravel/framework/src/Illuminate/Cache/Console/",
141141
"Dotenv\\": "overrides/vlucas/phpdotenv/src/",
142142
"Illuminate\\View\\": "overrides/laravel/framework/src/Illuminate/View/",
143+
"Illuminate\\View\\Compilers\\": "overrides/laravel/framework/src/Illuminate/View/Compilers/",
144+
"Illuminate\\View\\Compilers\\Concerns\\": "overrides/laravel/framework/src/Illuminate/View/Compilers/Concerns/",
145+
"Illuminate\\View\\Concerns\\": "overrides/laravel/framework/src/Illuminate/View/Concerns/",
143146
"Symfony\\Component\\Routing\\": "overrides/symfony/routing/",
144147
"Symfony\\Component\\VarDumper\\Cloner\\": "overrides/symfony/var-dumper/Cloner/",
145148
"Symfony\\Component\\VarDumper\\Dumper\\": "overrides/symfony/var-dumper/Dumper/",
@@ -252,6 +255,9 @@
252255
"vendor/laravel/framework/src/Illuminate/Cache/Console/ClearCommand.php",
253256
"vendor/vlucas/phpdotenv/src/Loader.php",
254257
"vendor/laravel/framework/src/Illuminate/View/View.php",
258+
"vendor/laravel/framework/src/Illuminate/View/Compilers/Compiler.php",
259+
"vendor/laravel/framework/src/Illuminate/View/Compilers/Concerns/CompilesLayouts.php",
260+
"vendor/laravel/framework/src/Illuminate/View/Concerns/ManagesLayouts.php",
255261
"vendor/symfony/routing/Route.php",
256262
"vendor/symfony/routing/CompiledRoute.php",
257263
"vendor/symfony/var-dumper/Cloner/Data.php",
Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
<?php
2+
3+
namespace Illuminate\View\Compilers;
4+
5+
use InvalidArgumentException;
6+
use Illuminate\Filesystem\Filesystem;
7+
8+
abstract class Compiler
9+
{
10+
/**
11+
* The Filesystem instance.
12+
*
13+
* @var \Illuminate\Filesystem\Filesystem
14+
*/
15+
protected $files;
16+
17+
/**
18+
* Get the cache path for the compiled views.
19+
*
20+
* @var string
21+
*/
22+
protected $cachePath;
23+
24+
/**
25+
* Create a new compiler instance.
26+
*
27+
* @param \Illuminate\Filesystem\Filesystem $files
28+
* @param string $cachePath
29+
* @return void
30+
*
31+
* @throws \InvalidArgumentException
32+
*/
33+
public function __construct(Filesystem $files, $cachePath)
34+
{
35+
if (! $cachePath) {
36+
throw new InvalidArgumentException('Please provide a valid cache path.');
37+
}
38+
39+
$this->files = $files;
40+
$this->cachePath = $cachePath;
41+
}
42+
43+
/**
44+
* Get the path to the compiled version of a view.
45+
*
46+
* @param string $path
47+
* @return string
48+
*/
49+
public function getCompiledPath($path)
50+
{
51+
return $this->cachePath.'/'.sha1('v2'.$path).'.php';
52+
}
53+
54+
/**
55+
* Determine if the view at the given path is expired.
56+
*
57+
* @param string $path
58+
* @return bool
59+
*/
60+
public function isExpired($path)
61+
{
62+
$compiled = $this->getCompiledPath($path);
63+
64+
// If the compiled file doesn't exist we will indicate that the view is expired
65+
// so that it can be re-compiled. Else, we will verify the last modification
66+
// of the views is less than the modification times of the compiled views.
67+
if (! $this->files->exists($compiled)) {
68+
return true;
69+
}
70+
71+
return $this->files->lastModified($path) >=
72+
$this->files->lastModified($compiled);
73+
}
74+
}
Lines changed: 118 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,118 @@
1+
<?php
2+
3+
namespace Illuminate\View\Compilers\Concerns;
4+
5+
trait CompilesLayouts
6+
{
7+
/**
8+
* The name of the last section that was started.
9+
*
10+
* @var string
11+
*/
12+
protected $lastSection;
13+
14+
/**
15+
* Compile the extends statements into valid PHP.
16+
*
17+
* @param string $expression
18+
* @return string
19+
*/
20+
protected function compileExtends($expression)
21+
{
22+
$expression = $this->stripParentheses($expression);
23+
24+
$echo = "<?php echo \$__env->make({$expression}, array_except(get_defined_vars(), array('__data', '__path')))->render(); ?>";
25+
26+
$this->footer[] = $echo;
27+
28+
return '';
29+
}
30+
31+
/**
32+
* Compile the section statements into valid PHP.
33+
*
34+
* @param string $expression
35+
* @return string
36+
*/
37+
protected function compileSection($expression)
38+
{
39+
$this->lastSection = trim($expression, "()'\" ");
40+
41+
return "<?php \$__env->startSection{$expression}; ?>";
42+
}
43+
44+
/**
45+
* Replace the @parent directive to a placeholder.
46+
*
47+
* @return string
48+
*/
49+
protected function compileParent()
50+
{
51+
//return ViewFactory::parentPlaceholder($this->lastSection ?: '');
52+
53+
$escapedLastSection = strtr($this->lastSection, ['\\' => '\\\\', "'" => "\\'"]);
54+
55+
return "<?php echo \Illuminate\View\Factory::parentPlaceholder('{$escapedLastSection}'); ?>";
56+
}
57+
58+
/**
59+
* Compile the yield statements into valid PHP.
60+
*
61+
* @param string $expression
62+
* @return string
63+
*/
64+
protected function compileYield($expression)
65+
{
66+
return "<?php echo \$__env->yieldContent{$expression}; ?>";
67+
}
68+
69+
/**
70+
* Compile the show statements into valid PHP.
71+
*
72+
* @return string
73+
*/
74+
protected function compileShow()
75+
{
76+
return '<?php echo $__env->yieldSection(); ?>';
77+
}
78+
79+
/**
80+
* Compile the append statements into valid PHP.
81+
*
82+
* @return string
83+
*/
84+
protected function compileAppend()
85+
{
86+
return '<?php $__env->appendSection(); ?>';
87+
}
88+
89+
/**
90+
* Compile the overwrite statements into valid PHP.
91+
*
92+
* @return string
93+
*/
94+
protected function compileOverwrite()
95+
{
96+
return '<?php $__env->stopSection(true); ?>';
97+
}
98+
99+
/**
100+
* Compile the stop statements into valid PHP.
101+
*
102+
* @return string
103+
*/
104+
protected function compileStop()
105+
{
106+
return '<?php $__env->stopSection(); ?>';
107+
}
108+
109+
/**
110+
* Compile the end-section statements into valid PHP.
111+
*
112+
* @return string
113+
*/
114+
protected function compileEndsection()
115+
{
116+
return '<?php $__env->stopSection(); ?>';
117+
}
118+
}

0 commit comments

Comments
 (0)