mirror of
https://github.com/getgrav/grav.git
synced 2025-11-02 11:26:02 +01:00
Fixed path traversal vulnerability when using bin/grav server
This commit is contained in:
@@ -6,6 +6,7 @@
|
|||||||
* Added `route` and `request` to `onPagesInitialized` event
|
* Added `route` and `request` to `onPagesInitialized` event
|
||||||
* Improved page cloning, added method `Page::initialize()`
|
* Improved page cloning, added method `Page::initialize()`
|
||||||
2. [](#bugfix)
|
2. [](#bugfix)
|
||||||
|
* Fixed path traversal vulnerability when using `bin/grav server`
|
||||||
* Fixed unescaped error messages in JSON error responses
|
* Fixed unescaped error messages in JSON error responses
|
||||||
* Fixed `|t(variable)` twig filter in admin
|
* Fixed `|t(variable)` twig filter in admin
|
||||||
|
|
||||||
|
|||||||
@@ -13,8 +13,25 @@ if (PHP_SAPI !== 'cli-server') {
|
|||||||
|
|
||||||
$_SERVER['PHP_CLI_ROUTER'] = true;
|
$_SERVER['PHP_CLI_ROUTER'] = true;
|
||||||
|
|
||||||
if (is_file($_SERVER['DOCUMENT_ROOT'] . DIRECTORY_SEPARATOR . $_SERVER['SCRIPT_NAME'])) {
|
$root = $_SERVER['DOCUMENT_ROOT'];
|
||||||
return false;
|
$path = $_SERVER['SCRIPT_NAME'];
|
||||||
|
if ($path !== '/index.php' && is_file($root . $path)) {
|
||||||
|
if (!(
|
||||||
|
// Block all direct access to files and folders beginning with a dot
|
||||||
|
strpos($path, '/.') !== false
|
||||||
|
// Block all direct access for these folders
|
||||||
|
|| preg_match('`^/(\.git|cache|bin|logs|backup|webserver-configs|tests)/`ui', $path)
|
||||||
|
// Block access to specific file types for these system folders
|
||||||
|
|| preg_match('`^/(system|vendor)/(.*)\.(txt|xml|md|html|yaml|yml|php|pl|py|cgi|twig|sh|bat)$`ui', $path)
|
||||||
|
// Block access to specific file types for these user folders
|
||||||
|
|| preg_match('`^/(user)/(.*)\.(txt|md|yaml|yml|php|pl|py|cgi|twig|sh|bat)$`ui', $path)
|
||||||
|
// Block all direct access to .md files
|
||||||
|
|| preg_match('`\.md$`ui', $path)
|
||||||
|
// Block access to specific files in the root folder
|
||||||
|
|| preg_match('`^/(LICENSE\.txt|composer\.lock|composer\.json|\.htaccess)$`ui', $path)
|
||||||
|
)) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
$grav_index = 'index.php';
|
$grav_index = 'index.php';
|
||||||
|
|||||||
Reference in New Issue
Block a user