fetch icon indicating copy to clipboard operation
fetch copied to clipboard

Secure cookies should be permitted on secure requests, not just where there is a `https` scheme

Open bvandersloot-mozilla opened this issue 7 months ago • 8 comments

What is the issue with the Fetch Standard?

Secure contexts are defined to allow things where the web platform wants to ensure there isn't a network attacker. There is no corresponding definition for URLs, so we just match on the scheme for Secure cookies. In the interest of letting localhost be localhost, we should probably permit Secure attributed cookies when host="localhost". We could even extend this to include DNS resolution to loopback addresses or IP addreses that are routed to not leave the device.

bvandersloot-mozilla avatar May 19 '25 12:05 bvandersloot-mozilla

cc @DCtheTall @mikewest

This seems like a logical thing to do, but I may be overlooking some horrible property of the Web platform that complicates things.

johannhof avatar May 20 '25 01:05 johannhof

I guess it does complicate the separation between http://localhost and https://localhost, but in so far as that matters, we should fix that by shipping https://github.com/sbingler/Origin-Bound-Cookies

davidben avatar May 20 '25 03:05 davidben

I believe this matches Chromium's existing behavior, though I'd want to test it to make sure I'm remembering the code correctly.

mikewest avatar May 20 '25 05:05 mikewest

Dumb question: Can we test localhost in WPTs?

johannhof avatar May 20 '25 13:05 johannhof

We cannot. At least, not in a way that works in a context-independent way.

We could add a webdriver mechanism to define some other origin as "localhost" (similar to what we did for loopback IP addresses in https://github.com/web-platform-tests/wpt/issues/26166), but that would be a reasonable amount of work to get right (in Chromium at least).

mikewest avatar May 20 '25 13:05 mikewest

This also matches Firefox's existing behavior, but not Safari's

bvandersloot-mozilla avatar May 20 '25 13:05 bvandersloot-mozilla

So the proposal here is to use https://w3c.github.io/webappsec-secure-contexts/#is-url-trustworthy on request's current URL instead of doing a scheme check? That's probably reasonable, but does seem best tackled as follow-up. (This does make me recall we never quite fully settled how Secure Contexts and HTML integrate, but that isn't really a blocker.)

The initial PR was doing a secure context check on request's client, which is quite a bit different.

annevk avatar May 20 '25 14:05 annevk

Yeah, the initial PR was definitely wrong. I think this is a good follow up as well.

bvandersloot-mozilla avatar May 20 '25 15:05 bvandersloot-mozilla