@@ -176,6 +176,56 @@ function(): HttpRequest {
176176 fn () => new HttpRequest ($ this ->configuration , HttpClient::CONTEXT_GENERIC_CLIENT , 'get ' , '/ ' . uniqid ())
177177]]);
178178
179+ it ('rejects file paths with protocol separators ' , function (): void {
180+ $ client = new HttpRequest ($ this ->configuration , HttpClient::CONTEXT_GENERIC_CLIENT , 'post ' , '/ ' );
181+
182+ expect (fn () => $ client ->addFile ('test ' , 'file:///etc/passwd ' ))
183+ ->toThrow (\InvalidArgumentException::class, 'File paths with protocol separators ("://") are not allowed: "file:///etc/passwd" ' );
184+
185+ expect (fn () => $ client ->addFile ('test ' , 'http://example.com/file.txt ' ))
186+ ->toThrow (\InvalidArgumentException::class, 'File paths with protocol separators ("://") are not allowed: "http://example.com/file.txt" ' );
187+
188+ expect (fn () => $ client ->addFile ('test ' , 'php://filter/convert.base64-encode/resource=/etc/passwd ' ))
189+ ->toThrow (\InvalidArgumentException::class, 'File paths with protocol separators ("://") are not allowed: "php://filter/convert.base64-encode/resource=/etc/passwd" ' );
190+ });
191+
192+ it ('rejects file paths for non-existent or unreadable files ' , function (): void {
193+ $ client = new HttpRequest ($ this ->configuration , HttpClient::CONTEXT_GENERIC_CLIENT , 'post ' , '/ ' );
194+
195+ // Non-existent file
196+ expect (fn () => $ client ->addFile ('test ' , '/non/existent/file.txt ' ))
197+ ->toThrow (\InvalidArgumentException::class, 'The file "/non/existent/file.txt" does not exist. ' );
198+
199+ // Create a temp file with no read permissions to test unreadable file
200+ $ tempFile = sys_get_temp_dir () . '/ ' . uniqid ('auth0_test_ ' );
201+ file_put_contents ($ tempFile , 'test content ' );
202+ chmod ($ tempFile , 0000 ); // Remove all permissions
203+
204+ try {
205+ expect (fn () => $ client ->addFile ('test ' , $ tempFile ))
206+ ->toThrow (\InvalidArgumentException::class);
207+ } finally {
208+ chmod ($ tempFile , 0666 ); // Restore permissions so we can delete it
209+ @unlink ($ tempFile );
210+ }
211+ });
212+
213+ it ('allows valid local file paths ' , function (): void {
214+ $ client = new HttpRequest ($ this ->configuration , HttpClient::CONTEXT_GENERIC_CLIENT , 'post ' , '/ ' );
215+
216+ // Create a temporary file that exists and is readable
217+ $ tempFile = sys_get_temp_dir () . '/ ' . uniqid ('auth0_test_ ' );
218+ file_put_contents ($ tempFile , 'test content ' );
219+
220+ try {
221+ // This should not throw an exception
222+ $ result = $ client ->addFile ('test ' , $ tempFile );
223+ expect ($ result )->toBeInstanceOf (HttpRequest::class);
224+ } finally {
225+ @unlink ($ tempFile );
226+ }
227+ });
228+
179229it ('throws a NetworkException when the underlying client raises a ClientExceptionInterface ' , function (HttpRequest $ client ): void {
180230 $ client ->call ();
181231})->with (['mocked client ' => [
0 commit comments