-
-
Notifications
You must be signed in to change notification settings - Fork 316
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* disable csp when query for docs/api --------- Co-authored-by: Benoît Viguier <ildyria@users.noreply.github.com> Co-authored-by: Martin Stone <1611702+d7415@users.noreply.github.com>
- Loading branch information
1 parent
82681d7
commit 055d4e1
Showing
4 changed files
with
54 additions
and
11 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
<?php | ||
|
||
namespace App\Http\Middleware; | ||
|
||
use App\Contracts\Exceptions\LycheeException; | ||
use Illuminate\Http\Request; | ||
|
||
/** | ||
* Class DisableCSP. | ||
* | ||
* This middleware disables the CSP when needed. | ||
* This ensures that some external dependencies are loaded for e.g. | ||
* docs/api or log-viewer | ||
*/ | ||
class DisableCSP | ||
{ | ||
/** | ||
* Handles an incoming request. | ||
* | ||
* @param Request $request the incoming request to serve | ||
* @param \Closure $next the next operation to be applied to the | ||
* request | ||
* | ||
* @return mixed | ||
* | ||
* @throws LycheeException | ||
*/ | ||
public function handle(Request $request, \Closure $next): mixed | ||
{ | ||
if ( | ||
config('debugbar.enabled', false) === true || | ||
$request->getRequestUri() === '/docs/api' | ||
) { | ||
config(['secure-headers.csp.enable' => false]); | ||
} | ||
|
||
if ($request->getRequestUri() === '/' . config('log-viewer.route_path', 'Logs')) { | ||
// We must disable unsafe-eval because vue3 used by log-viewer requires it. | ||
// We must disable unsafe-inline (and hashes) because log-viewer uses inline script with parameter to boot. | ||
// Those parameters are not know by Lychee if someone modifies the config. | ||
// We only do that in that specific case. It is disabled by default otherwise. | ||
config(['secure-headers.csp.script-src.unsafe-eval' => true]); | ||
config(['secure-headers.csp.script-src.unsafe-inline' => true]); | ||
config(['secure-headers.csp.script-src.hashes.sha256' => []]); | ||
} | ||
|
||
return $next($request); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters