-
-
Notifications
You must be signed in to change notification settings - Fork 2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Themes: Added route to serve public theme files
Allows files to be placed within a "public" folder within a theme directory which the contents of will served by BookStack for access. - Only "web safe" content-types are provided. - A static 1 day cache time it set on served files. For #3904
- Loading branch information
1 parent
b975180
commit 593645a
Showing
12 changed files
with
111 additions
and
15 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
<?php | ||
|
||
namespace BookStack\Theming; | ||
|
||
use BookStack\Facades\Theme; | ||
use BookStack\Http\Controller; | ||
use BookStack\Util\FilePathNormalizer; | ||
|
||
class ThemeController extends Controller | ||
{ | ||
/** | ||
* Serve a public file from the configured theme. | ||
*/ | ||
public function publicFile(string $theme, string $path) | ||
{ | ||
$cleanPath = FilePathNormalizer::normalize($path); | ||
if ($theme !== Theme::getTheme() || !$cleanPath) { | ||
abort(404); | ||
} | ||
|
||
$filePath = theme_path("public/{$cleanPath}"); | ||
if (!file_exists($filePath)) { | ||
abort(404); | ||
} | ||
|
||
$response = $this->download()->streamedFileInline($filePath); | ||
$response->setMaxAge(86400); | ||
|
||
return $response; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
<?php | ||
|
||
namespace BookStack\Util; | ||
|
||
use League\Flysystem\WhitespacePathNormalizer; | ||
|
||
/** | ||
* Utility to normalize (potentially) user provided file paths | ||
* to avoid things like directory traversal. | ||
*/ | ||
class FilePathNormalizer | ||
{ | ||
public static function normalize(string $path): string | ||
{ | ||
return (new WhitespacePathNormalizer())->normalizePath($path); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters