WordPress REST API Authentication Test đŸ›Ąī¸

This page tests how your browser interacts with a WordPress REST API endpoint when you might be logged into WordPress in another tab. WordPress often uses cookies for authentication.

Your WordPress site should have the following HTTP headers for this test to be fully illustrative regarding credentials:


Test 1: Attempting an Unauthenticated Request đŸ•ĩī¸â€â™€ī¸

This test uses fetch with credentials: 'omit'. This tells the browser not to send any cookies (like WordPress login cookies) with the request, even if Access-Control-Allow-Credentials: true is set on the server. You should not see your logged-in user details.

Test results will appear here.

Test 2: Attempting an Authenticated Request (If Logged In) đŸĒ

This test uses fetch with credentials: 'include'. If you are logged into WordPress in another tab on the same browser, and your WordPress site has Access-Control-Allow-Credentials: true, this request will send your authentication cookies. You should see your user details if you are logged in and the site is configured to allow credentialed cross-origin requests.

âš ī¸ If this shows your user details, it means JavaScript from other origins (if allowed by Access-Control-Allow-Origin) can make authenticated requests to your WordPress site if you are logged in. This is expected behavior with these settings but highlights the importance of controlling which origins are allowed.

Test results will appear here.

Explanation of Results 📝

Key Takeaway: To prevent inadvertent authenticated requests from JavaScript on other domains, you would typically avoid Access-Control-Allow-Credentials: true or be very restrictive with Access-Control-Allow-Origin. If you must use both, be aware that any script on an allowed origin can make requests as the logged-in user.

For unauthenticated requests from your own JavaScript (even on the same domain, but especially cross-origin), explicitly use credentials: 'omit' with fetch for clarity and to ensure no cookies are sent. WordPress REST API also often uses nonces for write operations to protect against CSRF attacks, which is a separate but related security measure.