Skip to content

Commit

Permalink
fix: ancestor header issue fix - allowing all domain iframe src embed
Browse files Browse the repository at this point in the history
  • Loading branch information
CS76 committed Jan 4, 2024
1 parent 9cefeb3 commit ef7f306
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 14 deletions.
16 changes: 2 additions & 14 deletions app/Http/Middleware/XFrameOptions.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,22 +17,10 @@ public function handle(Request $request, Closure $next): Response
{
$response = $next($request);

$option = 'SAMEORIGIN';

if ($request->route()->getName() == 'embed') {
$xframeOptions = env('X_FRAME_OPTIONS', $option);
if ($xframeOptions) {
$host = $request->getHttpHost();
$xframeOptions = str_replace('*', $host, $xframeOptions);
if (strpos($xframeOptions, 'ALLOW-FROM') !== false) {
$url = trim(str_replace('ALLOW-FROM', '', $xframeOptions));
$response->header('Content-Security-Policy', 'frame-ancestors '.$url);
}
}
} else {
$xframeOptions = $option;
$response->header('Content-Security-Policy', 'frame-ancestors frame-src data: blob: *');
}

return $response->header('X-Frame-Options', $xframeOptions);
return $response;
}
}
1 change: 1 addition & 0 deletions resources/ops/docker/nginx/vhost.conf
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ server {

client_max_body_size 200m;

add_header X-Frame-Options "SAMEORIGIN";
add_header X-XSS-Protection "1; mode=block";
add_header X-Content-Type-Options "nosniff";

Expand Down

0 comments on commit ef7f306

Please sign in to comment.