Skip to content

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.php
index b0ac579e4..d5427e97a 100644
--- a/api/app/Http/Middleware/AuthenticateJWT.php
+++ b/api/app/Http/Middleware/AuthenticateJWT.php
@@ -11,12 +11,12 @@ class AuthenticateJWT
public 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 rest
if (config('app.jwt_skip_ip_ua_validation')) {
return $next($request);
}
@@ -28,7 +28,7 @@ class AuthenticateJWT
return $next($request);
}
- // Validate IP and User Agent
+ // Validate User Agent
if ($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.php
index 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, Tw
public function getJWTCustomClaims()
{
return [
- 'ip' => Hash::make(request()->ip()),
'ua' => Hash::make(request()->userAgent()),
];
}