Skip to content

Commit

Permalink
prevent access of wiki files
Browse files Browse the repository at this point in the history
This prevents the crawler to descent into the wiki directory or data
directory, even when for some reason a higher up directory was made
accessible. This should prevent the circumvention of ACLs and prevent
access to sensitive data like user password hashes etc.
  • Loading branch information
splitbrain committed Apr 3, 2024
1 parent 55e6f8f commit e82754c
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 0 deletions.
3 changes: 3 additions & 0 deletions Crawler.php
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,9 @@ public function crawl($root, $local, $pattern, $recursive, $titlefile)
{
$path = $root . $local;

// do not descent into wiki or data directories
if(Path::isWikiControlled($path)) return [];

if (($dir = opendir($path)) === false) return [];
$result = [];
while (($file = readdir($dir)) !== false) {
Expand Down
22 changes: 22 additions & 0 deletions Path.php
Original file line number Diff line number Diff line change
Expand Up @@ -149,4 +149,26 @@ public static function realpath($path)
}
return implode('/', $output);
}

/**
* Check if the given path is within the data or dokuwiki dir
*
* This whould prevent accidental or deliberate circumvention of the ACLs
*
* @param string $path and already cleaned path
* @return bool
*/
public static function isWikiControlled($path)
{
global $conf;
$dataPath = self::cleanPath($conf['savedir']);
if (str_starts_with($path, $dataPath)) {
return true;
}
$wikiDir = self::cleanPath(DOKU_INC);
if (str_starts_with($path, $wikiDir)) {
return true;
}
return false;
}
}
4 changes: 4 additions & 0 deletions file.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,10 @@

try {
$pathInfo = $pathUtil->getPathInfo($path, false);
if ($pathUtil::isWikiControlled($pathInfo['path'])) {
throw new Exception('Access to wiki files is not allowed');
}

if (!is_readable($pathInfo['path'])) {
header('Content-Type: text/plain');
http_status(404);
Expand Down

0 comments on commit e82754c

Please sign in to comment.