Skip to content

Commit

Permalink
[huntr] adding cache control headers to the admin area (#3097)
Browse files Browse the repository at this point in the history
This PR forces the `Cache-Control: no-store, max-age=0` header to the response in the Admin Area. This forces cache to be ignored upon browsing back and forth between pages using the browser controls. Although absolutely no fail safe, it should provide better protection against serving cached pages once an admin has signed out.
  • Loading branch information
luceos committed Oct 7, 2021
1 parent 2b47e90 commit b4772e5
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 1 deletion.
3 changes: 2 additions & 1 deletion src/Admin/AdminServiceProvider.php
Expand Up @@ -61,7 +61,8 @@ public function register()
HttpMiddleware\CheckCsrfToken::class,
Middleware\RequireAdministrateAbility::class,
HttpMiddleware\ReferrerPolicyHeader::class,
HttpMiddleware\ContentTypeOptionsHeader::class
HttpMiddleware\ContentTypeOptionsHeader::class,
Middleware\DisableBrowserCache::class,
];
});

Expand Down
25 changes: 25 additions & 0 deletions src/Admin/Middleware/DisableBrowserCache.php
@@ -0,0 +1,25 @@
<?php

/*
* This file is part of Flarum.
*
* For detailed copyright and license information, please view the
* LICENSE file that was distributed with this source code.
*/

namespace Flarum\Admin\Middleware;

use Psr\Http\Message\ResponseInterface as Response;
use Psr\Http\Message\ServerRequestInterface as Request;
use Psr\Http\Server\MiddlewareInterface as Middleware;
use Psr\Http\Server\RequestHandlerInterface as Handler;

class DisableBrowserCache implements Middleware
{
public function process(Request $request, Handler $handler): Response
{
$response = $handler->handle($request);

return $response->withHeader('Cache-Control', 'max-age=0, no-store');
}
}

0 comments on commit b4772e5

Please sign in to comment.