Plugin Directory

Changeset 3462956


Ignore:
Timestamp:
02/16/2026 10:26:07 PM (4 days ago)
Author:
gkanters
Message:

Fix frontend batch-strings 403 on cached pages by allowing anonymous same-site requests when inline nonce is stale; keep referer/origin validation and existing rate limiting.

Location:
ai-translate
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • ai-translate/tags/2.2.8/ai-translate.php

    r3462708 r3462956  
    12351235                return true;
    12361236            }
     1237
     1238            // Public frontend pages can be heavily cached, causing stale inline nonces.
     1239            // Allow anonymous same-site requests without requiring a valid nonce.
     1240            if (!is_user_logged_in()) {
     1241                $origin = isset($_SERVER['HTTP_ORIGIN']) ? (string) $_SERVER['HTTP_ORIGIN'] : '';
     1242                if ($origin !== '' && strpos($origin, home_url()) !== 0) {
     1243                    return new \WP_Error('rest_forbidden', 'Invalid origin', ['status' => 403]);
     1244                }
     1245                return true;
     1246            }
     1247
    12371248            return new \WP_Error('rest_forbidden', 'Invalid nonce', ['status' => 403]);
    12381249        },
  • ai-translate/trunk/ai-translate.php

    r3462699 r3462956  
    12351235                return true;
    12361236            }
     1237
     1238            // Public frontend pages can be heavily cached, causing stale inline nonces.
     1239            // Allow anonymous same-site requests without requiring a valid nonce.
     1240            if (!is_user_logged_in()) {
     1241                $origin = isset($_SERVER['HTTP_ORIGIN']) ? (string) $_SERVER['HTTP_ORIGIN'] : '';
     1242                if ($origin !== '' && strpos($origin, home_url()) !== 0) {
     1243                    return new \WP_Error('rest_forbidden', 'Invalid origin', ['status' => 403]);
     1244                }
     1245                return true;
     1246            }
     1247
    12371248            return new \WP_Error('rest_forbidden', 'Invalid nonce', ['status' => 403]);
    12381249        },
Note: See TracChangeset for help on using the changeset viewer.