Skip to content

Commit 00dc79f

Browse files
authored
Fix security issues (#1782)
1 parent 8f4884e commit 00dc79f

File tree

1 file changed

+2
-2
lines changed

1 file changed

+2
-2
lines changed

resources/server/router.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525
$isIndex = null;
2626
$mediaSubtypeText = ['javascript', 'xml', 'json', 'ld+json', 'csv'];
2727

28-
$path = urldecode(parse_url($_SERVER['REQUEST_URI'], PHP_URL_PATH));
28+
$path = htmlspecialchars(urldecode(parse_url($_SERVER['REQUEST_URI'], PHP_URL_PATH)));
2929

3030
// watcher (called by 'livereload.js')
3131
if ($path == '/watcher') {
@@ -50,7 +50,7 @@
5050
$filename = $_SERVER['DOCUMENT_ROOT'] . $path;
5151

5252
// HTTP response: 404
53-
if (!file_exists($filename) || is_dir($filename)) {
53+
if ((realpath($filename) === false || strpos(realpath($filename), realpath($_SERVER['DOCUMENT_ROOT'])) !== 0) || !file_exists($filename) || is_dir($filename)) {
5454
http_response_code(404);
5555
// favicon.ico
5656
if ($path == '/favicon.ico') {

0 commit comments

Comments
 (0)