feat: force schema
This commit is contained in:
parent
d343dbf6f9
commit
d2c7bce033
@ -2,6 +2,8 @@
|
|||||||
|
|
||||||
namespace App\Providers;
|
namespace App\Providers;
|
||||||
|
|
||||||
|
use Illuminate\Http\Request;
|
||||||
|
use Illuminate\Support\Facades\URL;
|
||||||
use Illuminate\Support\ServiceProvider;
|
use Illuminate\Support\ServiceProvider;
|
||||||
|
|
||||||
class AppServiceProvider extends ServiceProvider
|
class AppServiceProvider extends ServiceProvider
|
||||||
@ -11,7 +13,42 @@ class AppServiceProvider extends ServiceProvider
|
|||||||
*/
|
*/
|
||||||
public function register(): void
|
public function register(): void
|
||||||
{
|
{
|
||||||
//
|
URL::macro(
|
||||||
|
'alternateHasCorrectSignature',
|
||||||
|
function (Request $request, $absolute = true, array $ignoreQuery = []) {
|
||||||
|
$ignoreQuery[] = 'signature';
|
||||||
|
|
||||||
|
$absoluteUrl = url($request->path());
|
||||||
|
$url = $absolute ? $absoluteUrl : '/'.$request->path();
|
||||||
|
|
||||||
|
$queryString = collect(explode('&', (string) $request
|
||||||
|
->server->get('QUERY_STRING')))
|
||||||
|
->reject(fn ($parameter) => in_array(str()->before($parameter, '='), $ignoreQuery))
|
||||||
|
->join('&');
|
||||||
|
|
||||||
|
$original = rtrim($url.'?'.$queryString, '?');
|
||||||
|
|
||||||
|
// Use the application key as the HMAC key
|
||||||
|
$key = config('app.key'); // Ensure app.key is properly set in .env
|
||||||
|
|
||||||
|
if (empty($key)) {
|
||||||
|
throw new \RuntimeException('Application key is not set.');
|
||||||
|
}
|
||||||
|
|
||||||
|
$signature = hash_hmac('sha256', $original, $key);
|
||||||
|
|
||||||
|
return hash_equals($signature, (string) $request->query('signature', ''));
|
||||||
|
}
|
||||||
|
);
|
||||||
|
|
||||||
|
URL::macro('alternateHasValidSignature', function (Request $request, $absolute = true, array $ignoreQuery = []) {
|
||||||
|
return URL::alternateHasCorrectSignature($request, $absolute, $ignoreQuery)
|
||||||
|
&& URL::signatureHasNotExpired($request);
|
||||||
|
});
|
||||||
|
|
||||||
|
Request::macro('hasValidSignature', function ($absolute = true, array $ignoreQuery = []) {
|
||||||
|
return URL::alternateHasValidSignature($this, $absolute, $ignoreQuery);
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -19,6 +56,8 @@ public function register(): void
|
|||||||
*/
|
*/
|
||||||
public function boot(): void
|
public function boot(): void
|
||||||
{
|
{
|
||||||
//
|
if (! app()->environment('local')) {
|
||||||
|
URL::forceScheme('https');
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user