Skip to content

Improve self-hosted sites login #3819

Closed
daniloercoli wants to merge 29 commits intodevelopfrom
feature/3805-improve-self-hosted-login-internals
Closed

Improve self-hosted sites login #3819
daniloercoli wants to merge 29 commits intodevelopfrom
feature/3805-improve-self-hosted-login-internals

Conversation

@daniloercoli
Copy link
Copy Markdown
Contributor

Fix #3805 by providing an enhanced version of the XML-RPC discovery procedure and some other nice things ;)

  • This PR also checks that the found endpoint does have the basic XML-RPC methods required by the app. (We may want to extended the list if necessary).
  • The Bad Behavior plugins matching is ready, but moved in the future folder. If you feel confident in keeping the BB plugins list updated (wordpress-mobile/app-blocking-plugins) feel free to put it back in production.
    The Bad Behavior matching seems to be solid, since the "main" logic behind it was taken from wpscan, but I didn't test it too much. In the end it is just a series of tests upon HTTP response codes returned by the external web server.
  • Also added a new Analytics event LOGIN_INSERTED_INVALID_URL (login_inserted_invalid_url), that has 1 property attached to it user_inserted_url, that keep tracks of how many invalid URLs we receive in the login screen. I've not added it to Mixpanel Should I?

cc @oguzkocer @hypest @SergioEstevao @bummytime @astralbodies

…ss-Android into feature/3805-improve-self-hosted-login-internals
Fixed a bunch of other issues along the way.
…ss-Android into feature/3805-improve-self-hosted-login-internals
@hypest
Copy link
Copy Markdown
Contributor

hypest commented Mar 4, 2016

I'm planning to extend the work done here by extracting the cross-platform flows into testable chunks.

}

private boolean isHTTPAuthErrorMessage(Exception e) {
if (e != null && e.getMessage() != null && e.getMessage().contains("401")) {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe we can just return this since we are not doing anything else in the if statement anymore.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Right. I've removed the unnecessary code.

String baseURL = getBaseURL(mOriginalURL);

if (!baseURL.contains("/plugins")) {
baseURL = baseURL + "/wp-content/plugins/";
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This might be a stupid question as I don't know how this class is going to be used, but is there any way the url contains /wp-content but not /plugins?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please ignore the above question, I found my answer in getBaseUrl, sorry about that!

}

int respCode = openConnection(baseURL);
if (respCode != HttpURLConnection.HTTP_OK && respCode != 401 && respCode != 403) {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am a bit confused here, what do we do if the error code is 401 or 403 for example? These cases don't seem to be handled later.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

OK, I have an idea. Is this just checking if we can access the server even if it's an unauthorized connection? If so, then this makes sense. However, wouldn't that cause the next call we are going to make to check if a plugin exists return error as well? I really don't know much about how self-hosted installations work, so I might be way off in my assumptions.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We need to check wether the http://domain/wp-content/plugins/ address is available on internet or not. If the HTTP response code in [200, 401, 403] means that the folder is available on the server. If the response is != from one of the codes above, we can safely assume that the folder is not there.
Note that the routine is just an heuristic, and we can't be 100% sure the folder is there.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

note2: Assuming that the folder is NOT there is not a problem, since the plugins check is just skipped. This minimize false positive.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the clarification. It's pretty convoluted.

@oguzkocer
Copy link
Copy Markdown
Contributor

@daniloercoli I've completed my review and left a few comments/questions. This is a complicated PR for me to take alone, so getting another set of eyes (more experienced ones) would be good.

Are there any testing instructions I can follow?

@daniloercoli
Copy link
Copy Markdown
Contributor Author

@oguzkocer I fixed the issues you've brought up during review.
We've a list of self-hosted sites, might make sense to try the new login on them.
I've tested the patch locally, by messing up with a local installation of WP.

Hint for reviewers: The best way to review all the login flow is to start looking at FetchBlogListWPOrg.getSelfHostedXmlrpcUrl and follow the flow from there. Looking at the diff could be hard to follow the new logic.

…ss-Android into feature/3805-improve-self-hosted-login-internals

# Conflicts:
#	WordPress/src/main/java/org/xmlrpc/android/ApiHelper.java
…after a SSLHanshakeException on self hosted sites. Props @hypest
…ted a valid URL on the UI, but WordPress is missconfigured and returns an invalid URL in the apiLink field in the RSD document.
@daniloercoli
Copy link
Copy Markdown
Contributor Author

Closing this PR since #3853 includes the changes added here, and adds Unit Tests.

@maxme maxme deleted the feature/3805-improve-self-hosted-login-internals branch March 23, 2016 14:16
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants