Skip to content

Commit 268e714

Browse files
author
Raphael Kubo da Costa
committed
Drop own powerful feature, require active local video source.
Fixes #79. The idea is that, based on the research on potential attacks on the Ambient Light Sensor API, it is important to prompt users before allowing access to illuminance readouts. This was already mandated by the main Generic Sensors spec, as `Sensor.start()` runs the "Request sensor access" abstract operation. The challenge with the Ambient Light Sensor API is prompting users in a way that they understand what they are being prompted for; the assumption is that most users are not familiar with what an Ambient Light sensor is. We have chosen to solve this issue by dropping our "ambient-light-sensor" powerful feature name altogether and integrating with the Media Capture and Streams specification instead: we consider an Ambient Light Sensor to be a 1x1 camera and require there to be at least one local video source that is not muted or stopped in order for illuminance readouts to be provided. Per the Media Capture and Streams specification, this is only possible if script has called `MediaDevices.getUserMedia()` and granted the "camera" permission. This also means the User Agent has at least indicated to the user that a local video source has started being used. In other words, an Ambient Light Sensor only provides readings if a local video source (such as a camera) is currently active and being used in the same window as the AmbientLightSensor instance, and when all local video sources stop we also stop providing readouts and fire an "error" with a NotReadableError exception. The Use Cases section had to be shortened, as some items described there no longer make much sense when a camera is required.
1 parent 2f4a4e2 commit 268e714

File tree

1 file changed

+117
-12
lines changed

1 file changed

+117
-12
lines changed

index.bs

Lines changed: 117 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,13 @@ urlPrefix: https://w3c.github.io/sensors/; spec: GENERIC-SENSOR
5555
urlPrefix: https://tc39.es/ecma262/; spec: ECMA-262
5656
type: abstract-op
5757
text: abs; url: eqn-abs
58+
urlPrefix: https://w3c.github.io/mediacapture-main/; spec: MEDIACAPTURE-STREAMS
59+
type: dfn
60+
text: stopped; url: source-stopped
61+
</pre>
62+
<pre class=link-defaults>
63+
spec:generic-sensor; type:attribute; text:[[state]]
64+
spec:mediacapture-streams; type:dfn; text:source
5865
</pre>
5966

6067
<pre class=biblio>
@@ -237,9 +244,13 @@ Works such as [[ALSPRIVACYANALYSIS]], [[PINSKIMMINGVIASENSOR]],
237244
[[STEALINGSENSITIVEDATA]], and [[VIDEORECOGNITIONAMBIENTLIGHT]] delve further
238245
into these issues.
239246

240-
To mitigate these threats specific to Ambient Light Sensor, user agents must
241-
<a>reduce accuracy</a> of sensor readings. User agents may also <a>limit
242-
maximum sampling frequency</a>.
247+
To mitigate these threats specific to Ambient Light Sensor, user agents must:
248+
- [=Reduce accuracy=] of sensor readings. See [[#reduce-sensor-accuracy]].
249+
- Obtain user consent before providing sensor readings. This is done by
250+
integrating with the [[MEDIACAPTURE-STREAMS]] specification. See
251+
[[#local-video-source-requirement]].
252+
253+
User agents may also <a>limit maximum sampling frequency</a>.
243254

244255
These mitigation strategies complement the [=mitigation strategies|generic mitigations=]
245256
defined in the Generic Sensor API [[!GENERIC-SENSOR]].
@@ -283,6 +294,39 @@ experience. <a href="https://crbug.com/1332536">Chromium bug 1332536</a> and <a
283294
href="https://crrev.com/c/3666917">Chromium review 3666917</a> contain more
284295
information about this.
285296

297+
Active local video source requirement {#local-video-source-requirement}
298+
-----
299+
300+
Many of the attacks on Ambient Light sensors referenced above rely on being
301+
able to access illuminance readouts for a certain amount of time without a user
302+
being aware that the data is being read.
303+
304+
[[STEALINGSENSITIVEDATA]] and [[ALSPRIVACYANALYSIS]] specifically recommend
305+
requesting user permission before allowing access to illuminance readouts as a
306+
privacy measure. On the other hand, it can be argued that conveying to users
307+
what an Ambient Light Sensor is so that they can make an informed choice to
308+
grant or deny access to it can be difficult.
309+
310+
What this specification does instead is consider an Ambient Light Sensor to be
311+
a 1x1 grayscale camera, integrate with the [[MEDIACAPTURE-STREAMS]]
312+
specification and require there to be at least one local video [=source=] that
313+
is not [=muted=] or [=stopped=] in order for illuminance readouts to be
314+
provided. In other words, an Ambient Light Sensor only provides readings if a
315+
local video source (such as a camera) is currently active and being used in the
316+
same window as the {{AmbientLightSensor}} instance.
317+
318+
Per the [[MEDIACAPTURE-STREAMS]] specification, this is only possible if script
319+
has called {{MediaDevices/getUserMedia()}} and granted the <a
320+
permission>"camera"</a> permission. This also means the User Agent has at least
321+
indicated to the user that a local video source has started being used as per
322+
[[MEDIACAPTURE-STREAMS#privacy-indicator-requirements]].
323+
324+
The goal of this model is to treat an Ambient Light Sensor as potentially as
325+
invasive as an actual camera device and subject it to the same strict privacy
326+
requirements together with the Generic Sensor mitigations described in
327+
[[GENERIC-SENSOR#security-and-privacy]] and the other Ambient Light
328+
Sensor-specific measures described in this section.
329+
286330
Model {#model}
287331
=====
288332

@@ -292,12 +336,12 @@ subclass is the {{AmbientLightSensor}} class.
292336
The <a>Ambient Light Sensor</a> has a <a>default sensor</a>,
293337
which is the device's main light detector.
294338

295-
The <a>Ambient Light Sensor</a> is a [=powerful feature=] that is identified by
296-
the [=powerful feature/name=] "<dfn permission export>ambient-light-sensor</dfn>",
297-
which is also its associated [=sensor permission name=]. Its
298-
[=powerful feature/permission revocation algorithm=] is the result of calling
299-
the [=generic sensor permission revocation algorithm=] with
300-
"ambient-light-sensor".
339+
The <a>Ambient Light Sensor</a>'s [=sensor permission names=] is an
340+
[=set/empty=] [=ordered set|set=].
341+
342+
Note: See [[#local-video-source-requirement]]. This specification relies on the
343+
permission model specified in the [[MEDIACAPTURE-STREAMS]] specification
344+
instead.
301345

302346
The <a>Ambient Light Sensor</a> is a [=policy-controlled feature=] identified by the string "ambient-light-sensor". Its [=default allowlist=] is `'self'`.
303347

@@ -345,6 +389,35 @@ The {{AmbientLightSensor/illuminance}} getter steps are:
345389
reading=] with [=this=] and "illuminance" as arguments.
346390
1. Return |illuminance|.
347391

392+
### Media Capture and Streams integration ### {#media-capture-and-streams-integration}
393+
394+
As discussed in [[#local-video-source-requirement]], illuminance readouts are
395+
provided only if the same {{Window}} with an {{AmbientLightSensor}} object has
396+
at least one local video [=source=] that is not [=muted=] or [=stopped=].
397+
398+
The [=ambient light pre-activation checks algorithm=] is invoked by
399+
{{Sensor/start()}} as specified in [[GENERIC-SENSOR]].
400+
401+
Furthermore, whenever an item is added to the {{Window}}.\[[devicesLiveMap]]
402+
internal slot, or one of its items has its value changed, implementations MUST
403+
run the following steps:
404+
405+
<div algorithm="deactivate sensors if necessary">
406+
1. Let |global| be the {{Window}} object of the affected \[[devicesLiveMap]]
407+
internal slot.
408+
1. Let |result| be the result of invoking [=check for active local video sources=] with |global|.
409+
1. If |result| is true, return.
410+
1. For each {{AmbientLightSensor}} object |sensor| whose [=relevant global
411+
object=] is |global|:
412+
1. If |sensor|.{{[[state]]}} is "idle", then [=continue=].
413+
1. Invoke [=deactivate a sensor object=] with |sensor|.
414+
1. Let |e| be the result of [=created|creating=]
415+
a "{{NotReadableError}}" {{DOMException}}.
416+
1. [=Queue a global task=] on the [=sensor task source=] with |global| to
417+
run [=notify error=] with |sensor| and |e| as
418+
arguments.
419+
</div>
420+
348421
Abstract Operations {#abstract-operations}
349422
===================
350423

@@ -418,13 +491,42 @@ quantization algorithm=]:
418491
1. Return |quantizedReading|.
419492
</div>
420493

494+
<h3 dfn>Ambient light pre-activation checks algorithm</h3>
495+
496+
The [=Ambient Light Sensor=] [=sensor type=] defines the following
497+
[=pre-activation checks algorithm=]:
498+
499+
<div algorithm="check active local video source">
500+
: input
501+
:: |sensor|, an {{AmbientLightSensor}} object
502+
: output
503+
:: A [=boolean=] indicating whether the checks have passed and sensor activation may proceed.
504+
505+
1. Let |global| be |sensor|'s [=relevant global object=].
506+
1. Return the result of invoking [=check for active local video sources=] with |global|.
507+
</div>
508+
509+
<h3 dfn>Check for active local video source</h3>
510+
511+
<div algorithm="check for active local video sources">
512+
: input
513+
:: |global|, an {{Window}} object
514+
: output
515+
:: A [=boolean=] indicating whether there are active local video sources.
516+
517+
1. If |global| does not have a \[[mediaStreamTrackSources]] internal slot, return false.
518+
1. For each |source| in |global|'s \[[mediaStreamTrackSources]] internal slot:
519+
1. If |source| is not a video input device, then [=continue=].
520+
1. If |source| is not [=stopped=] or [=muted=], then return true.
521+
1. Return false.
522+
</div>
523+
421524
Automation {#automation}
422525
==========
423526
This section extends the [=automation=] section defined in the Generic Sensor API [[GENERIC-SENSOR]]
424527
to provide mocking information about the ambient light levels for the purposes of testing a user agent's
425528
implementation of [=Ambient Light Sensor=].
426529

427-
428530
<h3 id="mock-ambient-light-sensor-type">Mock Sensor Type</h3>
429531

430532
The {{AmbientLightSensor}} class has an associated [=mock sensor type=] which is
@@ -440,8 +542,6 @@ dictionary is defined as follows:
440542
Use Cases and Requirements {#usecases-requirements}
441543
=========
442544

443-
- A Web application provides input for a smart home system to control lighting.
444-
- A Web application checks whether light level at work space is sufficient.
445545
- A Web application calculates settings for a camera with manual controls (aperture, shutter speed, ISO).
446546
- A Web application checks the current light level to determine whether a
447547
camera stream will contain data that is accurate enough for its purposes
@@ -451,6 +551,11 @@ While some of the use cases may benefit from obtaining precise ambient light mea
451551
cases that convert ambient light level fluctuations to user input events would benefit from
452552
higher [=sampling frequency|sampling frequencies=].
453553

554+
Note: A previous version of this specification did not require an active camera and did
555+
not integrate with the [[MEDIACAPTURE-STREAMS]] specification. It allowed for a wider
556+
range of use cases, such as providing input smart home systems to control lighting or
557+
checking whether the light level at a work space is sufficient.
558+
454559
Acknowledgements {#acknowledgements}
455560
================
456561

0 commit comments

Comments
 (0)