Beautiful Open-Source Form Builder
Refactor JWT authentication middleware to remove IP validation and update comments
JhumanJ053ef6c2f1b2
diff --git a/api/app/Http/Middleware/AuthenticateJWT.php b/api/app/Http/Middleware/AuthenticateJWT.phpindex b0ac579e4..d5427e97a 100644--- a/api/app/Http/Middleware/AuthenticateJWT.php+++ b/api/app/Http/Middleware/AuthenticateJWT.php@@ -11,12 +11,12 @@ class AuthenticateJWTpublic const API_SERVER_SECRET_HEADER_NAME = 'x-api-secret';/**- * Verifies the JWT token and validates the IP and User Agent- * Invalidates token otherwise+ * Verifies the JWT token and validates the User Agent.+ * Invalidates token otherwise.*/public function handle(Request $request, Closure $next){- // If skipping IP and UA validation is enabled in config, skip the rest+ // If skipping JWT client fingerprint validation is enabled in config, skip the restif (config('app.jwt_skip_ip_ua_validation')) {return $next($request);}@@ -28,7 +28,7 @@ class AuthenticateJWTreturn $next($request);}- // Validate IP and User Agent+ // Validate User Agentif ($payload) {if ($frontApiSecret = $request->header(self::API_SERVER_SECRET_HEADER_NAME)) {// If it's a trusted SSR request, skip the rest@@ -43,10 +43,6 @@ class AuthenticateJWT}$error = null;- if (! \Hash::check($request->ip(), $payload->get('ip'))) {- $error = 'Origin IP is invalid';- }-if (! \Hash::check($request->userAgent(), $payload->get('ua'))) {$error = 'Origin User Agent is invalid';}diff --git a/api/app/Models/User.php b/api/app/Models/User.phpindex 4ba914557..6c552ca1c 100644--- a/api/app/Models/User.php+++ b/api/app/Models/User.php@@ -353,7 +353,6 @@ class User extends Authenticatable implements JWTSubject, CachableAttributes, Twpublic function getJWTCustomClaims(){return [- 'ip' => Hash::make(request()->ip()),'ua' => Hash::make(request()->userAgent()),];}