File tree Expand file tree Collapse file tree 3 files changed +58
-1
lines changed
Expand file tree Collapse file tree 3 files changed +58
-1
lines changed Original file line number Diff line number Diff line change @@ -28,7 +28,7 @@ class Kernel extends HttpKernel
2828 \BookStack \Http \Middleware \ApplyCspRules::class,
2929 \BookStack \Http \Middleware \EncryptCookies::class,
3030 \Illuminate \Cookie \Middleware \AddQueuedCookiesToResponse::class,
31- \Illuminate \ Session \Middleware \StartSession ::class,
31+ \BookStack \ Http \Middleware \StartSessionExtended ::class,
3232 \Illuminate \View \Middleware \ShareErrorsFromSession::class,
3333 \BookStack \Http \Middleware \VerifyCsrfToken::class,
3434 \BookStack \Http \Middleware \CheckEmailConfirmed::class,
Original file line number Diff line number Diff line change 1+ <?php
2+
3+ namespace BookStack \Http \Middleware ;
4+
5+ use Illuminate \Http \Request ;
6+ use Illuminate \Session \Middleware \StartSession as Middleware ;
7+
8+ /**
9+ * An extended version of the default Laravel "StartSession" middleware
10+ * with customizations applied as required:
11+ *
12+ * - Adds filtering for the request URLs stored in session history.
13+ */
14+ class StartSessionExtended extends Middleware
15+ {
16+ protected static array $ pathPrefixesExcludedFromHistory = [
17+ 'uploads/images/ '
18+ ];
19+
20+ /**
21+ * @inheritdoc
22+ */
23+ protected function storeCurrentUrl (Request $ request , $ session ): void
24+ {
25+ $ requestPath = strtolower ($ request ->path ());
26+ foreach (static ::$ pathPrefixesExcludedFromHistory as $ excludedPath ) {
27+ if (str_starts_with ($ requestPath , $ excludedPath )) {
28+ return ;
29+ }
30+ }
31+
32+ parent ::storeCurrentUrl ($ request , $ session );
33+ }
34+ }
Original file line number Diff line number Diff line change @@ -383,6 +383,29 @@ public function test_system_images_remain_public_with_local_secure()
383383 }
384384 }
385385
386+ public function test_secure_images_not_tracked_in_session_history ()
387+ {
388+ config ()->set ('filesystems.images ' , 'local_secure ' );
389+ $ this ->asEditor ();
390+ $ page = $ this ->entities ->page ();
391+ $ result = $ this ->files ->uploadGalleryImageToPage ($ this , $ page );
392+ $ expectedPath = storage_path ($ result ['path ' ]);
393+ $ this ->assertFileExists ($ expectedPath );
394+
395+ $ this ->get ('/books ' );
396+ $ this ->assertEquals (url ('/books ' ), session ()->previousUrl ());
397+
398+ $ resp = $ this ->get ($ result ['path ' ]);
399+ $ resp ->assertOk ();
400+ $ resp ->assertHeader ('Content-Type ' , 'image/png ' );
401+
402+ $ this ->assertEquals (url ('/books ' ), session ()->previousUrl ());
403+
404+ if (file_exists ($ expectedPath )) {
405+ unlink ($ expectedPath );
406+ }
407+ }
408+
386409 public function test_system_images_remain_public_with_local_secure_restricted ()
387410 {
388411 config ()->set ('filesystems.images ' , 'local_secure_restricted ' );
You can’t perform that action at this time.
0 commit comments