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

Update basic auth cache to key off of origin instead of url #13281

Merged
merged 4 commits into from Sep 16, 2016

Conversation

@gilbertw1
Copy link
Contributor

gilbertw1 commented Sep 15, 2016

This pull request's primary purpose is to store basic auth credentials based on the url origin instead of the entire url. This fixes an issue where servo continuously prompts the user for credentials any time a basic auth secured resource is requested even though the user has already entered auth credentials for a different resource from the same origin.

The test associated with this PR hides image redirects behind a python handler that requires basic authentication. The reference page loads two images by directly specifying the image to load, while the test page loads the two images using the basic auth redirect handler with only the first image tag providing auth credentials.

I'd like to point a few specific items for review:

  • url::Origin does not derive Hash, so I am using ascii_serialization as the cache key. This seems like a stable enough representation.
  • I've updated the http loader to store credentials not only on Success responses, but Redirect responses as well. I stumbled on this because nginx was redirecting 'test' -> 'test/' in my testing, and other browsers were storing the credentials on the redirect response vs. prompting for credentials a second time.
  • In the test I'm using a timeout to load the second image (without authentication), otherwise the order that the images were loaded was unpredictable.

  • ./mach build -d does not report any errors
  • ./mach test-tidy does not report any errors related to these changes
  • These changes fix #12095 (github issue number if applicable).
  • There are tests for these changes OR
  • These changes do not require tests because _____

This change is Reviewable

@highfive
Copy link

highfive commented Sep 15, 2016

Thanks for the pull request, and welcome! The Servo team is excited to review your changes, and you should hear from @Ms2ger (or someone else) soon.

@highfive
Copy link

highfive commented Sep 15, 2016

Heads up! This PR modifies the following files:

  • @KiChjang: components/net/fetch/methods.rs, components/net/resource_thread.rs, components/net/http_loader.rs
Copy link
Member

jdm left a comment

This looks really great! There's only one change we can make to ensure that the new test is robust against timing changes.

<script type="text/javascript">
var authImg = '<img src="http://testuser:testpass@' + window.location.host + '/http/resources/securedimage.py">';
document.getElementById('auth').innerHTML = authImg;
setTimeout(function() {

This comment has been minimized.

@jdm

jdm Sep 15, 2016

Member

Rather than a timeout (which could cause intermittent failures if the first image finishes loading before the timeout fires), we should:

  • add class="reftest-wait" to the <html> element
  • add an onload handler to the first image, which starts the second image load
  • add an onload handler to the second load which removes the reftest-wait class

This comment has been minimized.

@gilbertw1

gilbertw1 Sep 15, 2016

Author Contributor

Thanks for the feedback! I've just incorporated the test changes in a new commit.

@bors-servo
Copy link
Contributor

bors-servo commented Sep 16, 2016

The latest upstream changes (presumably #13280) made this pull request unmergeable. Please resolve the merge conflicts.

@gilbertw1 gilbertw1 force-pushed the gilbertw1:basic-auth-cache-clean branch from 09ab326 to 54c7c33 Sep 16, 2016
@gilbertw1
Copy link
Contributor Author

gilbertw1 commented Sep 16, 2016

@jdm: Could you please advise on the MANIFEST.json file? Are the test entries in the correct location, should I update it in some way so that the CI build will pass? Thanks!

@jdm
Copy link
Member

jdm commented Sep 16, 2016

If you run ./mach update-manifest it should do the right thing.

@gilbertw1 gilbertw1 force-pushed the gilbertw1:basic-auth-cache-clean branch from 54c7c33 to 43dae3d Sep 16, 2016
@gilbertw1
Copy link
Contributor Author

gilbertw1 commented Sep 16, 2016

Thanks! Problem fixed.

@@ -1,15 +1,26 @@
<!doctype html>
<meta charset="utf-8">
<link rel="match" href="basic-auth-cache-test-ref.html">

This comment has been minimized.

@jdm

jdm Sep 16, 2016

Member

Oh, these elements should be children of the <html> element.

This comment has been minimized.

@gilbertw1

gilbertw1 Sep 16, 2016

Author Contributor

ah right, fixed.

@gilbertw1 gilbertw1 force-pushed the gilbertw1:basic-auth-cache-clean branch from 43dae3d to 715682c Sep 16, 2016
@jdm
Copy link
Member

jdm commented Sep 16, 2016

@bors-servo: r+
Thanks!

@bors-servo
Copy link
Contributor

bors-servo commented Sep 16, 2016

📌 Commit 715682c has been approved by jdm

@bors-servo
Copy link
Contributor

bors-servo commented Sep 16, 2016

Testing commit 715682c with merge e5b9987...

bors-servo added a commit that referenced this pull request Sep 16, 2016
Update basic auth cache to key off of origin instead of url

This pull request's primary purpose is to store basic auth credentials based on the url origin instead of the entire url. This fixes an issue where servo continuously prompts the user for credentials any time a basic auth secured resource is requested even though the user has already entered auth credentials for a different resource from the same origin.

The test associated with this PR hides image redirects behind a python handler that requires basic authentication. The reference page loads two images by directly specifying the image to load, while the test page loads the two images using the basic auth redirect handler with only the first image tag providing auth credentials.

I'd like to point a few specific items for review:
* url::Origin does not derive ```Hash```, so I am using ```ascii_serialization``` as the cache key. This seems like a stable enough representation.
* I've updated the http loader to store credentials not only on Success responses, but Redirect responses as well. I stumbled on this because nginx was redirecting 'test' -> 'test/' in my testing, and other browsers were storing the credentials on the redirect response vs. prompting for credentials a second time.
* In the test I'm using a timeout to load the second image (without authentication), otherwise the order that the images were loaded was unpredictable.

---
<!-- Thank you for contributing to Servo! Please replace each `[ ]` by `[X]` when the step is complete, and replace `__` with appropriate data: -->
- [x] `./mach build -d` does not report any errors
- [x] `./mach test-tidy` does not report any errors related to these changes
- [x] These changes fix #12095  (github issue number if applicable).

<!-- Either: -->
- [x] There are tests for these changes OR
- [ ] These changes do not require tests because _____

<!-- Reviewable:start -->
---
This change is [<img src="https://reviewable.io/review_button.svg" height="34" align="absmiddle" alt="Reviewable"/>](https://reviewable.io/reviews/servo/servo/13281)
<!-- Reviewable:end -->
@jdm
jdm approved these changes Sep 16, 2016
@bors-servo
Copy link
Contributor

bors-servo commented Sep 16, 2016

@bors-servo bors-servo merged commit 715682c into servo:master Sep 16, 2016
3 checks passed
3 checks passed
continuous-integration/appveyor/pr AppVeyor build succeeded
Details
continuous-integration/travis-ci/pr The Travis CI build passed
Details
homu Test successful
Details
@gilbertw1
Copy link
Contributor Author

gilbertw1 commented Sep 16, 2016

No problem, I plan to continue contributing in the future!

@gilbertw1 gilbertw1 deleted the gilbertw1:basic-auth-cache-clean branch Sep 16, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Linked issues

Successfully merging this pull request may close these issues.

5 participants
You can’t perform that action at this time.