Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion docs/guide/connect-browser.md
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ An explicit `connect($endpoint, $options)` call uses the supplied endpoint and o
For example, start a Playwright 1.64.1 server with its matching browser image:

```bash
docker run --rm --init --ipc=host -p 3000:3000 \
docker run --rm --init --ipc=host -p 127.0.0.1:3000:3000 \
--workdir /home/pwuser --user pwuser \
mcr.microsoft.com/playwright:v1.64.1-noble \
/bin/sh -c "npx -y playwright@1.64.1 run-server --port 3000 --host 0.0.0.0"
Expand Down
5 changes: 3 additions & 2 deletions tests/Fixtures/server.php
Original file line number Diff line number Diff line change
Expand Up @@ -91,10 +91,11 @@
}

// Construct file path
$file = __DIR__.'/html'.$uri;
$root = realpath(__DIR__.'/html');
$file = realpath(__DIR__.'/html'.rawurldecode($uri));

// Serve static file if it exists
if (file_exists($file) && is_file($file)) {
if (is_string($root) && is_string($file) && str_starts_with($file, $root.DIRECTORY_SEPARATOR) && is_file($file)) {
// Determine content type
$extension = strtolower(pathinfo($file, PATHINFO_EXTENSION));
$contentTypes = [
Expand Down
50 changes: 50 additions & 0 deletions tests/Unit/FixtureRouterTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
<?php

declare(strict_types=1);

/*
* This file is part of the community-maintained Playwright PHP project.
* It is not affiliated with or endorsed by Microsoft.
*
* (c) 2025-Present - Playwright PHP - https://github.com/playwright-php
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/

namespace Playwright\Tests\Unit;

use PHPUnit\Framework\Attributes\CoversNothing;
use PHPUnit\Framework\Attributes\DataProvider;
use PHPUnit\Framework\TestCase;
use Symfony\Component\Process\Process;

#[CoversNothing]
final class FixtureRouterTest extends TestCase
{
#[DataProvider('pathsOutsideTheFixtureRoot')]
public function testStaticPathsStayWithinTheFixtureRoot(string $uri): void
{
$process = new Process([PHP_BINARY, '-r', '$_SERVER["REQUEST_URI"] = $argv[1]; include $argv[2];', $uri, dirname(__DIR__).'/Fixtures/server.php']);
$process->mustRun();

$this->assertStringContainsString('404 Not Found', $process->getOutput());
$this->assertStringNotContainsString('readfile($file)', $process->getOutput());
}

/** @return iterable<string, array{string}> */
public static function pathsOutsideTheFixtureRoot(): iterable
{
yield 'raw parent' => ['/../server.php'];
yield 'encoded parent' => ['/%2e%2e/server.php'];
yield 'encoded separator' => ['/%2e%2e%2fserver.php'];
}

public function testKnownStaticFilesStillLoad(): void
{
$process = new Process([PHP_BINARY, '-r', '$_SERVER["REQUEST_URI"] = "/index.html"; include $argv[1];', dirname(__DIR__).'/Fixtures/server.php']);
$process->mustRun();

$this->assertSame(file_get_contents(dirname(__DIR__).'/Fixtures/html/index.html'), $process->getOutput());
}
}
Loading