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

Accept 'sec-'-prefixed headers as CORS-safelisted. #1000

Closed
wants to merge 3 commits into from
Closed

Conversation

mikewest
Copy link
Member

@mikewest mikewest commented Feb 14, 2020

As discussed in #993.

@yoavweiss: Is there a better bug that we should link this to? I know you've had a lot of conversations on this topic.

@annevk: I'm not entirely sure how best to phrase this. I was hoping for some mechanics in infra... is "begins with the string XXX" good enough, or should I be more explicit?

Thanks!


Preview | Diff

@yoavweiss
Copy link
Collaborator

So I don't have an open issue for this, but I do have an open PR. This replaces it, and is nicer (with a lovely note), so I can obsolete the other one.

Copy link
Collaborator

@yoavweiss yoavweiss left a comment

Choose a reason for hiding this comment

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

LGTM


<p class=note>As all headers beginning with "<code>Sec-</code>" are <a>forbidden header
names</a>, we have some confidence that they're generated by the user agent, and not via APIs
that developers directly control.
Copy link
Member

Choose a reason for hiding this comment

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

The other thing we should point out here is #880 (comment). In particular, if Fetch isn't in control of setting these headers, you might be in for a surprise with service workers.

Copy link
Member Author

Choose a reason for hiding this comment

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

I don't quite follow where that conversation ended up. What's the behavior in Service Workers that we want? What behavior would surprise developers? @yoavweiss

Copy link
Collaborator

Choose a reason for hiding this comment

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

So, the surprising bits would be that Sec- prefixed headers would disappear from the requests when developers would modify the request in SW in any way (but won't disappear for pass-through cases).

For the CH case, I think we could solve this by re-adding them below SWs (but @annevk had reservations). For Fetch-Metadata, maybe you could simply add them below SWs?

Copy link
Member

Choose a reason for hiding this comment

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

I think for Fetch-Metadata all is in order because they are set as part of main fetch.

fetch.bs Outdated Show resolved Hide resolved
fetch.bs Outdated Show resolved Hide resolved
mikewest and others added 2 commits February 14, 2020 14:30
Co-Authored-By: Anne van Kesteren <annevk@annevk.nl>
Co-Authored-By: Anne van Kesteren <annevk@annevk.nl>
@annevk
Copy link
Member

annevk commented Mar 13, 2020

I tried to write a patch to address my comment, but while doing so I discovered another problem. Namely, https://fetch.spec.whatwg.org/#cors-unsafe-request-header-names. And it's really two problems:

  1. With enough Sec- headers the 1024 limit would get breached.
  2. As currently written we'd ask the server to safelist Sec- headers, which doesn't make a lot of sense.

I suspect we don't want to change https://fetch.spec.whatwg.org/#cors-safelisted-request-header after all, but only want to change https://fetch.spec.whatwg.org/#cors-unsafe-request-header-names which is what ends up being used. However, we need to think through the value limit problem a bit.

@toyoshim
Copy link

Hi Anne,

Sec- is also listed in https://fetch.spec.whatwg.org/#forbidden-header-name.
So, I think it's completely safe to skip them in the 1024 limit counting. We can ensure that these are not set or modified by users' JavaScripts.

@annevk
Copy link
Member

annevk commented Mar 13, 2020

Up to a point, part of the reason for the limit is to avoid hitting server limits. If user agents add a lot of Sec- headers, or they get attacker-controlled values, we're back to square one. So I don't think it's that easy unfortunately.

@toyoshim
Copy link

Ah..., I see.
Thank you for your clarification.

Since we will have more Sec- prefixed headers day by day, it's likely to increase chance to send the preflight for almost all cross-origin requests.

I just started investigating performance implication caused by the preflight, and this point may contribute to revisit the origin policy supporting for the orogin-wide preflight-like query.

@annevk
Copy link
Member

annevk commented Mar 4, 2021

Closing this per the above comments and as it's no longer blocking #993. I filed #1186 as follow-up.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
do not merge yet Pull request must not be merged per rationale in comment
Development

Successfully merging this pull request may close these issues.

5 participants