Skip to content

Commit

Permalink
security-fix: check if the selected file resides in any of log dirs b…
Browse files Browse the repository at this point in the history
…efore displaying its contents
  • Loading branch information
saade committed May 17, 2024
1 parent 735180b commit b6355b9
Showing 1 changed file with 12 additions and 9 deletions.
21 changes: 12 additions & 9 deletions src/Pages/ViewLog.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,25 +41,22 @@ public function form(Form $form): Form

public function read(): string
{
if (! $this->logFile) {
if (! $this->logFile || ! $this->fileResidesInLogDirs($this->logFile)) {
$this->logFile = null;
return '';
}

return File::get($this->logFile);
}

public function write($content = ''): void
public function clear(): void
{
if (! $this->logFile) {
if (! $this->logFile || ! $this->fileResidesInLogDirs($this->logFile)) {
$this->logFile = null;
return;
}

File::put($this->logFile, $content);
}

public function clear(): void
{
$this->write();
File::put($this->logFile, '');
$this->refresh();
}

Expand All @@ -68,6 +65,12 @@ public function refresh(): void
$this->dispatch('logContentUpdated', content: $this->read());
}

protected function fileResidesInLogDirs(string $logFile): bool
{
return collect(FilamentLaravelLogPlugin::get()->getLogDirs())
->contains(fn (string $logDir) => str_contains($logFile, $logDir));
}

protected function getFinder(): Finder
{
return Finder::create()
Expand Down

0 comments on commit b6355b9

Please sign in to comment.