File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 22
33namespace Statamic \Dictionaries ;
44
5+ use League \Flysystem \PathTraversalDetected ;
56use Statamic \Facades \Antlers ;
67use Statamic \Facades \YAML ;
78
@@ -55,7 +56,13 @@ protected function getItemLabel(array $item): string
5556
5657 protected function getItems (): array
5758 {
58- $ path = resource_path ('dictionaries ' ).'/ ' .$ this ->config ['filename ' ];
59+ $ filename = $ this ->config ['filename ' ];
60+
61+ if (str_contains ($ filename , '.. ' )) {
62+ throw PathTraversalDetected::forPath ($ filename );
63+ }
64+
65+ $ path = resource_path ('dictionaries/ ' .$ filename );
5966
6067 if (! file_exists ($ path )) {
6168 throw new \Exception ('Dictionary file [ ' .$ path .'] does not exist. ' );
Original file line number Diff line number Diff line change @@ -245,8 +245,13 @@ public function process($data)
245245 $ id = $ this ->createTermFromString ($ id , $ taxonomy );
246246 }
247247
248+ if (! $ id ) {
249+ return null ;
250+ }
251+
248252 return explode (':: ' , $ id , 2 )[1 ];
249253 })
254+ ->filter ()
250255 ->unique ()
251256 ->values ()
252257 ->all ();
@@ -498,9 +503,15 @@ protected function createTermFromString($string, $taxonomy)
498503 $ slug = Str::slug ($ string , '- ' , $ lang );
499504
500505 if (! $ term = Facades \Term::find ("{$ taxonomy }:: {$ slug }" )) {
506+ $ taxonomy = Facades \Taxonomy::findByHandle ($ taxonomy );
507+
508+ if (User::current ()->cant ('create ' , [TermContract::class, $ taxonomy ])) {
509+ return null ;
510+ }
511+
501512 $ term = Facades \Term::make ()
502513 ->slug ($ slug )
503- ->taxonomy (Facades \Taxonomy:: findByHandle ( $ taxonomy) )
514+ ->taxonomy ($ taxonomy )
504515 ->set ('title ' , $ string );
505516
506517 $ term ->save ();
Original file line number Diff line number Diff line change 22
33namespace Tests \Dictionaries ;
44
5+ use League \Flysystem \PathTraversalDetected ;
56use PHPUnit \Framework \Attributes \DataProvider ;
67use PHPUnit \Framework \Attributes \Test ;
78use Statamic \Dictionaries \File ;
@@ -180,4 +181,15 @@ public function it_gets_array_from_value()
180181 'emoji ' => '🍌 ' ,
181182 ], $ item ->data ());
182183 }
184+
185+ #[Test]
186+ public function path_traversal_not_allowed ()
187+ {
188+ $ this ->expectException (PathTraversalDetected::class);
189+ $ this ->expectExceptionMessage ('Path traversal detected: ../secret.json ' );
190+
191+ (new File )
192+ ->setConfig (['filename ' => '../secret.json ' ])
193+ ->options ();
194+ }
183195}
You can’t perform that action at this time.
0 commit comments