|
5 | 5 | use Facades\Statamic\Tokens\Generator; |
6 | 6 | use Illuminate\Support\Carbon; |
7 | 7 | use Illuminate\Support\Collection; |
| 8 | +use PHPUnit\Framework\Attributes\DataProvider; |
8 | 9 | use PHPUnit\Framework\Attributes\Test; |
9 | 10 | use Statamic\Contracts\Tokens\Token; |
10 | 11 | use Statamic\Facades\File; |
@@ -129,6 +130,37 @@ public function attempting_to_find_a_non_existent_token_returns_null() |
129 | 130 | $this->assertNull($this->tokens->find('missing-token')); |
130 | 131 | } |
131 | 132 |
|
| 133 | + #[Test] |
| 134 | + public function it_prevents_path_traversal_in_find() |
| 135 | + { |
| 136 | + File::put(storage_path('statamic/evil.yaml'), "handler: 'Handler'\nexpires_at: 9999999999\ndata: []"); |
| 137 | + |
| 138 | + $this->assertNull($this->tokens->find('../evil')); |
| 139 | + } |
| 140 | + |
| 141 | + #[Test] |
| 142 | + #[DataProvider('invalidTokenNameProvider')] |
| 143 | + public function it_throws_when_making_a_token_with_an_invalid_name($token) |
| 144 | + { |
| 145 | + $this->expectException(\InvalidArgumentException::class); |
| 146 | + |
| 147 | + $this->tokens->make($token, 'Handler'); |
| 148 | + } |
| 149 | + |
| 150 | + public static function invalidTokenNameProvider() |
| 151 | + { |
| 152 | + return [ |
| 153 | + 'parent traversal' => ['../evil'], |
| 154 | + 'backslash traversal' => ['..\\evil'], |
| 155 | + 'nested traversal' => ['foo/../../evil'], |
| 156 | + 'forward slash' => ['foo/evil'], |
| 157 | + 'dots only' => ['..'], |
| 158 | + 'absolute path' => ['/etc/passwd'], |
| 159 | + 'windows drive' => ['C:\\evil'], |
| 160 | + 'trailing newline' => ["evil\n"], |
| 161 | + ]; |
| 162 | + } |
| 163 | + |
132 | 164 | #[Test] |
133 | 165 | public function it_deletes_expired_tokens() |
134 | 166 | { |
|
0 commit comments