Skip to content

Commit 8ace9f8

Browse files
authored
Fix: Prevent phar:// paths from leaking to frontend assets and strictly validate URLs (#7)
1 parent 30079cb commit 8ace9f8

File tree

4 files changed

+11
-6
lines changed

4 files changed

+11
-6
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,3 +9,4 @@ litedocs.phar
99
composer.lock
1010
/bin/litedocs.phar
1111
.php-cs-fixer.cache
12+
box.phar

box.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
"main": "bin/litedocs",
33
"output": "litedocs.phar",
44
"directories": ["src", "config", "vendor"],
5-
"files": ["composer.json", "composer.lock"],
5+
"files": ["composer.json", "composer.lock", "LICENSE", "README.md"],
66
"compression": "GZ",
77
"chmod": "0755"
88
}

src/Core/Kernel.php

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020

2121
class Kernel
2222
{
23-
public const string VERSION = '1.0.3';
23+
public const string VERSION = '1.0.4';
2424

2525
private array $config;
2626

@@ -321,13 +321,17 @@ private function createRedirectPage(string $path, string $target): void
321321

322322
private function processAsset(string $assetPath, string $siteDir, string $rootPath): string
323323
{
324-
if (filter_var($assetPath, FILTER_VALIDATE_URL)) {
324+
// if (filter_var($assetPath, FILTER_VALIDATE_URL)) {
325+
// return $assetPath;
326+
// }
327+
328+
if (str_starts_with($assetPath, 'http://') || str_starts_with($assetPath, 'https://') || str_starts_with($assetPath, '//')) {
325329
return $assetPath;
326330
}
327331

328332
if (!file_exists($assetPath)) {
329-
trigger_error("Asset not found: $assetPath", E_USER_WARNING);
330-
return $assetPath;
333+
trigger_error("Asset not found (excluded from build?): $assetPath", E_USER_WARNING);
334+
return '';
331335
}
332336

333337
$extension = pathinfo($assetPath, PATHINFO_EXTENSION);

src/Resources/themes/lite/assets/css/style.css

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)