Skip to content
Merged
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
6 changes: 6 additions & 0 deletions src/Route/UI/Http/Responses/PublicDirectoryIndexRedirect.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,12 @@ public static function for(Request $request, string $publicPath): ?RedirectRespo
return null;
}

// The content folders answer the site's 404 on purpose (see the
// skeleton's .htaccess): redirecting would tell a visitor they exist
if (preg_match('#^/(cms/wp-content|content)(/|$)#', $path) === 1) {
return null;
}

$root = realpath($publicPath);
$directory = realpath($publicPath.$path);

Expand Down
6 changes: 6 additions & 0 deletions tests/Unit/Route/PublicDirectoryIndexRedirectTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,10 @@
$this->public = sys_get_temp_dir().'/pollora-public-'.bin2hex(random_bytes(6));
mkdir($this->public.'/cms/wp-admin', 0777, true);
mkdir($this->public.'/cms/empty', 0777, true);
mkdir($this->public.'/cms/wp-content/plugins', 0777, true);
mkdir($this->public.'/content/plugins', 0777, true);
touch($this->public.'/cms/wp-content/plugins/index.php');
touch($this->public.'/content/plugins/index.php');
touch($this->public.'/index.php');
touch($this->public.'/cms/wp-admin/index.php');
touch($this->public.'/cms/wp-login.php');
Expand Down Expand Up @@ -40,6 +44,8 @@
'the root' => '/',
'a WordPress page' => '/sample-page/',
'outside public' => '/../',
'WordPress content folder' => '/cms/wp-content/plugins/',
'content folder' => '/content/plugins/',
]);

it('only redirects reads', function (): void {
Expand Down
Loading