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 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