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

Include "content-type" in cors safelisted request headers. #12915

Merged
merged 1 commit into from Aug 23, 2016

Conversation

@jeenalee
Copy link
Contributor

jeenalee commented Aug 17, 2016

The changes in headers.rs will allow headers with "content-type" name to be classified as cors safelisted request headers, depending on its value according to the Fetch spec. As a result of this change, more request web platform tests pass, whose expected test results are updated with this commit.

There is possibly one TODO related to this PR:


  • ./mach build -d does not report any errors
  • ./mach test-tidy does not report any errors
  • These changes fix #__ (github issue number if applicable).
  • There are tests for these changes OR
  • These changes do not require tests because web platform tests for the changes already exist.

This commit allows headers with "content-type" name to be classified as valid header name, depending on its value according to the Fetch spec. As a result of this change, more request web platform tests pass, whose expected test results are updated as well.


This change is Reviewable

match value_without_parameter {
"application/x-www-form-urlencoded" |
"multipart/form-data" |
"text/plain" => Ok(true),

This comment has been minimized.

@KiChjang

KiChjang Aug 17, 2016

Member

I'm quite sad that all of this infrastructure isn't using the mime crate.

This comment has been minimized.

@jeenalee

jeenalee Aug 17, 2016

Author Contributor

I didn't know about mime! Thanks for letting me know. Looks like it will be really helpful. I'll look into it.

This comment has been minimized.

@Manishearth

Manishearth Aug 18, 2016

Member

Yes. We should parse the value first, and operate on the parsed Header instance, matching on its type.

This is important because some of the other headers (e.g. Downlink) are only safe if they are parsed correctly.

This comment has been minimized.

@Manishearth

Manishearth Aug 18, 2016

Member

Actually, hyper doesn't expose clean APIs for dealing with this, so for now it's fine if you just parse as mime type and ignore the others.

@jeenalee jeenalee force-pushed the jeenalee:parse-headers branch from d2ae750 to 7b4f654 Aug 18, 2016
@jeenalee
Copy link
Contributor Author

jeenalee commented Aug 22, 2016

Hi @Manishearth, I updated the script to use the mime crate. When you have a moment, can you review it please? Thanks!

if self.guard.get() == Guard::RequestNoCors && !is_cors_safelisted_request_header(&valid_name) {
return Ok(());
}
// TODO: Requires clarification from the spec.

This comment has been minimized.

@Manishearth

Manishearth Aug 22, 2016

Member

link to spec bug here please

// "DPR", "Downlink", "Save-Data", "Viewport-Width", "Width":
// once parsed, the value should not be failure.
fn is_cors_safelisted_request_content_type(value: &[u8]) -> Result<bool, Error> {
let value_string = try!(str::from_utf8(value).map_err(

This comment has been minimized.

@Manishearth

Manishearth Aug 22, 2016

Member

The error doesn't get used in the end. What about

let value_string = if let Ok(s) = str::from_utf8(value) {
    s
} else {
    return false;
}

and then just return a bool

@Manishearth
Copy link
Member

Manishearth commented Aug 22, 2016

r=me with those two issues fixed

This commit allows headers with "content-type" name to be classified as valid header name, depending on its value according to [the Fetch spec](https://fetch.spec.whatwg.org/#cors-safelisted-request-header). As a result of this change, more request web platform tests pass, whose expected test results are updated with this commit.
@jeenalee jeenalee force-pushed the jeenalee:parse-headers branch from 7b4f654 to cc7b1c5 Aug 22, 2016
@jeenalee
Copy link
Contributor Author

jeenalee commented Aug 22, 2016

@Manishearth The two issues have been fixed. Thank you!

@Manishearth
Copy link
Member

Manishearth commented Aug 22, 2016

@bors-servo
Copy link
Contributor

bors-servo commented Aug 22, 2016

📌 Commit cc7b1c5 has been approved by Manishearth

@bors-servo
Copy link
Contributor

bors-servo commented Aug 22, 2016

Testing commit cc7b1c5 with merge 148647d...

bors-servo added a commit that referenced this pull request Aug 22, 2016
Include "content-type" in cors safelisted request headers.

<!-- Please describe your changes on the following line: -->

The changes in headers.rs will allow headers with "content-type" name to be classified as cors safelisted request headers, depending on its value according to [the Fetch spec](https://fetch.spec.whatwg.org/#cors-safelisted-request-header). As a result of this change, more request web platform tests pass, whose expected test results are updated with this commit.

There is possibly one TODO related to this PR:
- Figure out what `name/'invalid'` is in step 4 of the [Headers Delete method](https://fetch.spec.whatwg.org/#dom-headers-delete), and how to implement that.

---
<!-- 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
- [ ] These changes fix #__ (github issue number if applicable).

<!-- Either: -->
- [ ] There are tests for these changes OR
- [X] These changes do not require tests because web platform tests for the changes already exist.

<!-- Pull requests that do not address these steps are welcome, but they will require additional verification as part of the review process. -->

This commit allows headers with "content-type" name to be classified as valid header name, depending on its value according to [the Fetch spec](https://fetch.spec.whatwg.org/#cors-safelisted-request-header). As a result of this change, more request web platform tests pass, whose expected test results are updated as well.

<!-- 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/12915)
<!-- Reviewable:end -->
@bors-servo
Copy link
Contributor

bors-servo commented Aug 22, 2016

💔 Test failed - linux-rel

@highfive
Copy link

highfive commented Aug 22, 2016

  ▶ FAIL [expected PASS] /css-transforms-1_dev/html/transform-table-007.htm
  └   → /css-transforms-1_dev/html/transform-table-007.htm a5c014b20ef1363bea6f24eda28c7efb7c45698a
/css-transforms-1_dev/html/reference/transform-blank-ref.htm fa6407b1acbbfea27e27061e7d1bdeca98e4a728
Testing a5c014b20ef1363bea6f24eda28c7efb7c45698a == fa6407b1acbbfea27e27061e7d1bdeca98e4a728
@jeenalee
Copy link
Contributor Author

jeenalee commented Aug 22, 2016

Hmm, the /css-transforms-1_dev/html/transform-table-007.htm test passes locally...

@Manishearth
Copy link
Member

Manishearth commented Aug 22, 2016

@bors-servo
Copy link
Contributor

bors-servo commented Aug 22, 2016

Previous build results for arm32, arm64, linux-dev, mac-dev-unit, mac-rel-css, mac-rel-wpt, windows-dev are reusable. Rebuilding only linux-rel...

@bors-servo
Copy link
Contributor

bors-servo commented Aug 22, 2016

💔 Test failed - linux-rel

@highfive
Copy link

highfive commented Aug 22, 2016

  ▶ FAIL [expected PASS] /css-transforms-1_dev/html/transform-table-007.htm
  └   → /css-transforms-1_dev/html/transform-table-007.htm a5c014b20ef1363bea6f24eda28c7efb7c45698a
/css-transforms-1_dev/html/reference/transform-blank-ref.htm fa6407b1acbbfea27e27061e7d1bdeca98e4a728
Testing a5c014b20ef1363bea6f24eda28c7efb7c45698a == fa6407b1acbbfea27e27061e7d1bdeca98e4a728
@jdm
Copy link
Member

jdm commented Aug 22, 2016

jeenalee added a commit to jeenalee/servo that referenced this pull request Aug 22, 2016
The version that includes "content-type" in valid header name is from
[PR 12915](servo#12915).
@bors-servo
Copy link
Contributor

bors-servo commented Aug 22, 2016

Testing commit cc7b1c5 with merge 117a39f...

bors-servo added a commit that referenced this pull request Aug 22, 2016
Include "content-type" in cors safelisted request headers.

<!-- Please describe your changes on the following line: -->

The changes in headers.rs will allow headers with "content-type" name to be classified as cors safelisted request headers, depending on its value according to [the Fetch spec](https://fetch.spec.whatwg.org/#cors-safelisted-request-header). As a result of this change, more request web platform tests pass, whose expected test results are updated with this commit.

There is possibly one TODO related to this PR:
- Figure out what `name/'invalid'` is in step 4 of the [Headers Delete method](https://fetch.spec.whatwg.org/#dom-headers-delete), and how to implement that.

---
<!-- 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
- [ ] These changes fix #__ (github issue number if applicable).

<!-- Either: -->
- [ ] There are tests for these changes OR
- [X] These changes do not require tests because web platform tests for the changes already exist.

<!-- Pull requests that do not address these steps are welcome, but they will require additional verification as part of the review process. -->

This commit allows headers with "content-type" name to be classified as valid header name, depending on its value according to [the Fetch spec](https://fetch.spec.whatwg.org/#cors-safelisted-request-header). As a result of this change, more request web platform tests pass, whose expected test results are updated as well.

<!-- 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/12915)
<!-- Reviewable:end -->
@bors-servo
Copy link
Contributor

bors-servo commented Aug 23, 2016

💔 Test failed - linux-rel

@jdm
Copy link
Member

jdm commented Aug 23, 2016

@bors-servo
Copy link
Contributor

bors-servo commented Aug 23, 2016

Testing commit cc7b1c5 with merge 1e10f8b...

bors-servo added a commit that referenced this pull request Aug 23, 2016
Include "content-type" in cors safelisted request headers.

<!-- Please describe your changes on the following line: -->

The changes in headers.rs will allow headers with "content-type" name to be classified as cors safelisted request headers, depending on its value according to [the Fetch spec](https://fetch.spec.whatwg.org/#cors-safelisted-request-header). As a result of this change, more request web platform tests pass, whose expected test results are updated with this commit.

There is possibly one TODO related to this PR:
- Figure out what `name/'invalid'` is in step 4 of the [Headers Delete method](https://fetch.spec.whatwg.org/#dom-headers-delete), and how to implement that.

---
<!-- 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
- [ ] These changes fix #__ (github issue number if applicable).

<!-- Either: -->
- [ ] There are tests for these changes OR
- [X] These changes do not require tests because web platform tests for the changes already exist.

<!-- Pull requests that do not address these steps are welcome, but they will require additional verification as part of the review process. -->

This commit allows headers with "content-type" name to be classified as valid header name, depending on its value according to [the Fetch spec](https://fetch.spec.whatwg.org/#cors-safelisted-request-header). As a result of this change, more request web platform tests pass, whose expected test results are updated as well.

<!-- 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/12915)
<!-- Reviewable:end -->
@bors-servo
Copy link
Contributor

bors-servo commented Aug 23, 2016

@bors-servo bors-servo merged commit cc7b1c5 into servo:master Aug 23, 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
@bors-servo bors-servo mentioned this pull request Aug 23, 2016
3 of 5 tasks complete
@jeenalee jeenalee deleted the jeenalee:parse-headers branch Aug 24, 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.

None yet

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