mirror of
https://github.com/archtechx/tenancy.git
synced 2026-02-05 05:14:03 +00:00
Controller action for path-identified assets
This commit is contained in:
parent
e351a68f6f
commit
a3a0320fb4
1 changed files with 22 additions and 0 deletions
|
|
@ -26,4 +26,26 @@ class TenantAssetsController extends Controller
|
||||||
abort(404);
|
abort(404);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function assetWithPath($path = null)
|
||||||
|
{
|
||||||
|
abort_if($path === null, 404);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Prevents path traversal attack in asset requests
|
||||||
|
*
|
||||||
|
* @see https://www.stackhawk.com/blog/laravel-path-traversal-guide-examples-and-prevention/
|
||||||
|
*/
|
||||||
|
$basePath = storage_path("app/public");
|
||||||
|
$requestPath = realpath($basePath . '/' . $path);
|
||||||
|
|
||||||
|
$validPath = substr($requestPath, 0, strlen($basePath)) === $basePath;
|
||||||
|
abort_if($validPath === false, 404);
|
||||||
|
|
||||||
|
try {
|
||||||
|
return response()->file($requestPath);
|
||||||
|
} catch (Throwable $th) {
|
||||||
|
abort(404);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue