You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I have an custom endpoint registered via register_rest_route and protected via "Protected endpoints", configured via "Apply only on specific REST endpoints.
Internally, this API makes an invocation to a separate API using the WP rest_do_request to request some rest API results, and it is invoking a REST endpoint not protected with "Protected endpoints"
Expected results:
The invocation works well: the JWT is validated, the API runs and the internal rest_do_request succeeds
Current results:
Invoking the API results in a 502 bad gateway response
What I've tried to confirm this is a bug:
If I remove the rest_do_request call from the API implementation, the API request starts working well
If I disable protected endpoints and do requests unauthenticated, the API request starts working well
What I've done to confirm why this happens:
Debugging this a bit, it seems like the code in routes/api.php is being invoked twice: first for the API call, which validates the JWT token successfully, but the invocation of rest_do_request internally calls this again, and the invocation of hasAccess fails.
Potential fix:
If I edit ProtectEndpointService.php and make sure that hasAccess checks if the user is already logged in and returns true in line 40, the API starts to work well while authenticated, so it is clear that this is the code path causing the issue. Basically, move the code in line 61 up.
Please let me know your thoughts both on this issue and the potential fix (proposed or other) to make this scenario work well.
Thanks in advance!
The text was updated successfully, but these errors were encountered:
Bug Report
Plugin Version
3.5.6
PHP Version
8.1.29
WordPress Version
6.6.1
Bug description
Expected results:
The invocation works well: the JWT is validated, the API runs and the internal rest_do_request succeeds
Current results:
Invoking the API results in a 502 bad gateway response
What I've tried to confirm this is a bug:
What I've done to confirm why this happens:
Debugging this a bit, it seems like the code in routes/api.php is being invoked twice: first for the API call, which validates the JWT token successfully, but the invocation of rest_do_request internally calls this again, and the invocation of hasAccess fails.
Potential fix:
If I edit ProtectEndpointService.php and make sure that hasAccess checks if the user is already logged in and returns true in line 40, the API starts to work well while authenticated, so it is clear that this is the code path causing the issue. Basically, move the code in line 61 up.
Please let me know your thoughts both on this issue and the potential fix (proposed or other) to make this scenario work well.
Thanks in advance!
The text was updated successfully, but these errors were encountered: