1
0
Fork 0
mirror of https://github.com/archtechx/tenancy.git synced 2026-02-04 19:24:02 +00:00

Controller action for path-identified assets

This commit is contained in:
Craig Riley 2023-06-11 01:32:26 +01:00 committed by GitHub
parent e351a68f6f
commit a3a0320fb4
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -26,4 +26,26 @@ class TenantAssetsController extends Controller
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);
}
}
}