Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix path traversal on Laravel 10 #686

Merged
merged 1 commit into from
Jun 30, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 6 additions & 7 deletions src/Writing/Writer.php
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,7 @@ protected function performFinalTasksForLaravelType(): void
if (!is_dir($this->laravelTypeOutputPath)) {
mkdir($this->laravelTypeOutputPath, 0777, true);
}
$publicDirectory = app()->get('path.public');
$publicDirectory = public_path();
if (!is_dir($publicDirectory . $this->laravelAssetsPath)) {
mkdir($publicDirectory . $this->laravelAssetsPath, 0777, true);
}
Expand All @@ -180,8 +180,8 @@ protected function performFinalTasksForLaravelType(): void
// Rewrite asset links to go through Laravel
$contents = preg_replace('#href="\.\./docs/css/(.+?)"#', 'href="{{ asset("' . $this->laravelAssetsPath . '/css/$1") }}"', $contents);
$contents = preg_replace('#src="\.\./docs/(js|images)/(.+?)"#', 'src="{{ asset("' . $this->laravelAssetsPath . '/$1/$2") }}"', $contents);
$contents = str_replace('href="../docs/collection.json"', 'href="{{ route("'.$this->docsName.'.postman") }}"', $contents);
$contents = str_replace('href="../docs/openapi.yaml"', 'href="{{ route("'.$this->docsName.'.openapi") }}"', $contents);
$contents = str_replace('href="../docs/collection.json"', 'href="{{ route("' . $this->docsName . '.postman") }}"', $contents);
$contents = str_replace('href="../docs/openapi.yaml"', 'href="{{ route("' . $this->docsName . '.openapi") }}"', $contents);

file_put_contents("$this->laravelTypeOutputPath/index.blade.php", $contents);
}
Expand All @@ -206,9 +206,9 @@ public function writeHtmlDocs(array $groupedEndpoints): void
$assetsOutputPath = $outputPath;
} else {
$outputPath = rtrim($this->laravelTypeOutputPath, '/') . '/';
c::success("Wrote Blade docs to: ". $this->makePathFriendly($outputPath));
c::success("Wrote Blade docs to: " . $this->makePathFriendly($outputPath));
$this->generatedFiles['blade'] = realpath("{$outputPath}index.blade.php");
$assetsOutputPath = app()->get('path.public') . $this->laravelAssetsPath . '/';
$assetsOutputPath = public_path() . $this->laravelAssetsPath . '/';
c::success("Wrote Laravel assets to: " . $this->makePathFriendly($assetsOutputPath));
}
$this->generatedFiles['assets']['js'] = realpath("{$assetsOutputPath}js");
Expand All @@ -228,7 +228,7 @@ protected function getLaravelTypeOutputPath(): ?string
{
if ($this->isStatic) return null;

return config('view.paths.0', function_exists('base_path') ? base_path("resources/views") : "resources/views")."/$this->docsName";
return config('view.paths.0', function_exists('base_path') ? base_path("resources/views") : "resources/views") . "/$this->docsName";
}

/**
Expand All @@ -241,5 +241,4 @@ protected function makePathFriendly(string $path): string
{
return str_replace("\\", "/", str_replace(getcwd() . DIRECTORY_SEPARATOR, "", $path));
}

}