Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Protect Endpoints bug with Whitelisted and Protected endpoints #14

Closed
psusu opened this issue Nov 8, 2021 · 4 comments
Closed

Protect Endpoints bug with Whitelisted and Protected endpoints #14

psusu opened this issue Nov 8, 2021 · 4 comments
Assignees
Labels
bug Something isn't working

Comments

@psusu
Copy link

psusu commented Nov 8, 2021

Bug Description

Hello!
Trying the new feature Protect Endpoints in the 3.4.0 version I've found a bug with whitelisted or protected endpoints.

I'm working in a subfolder WP install like www.mysite/subfolder
I'm looking in function isEndpointProtected($endpoint) in file ProtectEndpointService.php

The removeWpJsonFromEndpoint function called in lines 82 and 102 strips /wp-json from the strings:
if my string is www.mysite/**subfolder**/wp-json/endpoint the comparison is always wrong

The function removeWpJsonFromEndpoint changes the string in: www.mysite/subfolder/endpoint and on line 91 or 106 this string is compared with strpos() to www.mysite/subfolder/wp-json/endpoint and retrieves a wrong result

Environment

Question Answer
PHP version PHP 7.3
WordPress version 5.8.1
Simple-JWT-Login plugin version 3.4.0
@canonex
Copy link
Contributor

canonex commented Nov 8, 2021

I confirm.

I use apache userdir and my address is:
https://mydomain.net/~me/mywordpress

So, a possible route is
https://mydomain.net/~me/mywordpress/wp-json/xx/v1/endpoint

At this time only the domain is considered and not the siteurl or home as written in the db options.

The comparison fails, as stripping out the wp-json is equal comparing:
~me/mywordpress/wp-json/xx/v1/endpoint
and
~me/mywordpress/xx/v1/endpoint
which is therefore always false.

So I commented out the line:
//$protectedEndpoint = $this->removeWpJsonFromEndpoint($protectedEndpoint);
and inserted in the ui in "Protected endpoints" the complete path
/~me/mywordpress/wp-json/xx/v1/endpoint
and it works correctly.

It would be useful to have the full flow by removing not only the domain but the whole siteurl.
In this way you could simply insert
/wp-json/xx/v1/endpoint

Thank you,
Rickyx

ps. how to retrieve the user id from the authorized endpoint?

@nicumicle nicumicle added the bug Something isn't working label Nov 13, 2021
@nicumicle nicumicle self-assigned this Nov 13, 2021
@nicumicle
Copy link
Owner

Hello @canonex @psusu

I did some fixes for this.

Can you please check on your side and let me know if it is working ok for you?

@nicumicle nicumicle added this to To do in Simple JWT Login Board via automation Nov 13, 2021
@nicumicle nicumicle moved this from To do to QA in Simple JWT Login Board Nov 13, 2021
@canonex
Copy link
Contributor

canonex commented Nov 15, 2021

I'm sorry, I tried several options but I can't figure out what should I write in the Protected endpoints (using Apply only on Specific REST endpoints option) if I want to protect this endpoint:
https://mydomain.net/~me/mywordpress/wp-json/xx/v1/endpoint

Thank you,
Riccardo

@nicumicle
Copy link
Owner

Hello @canonex,

In the protect endpoints, you neet to add

  • /wp-json/xx/v1/endpoint

@canonex canonex mentioned this issue Nov 18, 2021
3 tasks
nicumicle added a commit that referenced this issue Nov 21, 2021
Proposed fix for Protect endpoints issue #14
Simple JWT Login Board automation moved this from QA to Done Nov 21, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
Archived in project
Development

No branches or pull requests

3 participants