Skip to content

Commit

Permalink
Merge pull request #33 from utilewebsites/master
Browse files Browse the repository at this point in the history
Fix origin denied issue by trimming trailing slash from APP_URL and H…
  • Loading branch information
murdercode authored Jan 22, 2025
2 parents e093609 + ce6c0cf commit a990350
Showing 1 changed file with 7 additions and 5 deletions.
12 changes: 7 additions & 5 deletions src/Http/Middleware/TinymceMiddleware.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,17 +22,19 @@ public function handle($request, Closure $next)
/**
* Check if the request coming from the same origin
*/
$accepted_origins = [config('app.url')];
if (isset($_SERVER['HTTP_ORIGIN'])) {
if (in_array($_SERVER['HTTP_ORIGIN'], $accepted_origins)) {
header('Access-Control-Allow-Origin: '.$_SERVER['HTTP_ORIGIN']);
$accepted_origins = [rtrim(config('app.url'), '/')];
$origin = rtrim($_SERVER['HTTP_ORIGIN'], '/');

if (isset($origin)) {

Check failure on line 28 in src/Http/Middleware/TinymceMiddleware.php

View workflow job for this annotation

GitHub Actions / phpstan

Variable $origin in isset() always exists and is not nullable.
if (in_array($origin, $accepted_origins)) {
header('Access-Control-Allow-Origin: ' . $origin);
} else {
header('HTTP/1.1 403 Origin Denied');

return response()->json(['error' => 'Origin denied']);
}
}


return $next($request);
}
}

0 comments on commit a990350

Please sign in to comment.