use BookStack\Exceptions\HttpFetchException;
+/**
+ * Validate the host we're connecting to when making a server-side-request.
+ * Will use the given hosts config if given during construction otherwise
+ * will look to the app configured config.
+ */
class SsrUrlValidator
{
protected string $config;
- public function __construct(string $config = null)
+ public function __construct(?string $config = null)
{
$this->config = $config ?? config('app.ssr_hosts') ?? '';
}
protected function urlMatchesPattern($url, $pattern): bool
{
- $pattern = trim($pattern);
+ $pattern = rtrim(trim($pattern), '/');
$url = trim($url);
if (empty($pattern) || empty($url)) {
$quoted = preg_quote($pattern, '/');
$regexPattern = str_replace('\*', '.*', $quoted);
- return preg_match('/^' . $regexPattern . '.*$/i', $url);
+ return preg_match('/^' . $regexPattern . '($|\/.*$|#.*$)/i', $url);
}
/**