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

Assess compatibility risk of using [SecureContext] #15

Closed
anssiko opened this issue Nov 17, 2017 · 14 comments · Fixed by #51
Closed

Assess compatibility risk of using [SecureContext] #15

anssiko opened this issue Nov 17, 2017 · 14 comments · Fixed by #51
Assignees

Comments

@anssiko
Copy link
Member

anssiko commented Nov 17, 2017

If we'd add [SecureContext] to partial interface Navigator and BatteryManager as is the current trend, we could drop the following prose:

If the current settings object is not a secure context, then reject this Navigator object's battery promise with a "SecurityError" DOMException and abort these steps.

However, this would break any feature detection code that relies on checking the existence of properties or objects, e.g.:

if ("getBattery" in navigator && "BatteryManager" in window)
  console.log('All your battery are belong to us');

I guess nearly everyone using this API must do some sort of feature detection.

My hunch is we want to close this issue as won't fix citing backward compatibility concerns.

Thoughts?

@domenic
Copy link
Contributor

domenic commented Feb 25, 2021

This is one of, I believe, two APIs on the platform which do explicit secure context checks instead of using [SecureContext]. This is causing minor integration problems for other features like prerendering.

I think your argument in the OP indicates it'd be better to use [SecureContext]. That is, non-secure HTTP pages would be better off going down the "this browser does not suppport the API" path, and treating it similar to they do Firefox and Safari, instead of calling the API and getting surprised by a rejected promise.

@anssiko
Copy link
Member Author

anssiko commented Feb 25, 2021

It’s been a while that argument was made so I’ll happily align with the modern convention that does not cause prerendering problems.

@domenic
Copy link
Contributor

domenic commented Feb 25, 2021

To be clear, it's only causing minor problems for prerendering, and we can work around it. I think aligning would be ideal, but as always it's a tradeoff of how much effort it's worth, especially given potential compat risks.

@anssiko
Copy link
Member Author

anssiko commented Feb 25, 2021

Non-secure HTTP usage is now at ~0.38% per https://www.chromestatus.com/metrics/feature/popularity#BatteryStatusInsecureOrigin

Is that still too high to make this change?

@domenic
Copy link
Contributor

domenic commented Feb 25, 2021

Oh, it looks like Blink doesn't implement the spec's secure context restriction at all, wow. So there are three possible behaviors:

  1. The current implementation: works fine in a non-secure context
  2. The current spec: returns a rejected promise in a non-secure context
  3. The ideal spec: throws an exception (because the method doesn't exist at all because it's guarded with [SecureContext]) in a non-secure context

That's... tricky.

I guess my preference would be to remove the secure context restriction from the spec entirely, add a warning box pointing to this issue, and then as a separate effort, try to move the spec and implementation toward (3), if we think it's worth the engineering effort?

@anssiko
Copy link
Member Author

anssiko commented Feb 26, 2021

The move to HTTPS across the web over the last ~4 years should mitigate the compat risk imposed on legitimate sites I raised in the OP back in 2017.

Given this new data, I'd be supportive of the two-stage plan outlined by @domenic.

@domenic, do you want to amend #30 to align with the implementation and get it all reviewed at once? Can take another PR too.

Can you also get Blink owners sign-off for the plan?

Thanks for your efforts in modernizing this spec!

@domenic
Copy link
Contributor

domenic commented Feb 26, 2021

I've amended #30 in such a way!

Can you also get Blink owners sign-off for the plan?

Probably the best way to do that is with an Intent to Ship; I don't have any special powers there. I suspect they'd like to see some analysis of what type of breakage this would cause, e.g. looking at the sites listed in https://www.chromestatus.com/metrics/feature/timeline/popularity/2199 per HTTPArchive in a [SecureContext] build and seeing if they are visibly broken.

@anssiko
Copy link
Member Author

anssiko commented Feb 26, 2021

@domenic thanks!

Let’s see if I can summon @mounirlamouri to review #30. He might have some thoughts on the ItS.

@reillyeon
Copy link
Member

I support announcing a depreciation schedule for non-SecureContext access to the getBattery() method. In Chromium this would be something like "generate a warning on non-SecureContext usage of the method for N releases and then remove as long as usage does not change in an unexpected way".

@rakuco
Copy link
Member

rakuco commented Mar 1, 2021

cc @timvolodine as OWNER of third_party/blink/renderer/modules/battery in Blink. I can try to do that myself otherwise.

@rakuco
Copy link
Member

rakuco commented Jan 25, 2022

Latest update: starting with Chromium M99 (or maybe M100, depending on what the API owners there say), the browser will show a deprecation warning whenever the Battery Status API (i.e. navigator.getBattery() is used in an insecure origin). The plan is to stop exposing the API in insecure origins altogether starting with M103 (whose planned release date is around mid-June 2022).

chromestatus.com entry, blink-dev discussion

From a spec and web-platform-tests perspective, I wonder if it makes sense to update things immediately or somehow make the changes more in sync with Blink, which is the only engine implementing this API at the moment. This would mean landing any changes adding [SecureContext] to Web IDL and updating the tests accordingly in a few months rather than now. Opinions?

@anssiko
Copy link
Member Author

anssiko commented Jan 26, 2022

From a W3C process perspective, we’d land the spec and w-p-t changes as soon as there’s consensus in the WG. We seem to be good on that front: the issue has been open since 2017, discussed at our meetings, and we’ve had a warning in https://www.w3.org/TR/battery-status/#extensions-to-the-navigator-interface for a year with no push back for the proposal.

OTOH, if it is problematic to have Chromium w-p-t show some red until the Blink patches land, we can also consider other options, such as land spec changes now and coordinate w-p-t with Blink. Per our charter, we will follow a test as you commit approarch for CR and above. Recommended, but not mandatory for earlier maturity levels.

In any case, I think we should include a note to the spec about this deprecation.

Thanks for working on this, @rakuco!

@rakuco
Copy link
Member

rakuco commented Jan 26, 2022

From a W3C process perspective, we’d land the spec and w-p-t changes as soon as there’s consensus in the WG.

Yep, that's what I was thinking. I was asking about this because even though the chance is small, there's still the possibility that there is pushback between Chrome 99 and 102 and we are forced to rethink the deprecation and [SecureContext] change in Blink, in which case the spec would remain out of sync with its only implementation for an indefinite period of time.

@anssiko
Copy link
Member Author

anssiko commented Jan 26, 2022

In that scenario, it is possible to revert the spec and w-p-t changes in this particular case. I hope we don’t need to since we’ve done our homework. But we know from past experience that with deprecations there can be surprises.

With multiple implementations or more complex change/interactions this would be a more involved process.

rakuco added a commit to rakuco/wpt that referenced this issue Jan 26, 2022
This test does not reflect either the current spec or any implementation.

w3c/battery#30 removed the bits from the spec that mandated throwing a
SecurityError when the API was used in an insecure origin. Blink does not
perform any checks for a security context anyway, although the plan is to
switch spec and implementation to using [SecureContext] in the future, as
tracked in w3c/battery#15.
rakuco added a commit to web-platform-tests/wpt that referenced this issue Jan 28, 2022
This test does not reflect either the current spec or any implementation.

w3c/battery#30 removed the bits from the spec that mandated throwing a
SecurityError when the API was used in an insecure origin. Blink does not
perform any checks for a security context anyway, although the plan is to
switch spec and implementation to using [SecureContext] in the future, as
tracked in w3c/battery#15.
rakuco added a commit that referenced this issue Jan 31, 2022
…face.

In other words, stop exposing this API to insecure origins.

This has been discussed since at least 2016 (see #5). #11 made access from
an insecure origin throw a SecurityError at a time when the
`[SecureContext]` Web IDL extended attribute was not widespread.
Unfortunately, the spec change was not accompanied by a change in the
implementation(s) and, to this day, Blink's implementation (the only
remaining one) continues to expose the API to insecure origins.

Years later, #30 was added in the context of the discussions in #15 where it
was noted that the spec was still manually throwing a SecurityError when
checking if it was called by a secure origin. Besides stopping throwing a
SecurityError (which was never implemented), #30 also recognized the current
situation by noting that the API _should_ use `[SecureContext]` but did not
because it only made sense to do so when the implementation was updated
accordingly.

This change finally adds `[SecureContext]` to the spec's Web IDL because I
am also handling the Blink implementation [1][2]: starting with Chrome 99,
users will be warned that using the Battery Status API in an insecure origin
is deprecated, and starting with Chrome 103 doing so will no longer be
possible.

[1] https://chromestatus.com/feature/4878376799043584
[2] https://groups.google.com/a/chromium.org/g/blink-dev/c/w80tJL8uEV8/m/PfrHlvtgAgAJ

From a testing perspective, there isn't much to be done:
- web-platform-tests/wpt#5871 changed the existing tests to run in HTTPS.
- web-platform-tests/wpt#32556 removed the test for the SecurityError
  exception that never passed.

Fixes #15
rakuco added a commit that referenced this issue Feb 1, 2022
…face.

In other words, stop exposing this API to insecure origins. Even though this
API is not new, it provides user information that, transmitted insecurely,
can pose a risk to user privacy. See
https://w3ctag.github.io/design-principles/#secure-context for more
information on the guidelines we are trying to follow.

This has been discussed since at least 2016 (see #5). #11 made access from
an insecure origin throw a SecurityError at a time when the
`[SecureContext]` Web IDL extended attribute was not widespread.
Unfortunately, the spec change was not accompanied by a change in the
implementation(s) and, to this day, Blink's implementation (the only
remaining one) continues to expose the API to insecure origins.

Years later, #30 was added in the context of the discussions in #15 where it
was noted that the spec was still manually throwing a SecurityError when
checking if it was called by a secure origin. Besides stopping throwing a
SecurityError (which was never implemented), #30 also recognized the current
situation by noting that the API _should_ use `[SecureContext]` but did not
because it only made sense to do so when the implementation was updated
accordingly.

This change finally adds `[SecureContext]` to the spec's Web IDL because I
am also handling the Blink implementation [1][2]: starting with Chrome 99,
users will be warned that using the Battery Status API in an insecure origin
is deprecated, and starting with Chrome 103 doing so will no longer be
possible.

[1] https://chromestatus.com/feature/4878376799043584
[2] https://groups.google.com/a/chromium.org/g/blink-dev/c/w80tJL8uEV8/m/PfrHlvtgAgAJ

From a testing perspective, there isn't much to be done:
- web-platform-tests/wpt#5871 changed the existing tests to run in HTTPS.
- web-platform-tests/wpt#32556 removed the test for the SecurityError
  exception that never passed.

Fixes #15
rakuco added a commit that referenced this issue Feb 1, 2022
…face.

In other words, stop exposing this API to insecure origins. Even though this
API is not new, it provides user information that, transmitted insecurely,
can pose a risk to user privacy. See
https://w3ctag.github.io/design-principles/#secure-context for more
information on the guidelines we are trying to follow.

This has been discussed since at least 2016 (see #5). #11 made access from
an insecure origin throw a SecurityError at a time when the
`[SecureContext]` Web IDL extended attribute was not widespread.
Unfortunately, the spec change was not accompanied by a change in the
implementation(s) and, to this day, Blink's implementation (the only
remaining one) continues to expose the API to insecure origins.

Years later, #30 was added in the context of the discussions in #15 where it
was noted that the spec was still manually throwing a SecurityError when
checking if it was called by a secure origin. Besides stopping throwing a
SecurityError (which was never implemented), #30 also recognized the current
situation by noting that the API _should_ use `[SecureContext]` but did not
because it only made sense to do so when the implementation was updated
accordingly.

This change finally adds `[SecureContext]` to the spec's Web IDL because I
am also handling the Blink implementation [1][2]: starting with Chrome 99,
users will be warned that using the Battery Status API in an insecure origin
is deprecated, and starting with Chrome 103 doing so will no longer be
possible.

[1] https://chromestatus.com/feature/4878376799043584
[2] https://groups.google.com/a/chromium.org/g/blink-dev/c/w80tJL8uEV8/m/PfrHlvtgAgAJ

From a testing perspective, there isn't much to be done:
- web-platform-tests/wpt#5871 changed the existing tests to run in HTTPS.
- web-platform-tests/wpt#32556 removed the test for the SecurityError
  exception that never passed.

Fixes #15
@rakuco rakuco closed this as completed in #51 Feb 1, 2022
rakuco added a commit that referenced this issue Feb 1, 2022
…face. (#51)

In other words, stop exposing this API to insecure origins. Even though this
API is not new, it provides user information that, transmitted insecurely,
can pose a risk to user privacy. See
https://w3ctag.github.io/design-principles/#secure-context for more
information on the guidelines we are trying to follow.

This has been discussed since at least 2016 (see #5). #11 made access from
an insecure origin throw a SecurityError at a time when the
`[SecureContext]` Web IDL extended attribute was not widespread.
Unfortunately, the spec change was not accompanied by a change in the
implementation(s) and, to this day, Blink's implementation (the only
remaining one) continues to expose the API to insecure origins.

Years later, #30 was added in the context of the discussions in #15 where it
was noted that the spec was still manually throwing a SecurityError when
checking if it was called by a secure origin. Besides stopping throwing a
SecurityError (which was never implemented), #30 also recognized the current
situation by noting that the API _should_ use `[SecureContext]` but did not
because it only made sense to do so when the implementation was updated
accordingly.

This change finally adds `[SecureContext]` to the spec's Web IDL because I
am also handling the Blink implementation [1][2]: starting with Chrome 99,
users will be warned that using the Battery Status API in an insecure origin
is deprecated, and starting with Chrome 103 doing so will no longer be
possible.

[1] https://chromestatus.com/feature/4878376799043584
[2] https://groups.google.com/a/chromium.org/g/blink-dev/c/w80tJL8uEV8/m/PfrHlvtgAgAJ

From a testing perspective, there isn't much to be done:
- web-platform-tests/wpt#5871 changed the existing tests to run in HTTPS.
- web-platform-tests/wpt#32556 removed the test for the SecurityError
  exception that never passed.

Fixes #15
mattwoodrow pushed a commit to mattwoodrow/wpt that referenced this issue Feb 15, 2022
…ests#32556)

This test does not reflect either the current spec or any implementation.

w3c/battery#30 removed the bits from the spec that mandated throwing a
SecurityError when the API was used in an insecure origin. Blink does not
perform any checks for a security context anyway, although the plan is to
switch spec and implementation to using [SecureContext] in the future, as
tracked in w3c/battery#15.
moz-v2v-gh pushed a commit to mozilla/gecko-dev that referenced this issue Feb 26, 2022
…context.html., a=testonly

Automatic update from web-platform-tests
battery status: Remove battery-insecure-context.html. (#32556)

This test does not reflect either the current spec or any implementation.

w3c/battery#30 removed the bits from the spec that mandated throwing a
SecurityError when the API was used in an insecure origin. Blink does not
perform any checks for a security context anyway, although the plan is to
switch spec and implementation to using [SecureContext] in the future, as
tracked in w3c/battery#15.
--

wpt-commits: aa8ded0ca6ef536aa74719a73d7175499f0a2cd8
wpt-pr: 32556
DanielRyanSmith pushed a commit to DanielRyanSmith/wpt that referenced this issue Feb 28, 2022
…ests#32556)

This test does not reflect either the current spec or any implementation.

w3c/battery#30 removed the bits from the spec that mandated throwing a
SecurityError when the API was used in an insecure origin. Blink does not
perform any checks for a security context anyway, although the plan is to
switch spec and implementation to using [SecureContext] in the future, as
tracked in w3c/battery#15.
jamienicol pushed a commit to jamienicol/gecko that referenced this issue Mar 1, 2022
…context.html., a=testonly

Automatic update from web-platform-tests
battery status: Remove battery-insecure-context.html. (#32556)

This test does not reflect either the current spec or any implementation.

w3c/battery#30 removed the bits from the spec that mandated throwing a
SecurityError when the API was used in an insecure origin. Blink does not
perform any checks for a security context anyway, although the plan is to
switch spec and implementation to using [SecureContext] in the future, as
tracked in w3c/battery#15.
--

wpt-commits: aa8ded0ca6ef536aa74719a73d7175499f0a2cd8
wpt-pr: 32556
moz-v2v-gh pushed a commit to mozilla/gecko-dev that referenced this issue Mar 8, 2022
…context.html., a=testonly

Automatic update from web-platform-tests
battery status: Remove battery-insecure-context.html. (#32556)

This test does not reflect either the current spec or any implementation.

w3c/battery#30 removed the bits from the spec that mandated throwing a
SecurityError when the API was used in an insecure origin. Blink does not
perform any checks for a security context anyway, although the plan is to
switch spec and implementation to using [SecureContext] in the future, as
tracked in w3c/battery#15.
--

wpt-commits: aa8ded0ca6ef536aa74719a73d7175499f0a2cd8
wpt-pr: 32556
jamienicol pushed a commit to jamienicol/gecko that referenced this issue Mar 8, 2022
…context.html., a=testonly

Automatic update from web-platform-tests
battery status: Remove battery-insecure-context.html. (#32556)

This test does not reflect either the current spec or any implementation.

w3c/battery#30 removed the bits from the spec that mandated throwing a
SecurityError when the API was used in an insecure origin. Blink does not
perform any checks for a security context anyway, although the plan is to
switch spec and implementation to using [SecureContext] in the future, as
tracked in w3c/battery#15.
--

wpt-commits: aa8ded0ca6ef536aa74719a73d7175499f0a2cd8
wpt-pr: 32556
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants