Skip to content

Commit 49df478

Browse files
authored
Merge pull request #6057 from BookStackApp/v25-12
V25.12 changes v3
2 parents 60a3b0c + 5f5fea7 commit 49df478

File tree

5 files changed

+202
-121
lines changed

5 files changed

+202
-121
lines changed

app/Entities/Controllers/PageRevisionController.php

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@
1212
use BookStack\Facades\Activity;
1313
use BookStack\Http\Controller;
1414
use BookStack\Permissions\Permission;
15+
use BookStack\Util\HtmlContentFilter;
16+
use BookStack\Util\HtmlContentFilterConfig;
1517
use BookStack\Util\SimpleListOptions;
1618
use Illuminate\Http\Request;
1719
use Ssddanbrown\HtmlDiff\Diff;
@@ -101,12 +103,15 @@ public function changes(string $bookSlug, string $pageSlug, int $revisionId)
101103

102104
$prev = $revision->getPreviousRevision();
103105
$prevContent = $prev->html ?? '';
104-
$diff = Diff::excecute($prevContent, $revision->html);
106+
107+
// TODO - Refactor PageContent so we can de-dupe these steps
108+
$rawDiff = Diff::excecute($prevContent, $revision->html);
109+
$filterConfig = HtmlContentFilterConfig::fromConfigString(config('app.content_filtering'));
110+
$filter = new HtmlContentFilter($filterConfig);
111+
$diff = $filter->filterString($rawDiff);
105112

106113
$page->fill($revision->toArray());
107-
// TODO - Refactor PageContent so we don't need to juggle this
108-
$page->html = $revision->html;
109-
$page->html = (new PageContent($page))->render();
114+
$page->html = '';
110115
$this->setPageTitle(trans('entities.pages_revision_named', ['pageName' => $page->getShortName()]));
111116

112117
return view('pages.revision', [

app/Http/Controller.php

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -167,14 +167,26 @@ protected function getImageValidationRules(): array
167167

168168
/**
169169
* Redirect to the URL provided in the request as a '_return' parameter.
170-
* Will check that the parameter leads to a URL under the root path of the system.
170+
* Will check that the parameter leads to a URL under the same origin as the application.
171171
*/
172172
protected function redirectToRequest(Request $request): RedirectResponse
173173
{
174174
$basePath = url('/');
175175
$returnUrl = $request->input('_return') ?? $basePath;
176176

177-
if (!str_starts_with($returnUrl, $basePath)) {
177+
// Only allow use of _return on requests where we expect CSRF to be active
178+
// to prevent it potentially being used as an open redirect
179+
$allowedMethods = ['POST', 'PUT', 'PATCH', 'DELETE'];
180+
if (!in_array($request->getMethod(), $allowedMethods)) {
181+
return redirect($basePath);
182+
}
183+
184+
$intendedUrl = parse_url($returnUrl);
185+
$baseUrl = parse_url($basePath);
186+
$isSameOrigin = ($intendedUrl['host'] ?? '') === ($baseUrl['host'] ?? '')
187+
&& ($intendedUrl['scheme'] ?? '') === ($baseUrl['scheme'] ?? '')
188+
&& ($intendedUrl['port'] ?? 0) === ($baseUrl['port'] ?? 0);
189+
if (!$isSameOrigin) {
178190
return redirect($basePath);
179191
}
180192

0 commit comments

Comments
 (0)