mirror of
https://github.com/BookStackApp/BookStack.git
synced 2026-07-15 21:31:36 +03:00
Added a central URLFilter class to check & clean URLs used for attachments, which is also used for validation, and by the purifier to standardise protocols (and to make protocol config easier in future). Thanks to mfk25 for reporting.
30 lines
903 B
PHP
30 lines
903 B
PHP
<?php
|
|
|
|
namespace BookStack\App\Providers;
|
|
|
|
use BookStack\Uploads\ImageService;
|
|
use BookStack\Util\UrlFilter;
|
|
use Illuminate\Support\Facades\Validator;
|
|
use Illuminate\Support\ServiceProvider;
|
|
|
|
class ValidationRuleServiceProvider extends ServiceProvider
|
|
{
|
|
/**
|
|
* Register our custom validation rules when the application boots.
|
|
*/
|
|
public function boot(): void
|
|
{
|
|
Validator::extend('image_extension', function ($attribute, $value, $parameters, $validator) {
|
|
$extension = strtolower($value->getClientOriginalExtension());
|
|
|
|
return ImageService::isExtensionSupported($extension);
|
|
});
|
|
|
|
Validator::extend('safe_url', function ($attribute, $value, $parameters, $validator) {
|
|
$cleanLinkName = strtolower(trim($value));
|
|
$filter = new UrlFilter($cleanLinkName);
|
|
return $filter->isAllowed();
|
|
});
|
|
}
|
|
}
|