Skip to content

A self-hosted media server and file management system

fix: only public class property on singleton path resolver can cause security issues

aminnausinf0d9e80cfced
diff --git a/app/Services/PathResolverService.php b/app/Services/PathResolverService.php
index 128af167..e2071969 100644
--- a/app/Services/PathResolverService.php
+++ b/app/Services/PathResolverService.php
@@ -9,46 +9,39 @@ use Illuminate\Database\Eloquent\Collection;
use Illuminate\Database\Eloquent\ModelNotFoundException;
class PathResolverService {
- private bool $onlyPublic = false;
-
- public function onlyPublic(bool $value = true): self {
- $this->onlyPublic = $value;
-
- return $this;
- }
-
- private function addPrivacyFilter(Builder $query): Builder {
- return $this->onlyPublic
+ private function addPrivacyFilter(Builder $query, bool $onlyPublic): Builder {
+ return $onlyPublic
? $query->where('is_private', false)
: $query;
}
- public function resolveCategory(string $identifier, array $select = ['id', 'name', 'default_folder_id', 'is_private']): Category {
+ public function resolveCategory(string $identifier, bool $onlyPublic = false, array $select = ['id', 'name', 'default_folder_id', 'is_private']): Category {
return $this->firstSuccessful([
- fn () => $this->resolveCategoryByName($identifier, $select),
- fn () => $this->resolveCategoryById($identifier, $select),
+ fn () => $this->resolveCategoryByName($identifier, $select, $onlyPublic),
+ fn () => $this->resolveCategoryById($identifier, $select, $onlyPublic),
], "No category found matching '{$identifier}'");
}
- private function resolveCategoryByName(string $identifier, array $select): ?Category {
- return $this->addPrivacyFilter(Category::query())
+ private function resolveCategoryByName(string $identifier, array $select, bool $onlyPublic): ?Category {
+ return $this->addPrivacyFilter(Category::query(), $onlyPublic)
->select(...$select)->where('name', 'ilike', '%' . $identifier . '%')
->orderByRaw('POSITION(lower(?) in lower(name))', [$identifier])
->first();
}
- private function resolveCategoryById(string $identifier, array $select): ?Category {
+ private function resolveCategoryById(string $identifier, array $select, bool $onlyPublic): ?Category {
if (! ctype_digit($identifier) || (int) $identifier <= 0) {
return null;
}
- return $this->addPrivacyFilter(Category::query())
+ return $this->addPrivacyFilter(Category::query(), $onlyPublic)
->select(...$select)->find((int) $identifier);
}
- public function resolveFolder(string $identifier, Category $category, ?Collection $folders = null): ?Folder {
+ public function resolveFolder(string $identifier, Category $category, ?Collection $folders = null, bool $onlyPublic = false): ?Folder {
if (! $folders) {
- $folders = Folder::with('series')->where('category_id', $category->id)->get();
+ $query = Folder::with('series')->where('category_id', $category->id);
+ $folders = $this->addPrivacyFilter($query, $onlyPublic)->get();
}
return $this->firstSuccessful([
diff --git a/app/Services/PreviewGeneratorService.php b/app/Services/PreviewGeneratorService.php
index 9df3d3be..d2bf329c 100644
--- a/app/Services/PreviewGeneratorService.php
+++ b/app/Services/PreviewGeneratorService.php
@@ -33,7 +33,7 @@ class PreviewGeneratorService {
$folderSlug = $request->route('folderName') ?? '';
$videoId = $request->query('video');
- $category = $this->pathResolver->onlyPublic($request->user()?->id !== 1)->resolveCategory($categorySlug);
+ $category = $this->pathResolver->resolveCategory($categorySlug, $request->user()?->id !== 1);
$folder = $this->pathResolver->resolveFolder(identifier: $folderSlug, category: $category)->load('series');
if ($videoId) {