-
Notifications
You must be signed in to change notification settings - Fork 25
/
Copy pathspec.bs
1792 lines (1514 loc) · 81.3 KB
/
spec.bs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
<pre class='metadata'>
Title: Private Aggregation API
Shortname: private-aggregation-api
Level: 1
Status: UD
Group: patcg-id
Repository: patcg-individual-drafts/private-aggregation-api
URL: https://patcg-individual-drafts.github.io/private-aggregation-api
Editor: Alexander Turner, Google https://www.google.com, [email protected]
Abstract: A generic API for measuring aggregate, cross-site data in a privacy
preserving manner. The potentially identifying cross-site data is
encapsulated into <em>aggregatable reports</em>. To prevent leakage, this
data is encrypted, ensuring it can only be processed by an <em>aggregation
service</em>. During processing, this service will add noise and impose
limits on how many queries can be performed.
Markup Shorthands: markdown on
Complain About: accidental-2119 on, missing-example-ids on
Assume Explicit For: on
</pre>
<pre class="anchors">
urlPrefix: https://wicg.github.io/turtledove/; type: interface
text: InterestGroupBiddingScriptRunnerGlobalScope
text: InterestGroupScriptRunnerGlobalScope
text: InterestGroupScoringScriptRunnerGlobalScope
text: InterestGroupReportingScriptRunnerGlobalScope
urlPrefix: https://wicg.github.io/shared-storage/; type: interface
text: SharedStorageWorklet
text: SharedStorageWorkletGlobalScope
spec: hr-time; type: dfn; urlPrefix: https://w3c.github.io/hr-time/
text: current wall time; url: #dfn-current-wall-time
text: duration; url: #dfn-duration
text: duration from; url: #dfn-duration-from
text: moment; url: #dfn-moment
text: unix epoch; url: #dfn-unix-epoch
text: wall clock; url: #dfn-wall-clock
spec: html; type: dfn; urlPrefix: https://tc39.es/ecma262/
text: call; url: sec-call
spec: webdriver; urlPrefix: https://w3c.github.io/webdriver/
type: dfn
text: getting a property; url: dfn-getting-properties
text: error code; url: dfn-error-code
spec: fenced-frame; urlPrefix: https://wicg.github.io/fenced-frame/
type: dfn;
for: browsing context;
text: fenced frame config instance; url: browsing-context-fenced-frame-config-instance
</pre>
<pre class=link-defaults>
spec:infra; type:dfn; text:user agent
spec:webidl; type:dfn; text:attribute
</pre>
Introduction {#intro}
=====================
<em>This section is non-normative.</em>
Motivation {#motivation}
------------------------
Browsers are now working to prevent cross-site user tracking, including by
partitioning storage and removing third-party cookies. There are a range of API
proposals to continue supporting legitimate use cases in a way that respects
user privacy. Many of these APIs, including the
<a href="https://wicg.github.io/shared-storage/">Shared Storage API</a> and the
<a href="https://wicg.github.io/turtledove/">Protected Audience API</a>, isolate
potentially identifying cross-site data in special contexts, which ensures that
the data cannot escape the user agent.
Relative to cross-site data from an individual user, aggregate data about groups
of users can be less sensitive and yet would be sufficient for a wide range of
use cases. An aggregation service has been built to allow reporting noisy,
aggregated cross-site data. This service was originally created for use by the
<a href="https://wicg.github.io/attribution-reporting-api/">Attribution
Reporting API</a>, but allowing more general aggregation supports additional use
cases. In particular, the Protected Audience and Shared Storage APIs expect this
functionality to be available.
Overview {#overview}
--------------------
This document outlines a general-purpose API that can be called from isolated
contexts that have access to cross-site data (such as a Shared Storage worklet).
Within these contexts, potentially identifying data can be encapsulated into
"aggregatable reports". To prevent leakage, the cross-site data in these reports
is encrypted to ensure it can only be processed by the aggregation service.
During processing, this service adds noise and imposes limits on how many
queries can be performed.
This API provides functions that allow the origin to construct an aggregatable
report and specify the values to be embedded into its encrypted payload (for
later computation via the aggregation service). These calls result in the
aggregatable report being queued to be sent to the reporting endpoint of the
script's origin after a delay. After the endpoint receives the reports, it will
batch the reports and send them to the aggregation service for processing. The
output of that process is a summary report containing the (approximate) result,
which is dispatched back to the script's origin.
Alternative considered {#alternative-considered}
------------------------------------------------
Instead of the chosen API shape, we considered aligning with a design that is
much closer to {{WindowOrWorkerGlobalScope/fetch()}}. However, there are a few
key differences which make this unfavorable:
- This API is designed to be used in isolated contexts where
{{WindowOrWorkerGlobalScope/fetch()}} is not available.
- It's an anti-goal to give the developer control over when [=aggregatable
reports=] are being sent or knowledge that they were sent (outside of the
isolated context). Note, however, the exception when providing a context ID
from <em>outside</em> the isolated context, see [Protecting against leaks
via the number of
reports](#protecting-against-leaks-via-the-number-of-reports) below.
- The reports cannot be sent to arbitrary reporting endpoints, only a
particular <code>[[RFC8615|.well-known]]</code> path on the script origin.
- The report's input is very specific (an array of {{PAHistogramContribution}}s)
and is not amenable to {{WindowOrWorkerGlobalScope/fetch()}}'s general
purpose contents.
- There is no concept of a response.
So, we chose the more tailored API shape detailed below.
Exposed interface {#exposed-interface}
======================================
<xmp class="idl">
[Exposed=(InterestGroupScriptRunnerGlobalScope,SharedStorageWorklet),
SecureContext]
interface PrivateAggregation {
undefined contributeToHistogram(PAHistogramContribution contribution);
undefined contributeToHistogramOnEvent(DOMString event,
record<DOMString, any> contribution);
undefined enableDebugMode(optional PADebugModeOptions options = {});
};
dictionary PAHistogramContribution {
required bigint bucket;
required long value;
bigint filteringId = 0;
};
dictionary PADebugModeOptions {
required bigint debugKey;
};
</xmp>
Issue: Per the <a href=https://www.w3.org/TR/design-principles/#numeric-types>
Web Platform Design Principles</a>, we should consider switching `long` to
`[EnforceRange] long long`.
Issue: {{PrivateAggregation/enableDebugMode(options)}}'s argument should not
have a default value of `{}`. Alternatively, {{PADebugModeOptions/debugKey}}
should not be required in {{PADebugModeOptions}}.
Each {{PrivateAggregation}} object has the following fields:
<dl dfn-for="PrivateAggregation">
: <dfn export>scoping details</dfn> (default null)
:: A [=scoping details=] or null
: <dfn export>allowed to use</dfn> (default false)
:: A [=boolean=]
: <dfn export>should perform default contributeToHistogramOnEvent()
processing</dfn> (default an algorithm that always returns true)
:: An algorithm that takes a {{PrivateAggregation}}, {{DOMString}} and a [=map=]
(with {{DOMString}} keys) and returns either a [=boolean=] or an
[=exception=].
Note: This allows embedding APIs to override processing for all calls or
just certain ones. A return value of true indicates that this call will
be processed using the default implementation in this spec. A return
value that is an [=exception=] allows the embedding API's processing to
[=exception/throw=].
</dl>
Note: See [Exposing to global scopes](#exposing) below.
<div algorithm>
The <dfn method for="PrivateAggregation">
contributeToHistogram(PAHistogramContribution |contribution|)</dfn> method steps
are:
1. Let |validationResult| be the result of [=validating a histogram
contribution=] given |contribution| and [=this=]'s
[=PrivateAggregation/scoping details=].
1. If |validationResult| is an [=exception=], [=exception/throw=]
|validationResult|.
1. [=Assert=]: |validationResult| is a [=contribution cache entry=].
1. [=Append an entry to the contribution cache|Append=] |validationResult| to
the [=contribution cache=].
Issue(44): Consider accepting an array of contributions.
</div>
<div algorithm>
The <dfn method for="PrivateAggregation">contributeToHistogramOnEvent(|event|,
|contribution|)</dfn> method steps are:
1. Let |defaultProcessingResult| be the result of running [=this=]'s
[=PrivateAggregation/should perform default contributeToHistogramOnEvent()
processing=] given [=this=], |event| and |contribution|.
1. If |defaultProcessingResult| is an [=exception=], [=exception/throw=]
|defaultProcessingResult|.
1. If |defaultProcessingResult| is false, return.
1. Set |contribution| to the result of [=converted to an IDL value|converting=]
|contribution|'s [=converted to a JavaScript value|JavaScript value=] to the
IDL type {{PAHistogramContribution}}.
Note: This throws a {{TypeError}} if |contribution| is not compatible.
1. Let |validationResult| be the result of [=validating a histogram
contribution=] given |contribution| and [=this=]'s
[=PrivateAggregation/scoping details=].
1. If |validationResult| is an [=exception=], [=exception/throw=]
|validationResult|.
1. [=Assert=]: |validationResult| is a [=contribution cache entry=].
1. If |event| does not [=string/start with=] "<code>reserved.</code>",
[=exception/throw=] a {{TypeError}}.
1. Let |unprefixedEvent| be the [=code unit substring=] from
"<code>reserved.</code>"'s [=string/length=] to |event|'s [=string/length=]
within |event|.
1. If |unprefixedEvent| [=string/is=] any of the [=internal error events=]:
1. Let |maybeContributionCacheEntry|'s [=contribution cache entry/error
event=] be |unprefixedEvent|.
1. [=Append an entry to the contribution cache|Append=]
|maybeContributionCacheEntry| to the [=contribution cache=].
Note: For forward compatibility, we do not throw an error for unrecognized
events that [=string/start with=] "<code>reserved.</code>".
</div>
<div algorithm>
The <dfn method for="PrivateAggregation">
enableDebugMode(optional PADebugModeOptions options)</dfn> method steps are:
1. Let |scopingDetails| be [=this=]'s [=PrivateAggregation/scoping details=].
1. Let |debugScope| be the result of running |scopingDetails|' [=scoping
details/get debug scope steps=].
1. If [=debug scope map=][|debugScope|] [=map/exists=], [=exception/throw=] a
"{{DataError}}" {{DOMException}}.
Note: This would occur if `enableDebugMode()` has already been run for this
[=debug scope=].
1. Let |debugKey| be null.
1. If |options| was given:
1. If |options|["{{PADebugModeOptions/debugKey}}"] is not [=set/contained=]
in [=the exclusive range|the range=] 0 to 2<sup>64</sup>, exclusive,
[=exception/throw=] a "{{DataError}}" {{DOMException}}.
1. Set |debugKey| to |options|["{{PADebugModeOptions/debugKey}}"].
1. Let |debugDetails| be a new [=debug details=] with the items:
: [=debug details/enabled=]
:: true
: [=debug details/key=]
:: |debugKey|
1. Optionally, set |debugDetails| to a new [=debug details=].
Note: This allows the user agent to make debug mode unavailable globally or
just for certain callers.
1. [=map/Set=] [=debug scope map=][|debugScope|] to |debugDetails|.
Issue: Ensure errors are of an appropriate type, e.g. {{InvalidAccessError}} is
deprecated.
</div>
Exposing to global scopes {#exposing}
=====================================
To expose this API to a global scope, a [=read only=] [=attribute=]
`privateAggregation` of type {{PrivateAggregation}} should be exposed on the
global scope. Its [=getter steps=] should be set to the [=get the
privateAggregation=] steps given [=this=].
Each global scope should set the [=PrivateAggregation/allowed to use=] for the
{{PrivateAggregation}} object it exposes based on whether a relevant
[=document=] is [=allowed to use=] the "<code>[=private-aggregation=]</code>"
[=policy-controlled feature=].
Additionally, each global scope should set the [=PrivateAggregation/scoping
details=] for the {{PrivateAggregation}} object it exposes to a non-null value.
The global scope should wait to set the field until the API is intended to be
available.
<div class="example" id="shared-storage-only-within-operations">
Shared Storage only allows Private Aggregation when an operation is being
invoked, not in the top-level context:
<pre highlight="js">
class ExampleOperation {
async run(data) {
privateAggregation.contributeToHistogram(...) // This is allowed.
}
}
register('example-operation', ExampleOperation);
privateAggregation.contributeToHistogram(...) // This would cause an error.
</pre>
So, Shared Storage sets the [=PrivateAggregation/scoping details=]
immediately after the initial execution of the module script is complete.
</div>
For any [=batching scope=] returned by the [=scoping details/get batching scope
steps=], the [=process contributions for a batching scope=] steps should later
be performed given that same batching scope, the global scope's [=relevant
settings object=]'s [=environment settings object/origin=], some [=context
type=] and a timeout (or null).
Note: This last requirement means that global scopes with different origins
cannot share the same batching scope, see [Same-origin
policy](#same-origin-policy) discussion.
For any [=debug scope=] returned by the [=scoping details/get debug scope
steps=], the [=mark a debug scope complete=] steps should later be performed
given that same [=debug scope=].
Note: A later algorithm [=asserts=] that, for any [=contribution cache entry=]
in the [=contribution cache=], the [=mark a debug scope complete=] steps
were performed given the entry's [=contribution cache entry/debug scope=]
before the [=process contributions for a batching scope=] steps are
performed given the entry's [=contribution cache entry/batching scope=].
Overriding `contributeToHistogramOnEvent()` processing {#contributetohistogramonevent}
--------------------------------------------------------------------------------------
Each API may also set the [=PrivateAggregation/should perform default
contributeToHistogramOnEvent() processing=] algorithm for the
{{PrivateAggregation}} object it exposes. This hook enables the embedding API to
override processing for any {{PrivateAggregation/
contributeToHistogramOnEvent()}} call it wants to.
This algorithm should return true to indicate that the regular processing
defined in this spec should occur (for that call). It should return an
[=exception=] to indicate an error has occurred in the embedding API's
processing. Alternatively, it should return false to indicate that the embedding
API will process the call, but no [=exception=] should be [=exception/thrown=].
If the embedding API overrides processing for a call (i.e. the algorithm does
not return true), it should accept any `event` that is a [=string/
concatenation=] of « "<code>reserved.</code>", |errorEvent| » where |errorEvent|
is an [=internal error event=] and should accept any `contribution` with a
[=converted to a JavaScript value|JavaScript value=] that is [=converted to an
IDL value|convertible=] to the IDL type {{PAHistogramContribution}}. That is, it
should not return an [=exception=] in those cases. However, the embedding API
may accept additional `event`s or `contribution`s that would not be accepted by
the default processing defined in this spec.
If the embedding API overrides processing for a call specifying a contribution
conditional on an [=internal error event=], the embedding API should call
[=append an entry to the contribution cache=] with the appropriate entry unless
it intends to drop that contribution.
If the embedding API overrides processing for a call to support additional error
events, it must wait until the associated condition has been determined to have
occurred or not. If the custom error event was triggered, it should use
<code>[=already triggered external error=]</code> as the [=contribution cache
entry/error event=] for the associated contributions. If the custom error event
was not triggered, the contributions should be dropped and no call to [=append
an entry to the contribution cache=] should be made for those contributions.
Note also that, if the embedding API overrides processing, it must convert
`contribution` to the IDL type {{PAHistogramContribution}} before it is able to
call [=append an entry to the contribution cache=]. This applies whether the
`contribution` has a [=converted to a JavaScript value|JavaScript value=] that
is automatically [=converted to an IDL value|convertible=] to the IDL type or
not.
APIs exposing Private Aggregation {#apis-exposing-private-aggregation}
----------------------------------------------------------------------
<em>This section is non-normative.</em>
This API is currently exposed in global scopes defined in the specifications of
two APIs:
1. <a href="https://wicg.github.io/shared-storage/">Shared Storage</a> and
1. <a href="https://wicg.github.io/turtledove/">Protected Audience</a>.
Structures {#structures}
========================
<h3 dfn-type=dfn export>Batching scope</h3>
A batching scope is a <a spec=HTML>unique internal value</a> that identifies
which {{PAHistogramContribution}}s should be sent in the same [=aggregatable
report=] unless their [=aggregatable report/debug details=] differ.
Issue: Unique internal value is not an exported definition. See
<a href="https://github.com/whatwg/infra/issues/583">infra/583</a>.
<h3 dfn-type=dfn export>Debug scope</h3>
A debug scope is a <a spec=HTML>unique internal value</a> that identifies which
{{PAHistogramContribution}}s should have their [=debug details=] affected by the
presence or absence of a call to {{PrivateAggregation/enableDebugMode()}} in the
same period of execution.
<h3 dfn-type=dfn export>Scoping details</h3>
A scoping details is a [=struct=] with the following items:
<dl dfn-for="scoping details">
: <dfn export>get batching scope steps</dfn>
:: An algorithm returning a [=batching scope=]
: <dfn export>get debug scope steps</dfn>
:: An algorithm returning a [=debug scope=]
</dl>
<h3 dfn-type=dfn>Debug details</h3>
A debug details is a [=struct=] with the following items:
<dl dfn-for="debug details">
: <dfn>enabled</dfn> (default false)
:: A [=boolean=]
: <dfn>key</dfn> (default null)
:: An unsigned 64-bit integer or null. The key must be null if [=debug
details/enabled=] is false.
</dl>
<h3 id="error-events-heading">Error events</h3>
An <dfn export>internal error event</dfn> is one of the following:
<dl dfn-for="internal error event">
: "<dfn><code>report-success</code></dfn>"
:: The report was scheduled and no contributions were dropped.
: "<dfn><code>too-many-contributions</code></dfn>"
:: The report was scheduled, but some contributions were dropped due to the
per-report limit.
: "<dfn><code>empty-report-dropped</code></dfn>"
:: The report was not scheduled as it had no contributions.
: "<dfn><code>pending-report-limit-reached</code></dfn>"
:: The report was scheduled, but the limit of pending reports was reached. That
is, attempting to schedule one more report would fail due to the limit.
: "<dfn><code>insufficient-budget</code></dfn>"
:: One or more contributions in the report were dropped (or the
whole report was) as there was not enough contribution budget.
: "<dfn><code>contribution-timeout-reached</code></dfn>"
:: The context(s) associated with the report was still running when
the contribution timeout occurred.
</dl>
An <dfn export>error event</dfn> is an [=internal error event=] or the special
value <dfn export><code>already triggered external error</code></dfn>.
Note: This special value represents any external error event that has already
occurred. External error events are defined by embedding APIs and are
distinct from [=internal error events=]. See
[contributeToHistogramOnEvent()](#contributetohistogramonevent) for more
details.
<dfn>All error events</dfn> is a [=list=] of [=error events=] that consists of
all the [=internal error events=] in the order they are defined above followed
by <code>[=already triggered external error=]</code>.
<h3 dfn-type=dfn export>Contribution cache entry</h3>
A contribution cache entry is a [=struct=] with the following items:
<dl dfn-for="contribution cache entry">
: <dfn export>contribution</dfn>
:: A {{PAHistogramContribution}}
: <dfn export>error event</dfn> (default null)
:: An [=error event=] or null.
Note: This indicates which [=error event=] the contribution is conditional
on, or null if the contribution is unconditional.
: <dfn export>batching scope</dfn>
:: A [=batching scope=]
: <dfn export>debug scope</dfn>
:: A [=debug scope=]
: <dfn export>debug details</dfn> (default null)
:: A [=debug details=] or null
</dl>
<h3 dfn-type=dfn>Pending contributions</h3>
A pending contributions is a [=struct=] with the following items:
<dl dfn-for="pending contributions">
: <dfn>unconditional contributions</dfn> (default: a new [=list=])
:: A [=list=] of {{PAHistogramContribution}}s
: <dfn>conditional contributions</dfn> (default: a new [=map=])
:: A [=map=] where its [=map/keys=] are [=error events=] and [=map/values=] are
[=lists=] of {{PAHistogramContribution}}s
: <dfn>triggered error events</dfn> (default: a new [=set=])
:: A [=set=] of [=internal error events=]
</dl>
<h3 dfn-type=dfn>Aggregatable report</h3>
An aggregatable report is a [=struct=] with the following items:
<dl dfn-for="aggregatable report">
: <dfn>reporting origin</dfn>
:: An [=origin=]
: <dfn>original report time</dfn>
:: A [=moment=]
: <dfn>report time</dfn>
:: A [=moment=]
: <dfn>contributions</dfn>
:: A [=list=] of {{PAHistogramContribution}}s
: <dfn>api</dfn>
:: A [=context type=]
: <dfn>report ID</dfn>
:: A [=string=]
: <dfn>debug details</dfn>
:: A [=debug details=]
: <dfn>aggregation coordinator</dfn>
:: An [=aggregation coordinator=]
: <dfn>context ID</dfn>
:: A [=string=] or null
: <dfn>filtering ID max bytes</dfn>
:: A positive integer
: <dfn>max contributions</dfn>
:: A positive integer
: <dfn>queued</dfn>
:: A [=boolean=]
</dl>
Aggregation coordinator {#aggregation-coordinator-structure}
------------------------------------------------------------
An <dfn export>aggregation coordinator</dfn> is an [=origin=] that the [=allowed
aggregation coordinator set=] [=set/contains=].
Issue: Consider switching to the <a spec="attribution-reporting-api">suitable
origin</a> concept used by the Attribution Reporting API here and elsewhere.
Issue: Move other structures to be defined inline instead of via a header.
Consider also removing all the subheadings.
<h3 dfn-type=dfn>Context type</h3>
A context type is a [=string=] indicating what kind of global scope the
{{PrivateAggregation}} object was exposed in. Each API exposing Private
Aggregation should pick a unique string (or multiple) for this.
Pre-specified report parameters {#pre-specified-report-parameters-structure}
----------------------------------------------------------------------------
A <dfn export>pre-specified report parameters</dfn> is a [=struct=] with the
following items:
<dl dfn-for="pre-specified report parameters">
: <dfn export>context ID</dfn> (default: null)
:: A [=string=] or null
: <dfn export>filtering ID max bytes</dfn> (default: [=default filtering ID max
bytes=])
:: A positive integer
: <dfn export>max contributions</dfn> (default: null)
:: A positive integer or null
</dl>
Storage {#storage}
==================
A [=user agent=] holds an <dfn>aggregatable report cache</dfn>, which is a
[=list=] of [=aggregatable reports=].
A [=user agent=] holds an <dfn>aggregation coordinator map</dfn>, which is a
[=map=] from [=batching scopes=] to [=aggregation coordinators=].
A [=user agent=] holds a <dfn>pre-specified report parameters map</dfn>, which
is a [=map=] from [=batching scopes=] to [=pre-specified report parameters=].
A [=user agent=] holds a <dfn>contribution cache</dfn>, which is a [=list=] of
[=contribution cache entries=].
A [=user agent=] holds a <dfn>debug scope map</dfn>, which is a [=map=] from
[=debug scopes=] to [=debug details=].
Issue: Elsewhere, link to definition when using [=user agent=].
Clearing storage {#clearing-storage}
----------------------------------------
The user agent must expose controls that allow the user to delete data from
the [=aggregatable report cache=] as well as any contribution history data
stored for the [=query the budget=] algorithm.
The user agent may expose controls that allow the user to delete data from the
[=contribution cache=], the [=debug scope map=] and the [=pre-specified report
parameters map=].
Constants {#constants}
======================
<dfn export>Default filtering ID max bytes</dfn> is a positive integer
controlling the max bytes used if none is explicitly chosen. Its value is 1.
<dfn export>Valid filtering ID max bytes range</dfn> is a [=set=] of positive
integers controlling the allowable values of max bytes. Its value is [=the
inclusive range|the range=] 1 to 8, inclusive.
Issue: Consider adding more constants.
[=Implementation-defined=] values {#implementation-defined-values}
==================================================================
<dfn>Allowed aggregation coordinator set</dfn> is a [=set=] of [=origins=] that
controls which [=origins=] are valid [=aggregation coordinators=]. Every
[=set/item=] in this [=set=] must be a [=potentially trustworthy origin=].
<dfn>Default aggregation coordinator</dfn> is an [=aggregation coordinator=]
that controls which is used for a report if none is explicitly selected.
<dfn>Maximum maxContributions</dfn> is a positive integer that defines an upper
bound on the number of contributions per [=aggregatable report=].
<dfn>Default maxContributions by API</dfn> is a [=map=] from [=context types=]
to positive integers. Semantically, it defines the default number of
contributions per report for every kind of calling context, e.g. Shared Storage.
The values in this map are used when callers do not specifically request another
value. Each value in this map must be less than or equal to [=maximum
maxContributions=].
<dfn>Minimum report delay</dfn> is a non-negative [=duration=] that controls the
minimum delay to deliver an [=aggregatable report=].
<dfn>Randomized report delay</dfn> is a positive [=duration=] that controls the
random delay to deliver an [=aggregatable report=]. This delay is additional to
the [=minimum report delay=].
Permissions Policy integration {#permissions-policy-integration}
================================================================
This specification defines a [=policy-controlled feature=] identified by the
string "<code><dfn export>private-aggregation</dfn></code>". Its
[=policy-controlled feature/default allowlist=] is "`*`".
Note: The [=PrivateAggregation/allowed to use=] field is set by other
specifications that integrate with this API according to this
[=policy-controlled feature=].
Algorithms {#algorithms}
====================
To <dfn>serialize an integer</dfn>, represent it as a [=string=] of the shortest
possible decimal number.
Issue: This would ideally be replaced by a more descriptive algorithm in Infra.
See <a href="https://github.com/whatwg/infra/issues/201">infra/201</a>.
Exported algorithms {#exported-algorithms}
------------------------------------------
Note: These algorithms allow other specifications to integrate with this API.
<div algorithm>
To <dfn export>get the privateAggregation</dfn> given a
{{PrivateAggregation}} |this|:
1. Let |scopingDetails| be |this|'s [=PrivateAggregation/scoping details=].
1. If |scopingDetails| is null, [=exception/throw=] a "{{NotAllowedError}}"
{{DOMException}}.
Note: This indicates the API is not yet available, for example, because the
initial execution of the script after loading is not complete.
Issue: Consider improving developer ergonomics here (e.g. a way to detect
this case).
1. If |this|'s [=PrivateAggregation/allowed to use=] is false, [=exception/
throw=] an "{{InvalidAccessError}}" {{DOMException}}.
1. Return |this|.
Issue: Ensure errors are of an appropriate type, e.g. {{InvalidAccessError}} is
deprecated.
</div>
<div algorithm>
To <dfn export>append an entry to the contribution cache</dfn> given a
[=contribution cache entry=] |entry|:
1. [=list/Append=] |entry| to the [=contribution cache=].
</div>
<div algorithm>
To <dfn export>get a debug details</dfn> given a [=debug scope=]
|debugScope|, perform the following steps. They return a [=debug details=].
1. If [=debug scope map=][|debugScope|] [=map/exists=], return
[=debug scope map=][|debugScope|].
1. Otherwise, return a new [=debug details=].
</div>
<div algorithm>
To <dfn export>mark a debug scope complete</dfn> given a [=debug
scope=] |debugScope| and an optional [=debug details=] or null
|debugDetailsOverride| (default null):
1. Let |debugDetails| be |debugDetailsOverride|.
1. If [=debug scope map=][|debugScope|] [=map/exists=]:
1. [=Assert=]: |debugDetailsOverride| is null.
Note: The override can be provided if the debug details have not been
set otherwise.
1. Set |debugDetails| to [=debug scope map=][|debugScope|].
1. [=map/Remove=] [=debug scope map=][|debugScope|].
1. If |debugDetails|'s [=debug details/key=] is not null, [=assert=]:
|debugDetails|'s [=debug details/enabled=] is true.
1. If |debugDetails| is null, set |debugDetails| to a new [=debug details=].
1. [=list/iterate|For each=] |entry| of the [=contribution cache=]:
1. If |entry|'s [=contribution cache entry/debug scope=] is |debugScope|,
set |entry|'s [=contribution cache entry/debug details=] to
|debugDetails|.
</div>
<div algorithm>
To <dfn export>determine if a report should be sent deterministically</dfn>
given a [=pre-specified report parameters=] |preSpecifiedParams| and a [=context
type=] |api|, perform the following steps. They return a [=boolean=]:
1. If |preSpecifiedParams|' [=pre-specified report parameters/context ID=] is
not null, return true.
1. If |preSpecifiedParams|' [=pre-specified report parameters/filtering ID max
bytes=] is not the [=default filtering ID max bytes=], return true.
1. Let |effectiveMaxContributions| be the result of [=determining the max
contributions=] with |api| and |preSpecifiedParams|' [=pre-specified report
parameters/max contributions=].
1. Let |defaultMaxContributions| be [=default maxContributions by API=][|api|].
1. If |effectiveMaxContributions| is not |defaultMaxContributions|, return true.
1. Return false.
Note: It is sometimes necessary to send a 'null report' to conceal the fact that
there were no contributions. For instance, it's possible that budget, which is
cross-site data in its own right, was insufficient for the requested
contributions. Alternatively, the caller might have chosen to make no
contributions after reading cross-site data. In these kinds of scenarios, the
absence of a report could reveal cross-site data to the reporting endpoint. See
[Protecting against leaks via the number of
reports](#protecting-against-leaks-via-the-number-of-reports).
</div>
<div algorithm>
To <dfn export>process contributions for a batching scope</dfn> given
a [=batching scope=] |batchingScope|, an [=origin=] |reportingOrigin|, a
[=context type=] |contextType| and a [=moment=] or null |timeout|:
Note: Embedding APIs are expected to set |timeout| to null if a report isn't
[=determine if a report should be sent deterministically|deterministic=] or
if the timeout was already reached, i.e. if it caused this call to be
triggered. (A timeout always has to be set for [=determine if a report
should be sent deterministically|deterministic=] reports.)
1. Let |batchEntries| be a new [=list=].
1. [=list/iterate|For each=] |entry| of the [=contribution cache=]:
1. If |entry|'s [=contribution cache entry/batching scope=] is
|batchingScope|:
1. [=Assert=]: |entry|'s [=contribution cache entry/debug details=] is
not null.
Note: This asserts that the [=mark a debug scope complete=] steps
were run before the [=process contributions for a batching
scope=] steps.
1. [=list/Append=] |entry| to |batchEntries|.
1. Let |aggregationCoordinator| be the [=default aggregation coordinator=].
1. If [=aggregation coordinator map=][|batchingScope|] [=map/exists=]:
1. Set |aggregationCoordinator| to [=aggregation coordinator
map=][|batchingScope|].
1. [=map/Remove=] [=aggregation coordinator map=][|batchingScope|].
1. Let |preSpecifiedParams| be a new [=pre-specified report parameters=].
1. If [=pre-specified report parameters map=][|batchingScope|] [=map/exists=]:
1. Set |preSpecifiedParams| to [=pre-specified report parameters
map=][|batchingScope|].
1. [=map/Remove=] [=pre-specified report parameters map=][|batchingScope|].
1. Let |isDeterministicReport| be the result of [=determining if a report should
be sent deterministically=] given |preSpecifiedParams| and |contextType|.
1. If |isDeterministicReport| is false, [=assert=]: |timeout| is null.
Note: Timeouts can only be used for deterministic reports.
1. If |batchEntries| [=list/is empty=] and |isDeterministicReport| is false,
return.
1. Let |batchedContributions| be a new [=ordered map=].
1. [=list/iterate|For each=] |entry| of |batchEntries|:
1. [=list/Remove=] |entry| from the [=contribution cache=].
1. Let |debugDetails| be |entry|'s [=contribution cache entry/debug
details=].
1. If |batchedContributions|[|debugDetails|] does not [=map/exist=], [=map/
set=] |batchedContributions|[|debugDetails|] to a new [=pending
contributions=].
1. If |entry|'s [=contribution cache entry/error event=] is null:
1. [=list/Append=] |entry|'s [=contribution cache entry/contribution=]
to |batchedContributions|[|debugDetails|]'s [=pending contributions/
unconditional contributions=].
1. Otherwise:
1. Let |conditionalContributions| be
|batchedContributions|[|debugDetails|]'s [=pending contributions/
conditional contributions=].
1. If |conditionalContributions|[|errorEvent|] does not [=map/exist=],
[=map/set=] |conditionalContributions|[|errorEvent|] to a new
[=list=].
1. [=list/Append=] |entry|'s [=contribution cache entry/contribution=]
to |conditionalContributions|[|errorEvent|].
1. If |batchedContributions| [=map/is empty=]:
1. Let |debugDetails| be a new [=debug details=].
1. Set |batchedContributions|[|debugDetails|] to a new [=pending
contributions=].
1. [=map/iterate|For each=] |debugDetails| → |pendingContributions| of
|batchedContributions|:
1. Perform the [=report creation and scheduling steps=] with
|reportingOrigin|, |contextType|, |pendingContributions|,
|debugDetails|, |aggregationCoordinator|, |preSpecifiedParams| and
|timeout|.
Note: These steps break up the contributions based on their [=debug details=] as
each report can only have one set of metadata.
</div>
<div algorithm>
To <dfn export>determine if an origin is an aggregation coordinator</dfn> given
an [=origin=] |origin|, perform the following steps. They return a [=boolean=].
1. Return whether |origin| is an [=aggregation coordinator=].
</div>
<div algorithm>
To <dfn export>obtain the Private Aggregation coordinator</dfn> given a
{{USVString}} |originString|, perform the following steps. They return an
[=aggregation coordinator=] or a {{DOMException}}.
1. Let |url| be the result of running the [=URL parser=] on |originString|.
1. If |url| is failure or null, return a new {{DOMException}} with name
"`SyntaxError`".
Issue: Consider throwing an error if the path is not empty.
1. Let |origin| be |url|'s [=url/origin=].
1. If the result of [=determining if an origin is an aggregation coordinator=]
given |origin| is false, return a new {{DOMException}} with name
"`DataError`".
1. Return |origin|.
</div>
<div algorithm>
To <dfn export>set the aggregation coordinator for a batching scope</dfn> given
an [=origin=] |origin| and a [=batching scope=] |batchingScope|:
1. [=Assert=]: |origin| is an [=aggregation coordinator=].
1. [=map/Set=] [=aggregation coordinator map=][|batchingScope|] to |origin|.
</div>
Issue: Elsewhere, surround algorithms in a `<div algorithm>` block to match, and
add styling for all algorithms per
[bikeshed/1472](https://github.com/speced/bikeshed/issues/1472).
<div algorithm>
To <dfn export>set the pre-specified report parameters for a batching
scope</dfn> given a [=pre-specified report parameters=] |params| and a
[=batching scope=] |batchingScope|:
1. Let |contextId| be |params|' [=pre-specified report parameters/context ID=].
1. [=Assert=]: |contextId| is null or |contextId|'s [=string/length=] is not
larger than 64.
1. Let |filteringIdMaxBytes| be |params|' [=pre-specified report parameters/
filtering ID max bytes=].
1. [=Assert=]: |filteringIdMaxBytes| is [=set/contained=] in the [=valid
filtering ID max bytes range=]
1. Let |maxContributions| be |params|' [=pre-specified report parameters/max
contributions=].
1. [=Assert=]: |maxContributions| is null or greater than zero.
1. [=map/Set=] [=pre-specified report parameters map=][|batchingScope|] to
|params|.
</div>
<div algorithm>
To <dfn export>validate a histogram contribution</dfn> given a
{{PAHistogramContribution}} |contribution| and a [=scoping details=]
|scopingDetails|, perform the following steps. They return a [=contribution
cache entry=] or an [=exception=].
1. If |contribution|["{{PAHistogramContribution/bucket}}"] is not [=set/
contained=] in [=the exclusive range|the range=] 0 to 2<sup>128</sup>,
exclusive, return a {{RangeError}}.
1. If |contribution|["{{PAHistogramContribution/value}}"] is negative, return a
{{RangeError}}.
1. Let |batchingScope| be the result of running |scopingDetails|' [=scoping
details/get batching scope steps=].
1. Let |filteringIdMaxBytes| be the [=default filtering ID max bytes=].
1. If [=pre-specified report parameters map=][|batchingScope|] [=map/exists=]:
1. Set |filteringIdMaxBytes| to [=pre-specified report parameters
map=][|batchingScope|]'s [=pre-specified report parameters/filtering ID
max bytes=].
1. If |contribution|["{{PAHistogramContribution/filteringId}}"] is not [=set/
contained=] in [=the exclusive range|the range=] 0 to
256<sup>|filteringIdMaxBytes|</sup>, exclusive, return a {{RangeError}}.
1. Return a new [=contribution cache entry=] with the items:
: [=contribution cache entry/contribution=]
:: |contribution|
: [=contribution cache entry/batching scope=]
:: |batchingScope|
: [=contribution cache entry/debug scope=]
:: The result of running |scopingDetails|' [=scoping details/get debug scope
steps=].
Issue: Ensure errors are of an appropriate type, e.g. {{InvalidAccessError}} is
deprecated.
</div>
Scheduling reports {#scheduling-reports}
----------------------------------------
<div algorithm>
To perform the <dfn>report creation and scheduling steps</dfn> with an
[=origin=] |reportingOrigin|, a [=context type=] |api|, a [=pending
contributions=] |pendingContributions|, a [=debug details=] |debugDetails|, an
[=aggregation coordinator=] |aggregationCoordinator|, a [=pre-specified report
parameters=] |preSpecifiedParams| and a [=moment=] or null |timeout|:
1. [=Assert=]: |reportingOrigin| is a [=potentially trustworthy origin=].
1. Optionally, return.
Note: This [=implementation-defined=] condition is intended to allow [=user
agents=] to drop reports for a number of reasons, for example user
opt-out, an origin not being
<a href="https://github.com/privacysandbox/attestation">enrolled</a> or
a limit on pending reports being reached.
1. Let |currentWallTime| be the [=current wall time=].
1. Let |allUnmergedContributions| be the result of [=compiling all unmerged
contributions=], given |reportingOrigin|, |api|, |pendingContributions|,
|preSpecifiedParams|, |timeout| and |currentWallTime|.
1. Let |isDeterministicReport| be the result of [=determining if a report
should be sent deterministically=] given |preSpecifiedParams| and |api|.
1. Let |effectiveMaxContributions| be the result of [=determining the max
contributions=] with |api| and |preSpecifiedParams|' [=pre-specified
report parameters/max contributions=].
1. Let |keptMergeKeys| be a new [=set=].
1. [=list/For each=] |contribution| of |allUnmergedContributions|:
1. Let |mergeKey| be |contribution|'s [=merge key=].
1. If |keptMergeKeys|' [=list/size=] is |effectiveMaxContributions| and
|keptMergeKeys| does not [=list/contain=] |mergeKey|, [=iteration/
continue=].
1. Otherwise, [=set/append=] |mergeKey| to |keptMergeKeys|.
1. [=list/Remove=] all items that have a [=merge key=] that is not [=list/
contained=] in |keptMergeKeys| from |allUnmergedContributions|.
1. Let |finalBudgetResults| be the result of [=querying the budget=] given
|allUnmergedContributions|, |reportingOrigin|, |api|, |currentWallTime| and
true.
1. [=Assert=]: |finalBudgetResults|' [=list/size=] equals
|allUnmergedContributions|' [=list/size=].
1. [=set/For each=] |i| of [=the exclusive range|the range=] 0 to
|finalBudgetResults|' [=list/size=], exclusive:
1. If |finalBudgetResults|[|i|] is false, set
|allUnmergedContributions|[i]'s {{PAHistogramContribution/value}} to 0.
1. [=list/Remove=] all items from |allUnmergedContributions| that have a
{{PAHistogramContribution/value}} of 0.
1. Let |mergedContributionsMap| be a new [=ordered map=].
1. [=list/For each=] |contribution| of |allUnmergedContributions|:
1. Let |mergeKey| be |contribution|'s [=merge key=].
1. If |mergedContributionsMap|[|mergeKey|] [=map/exists=], add
|contribution|'s {{PAHistogramContribution/value}} to
|mergedContributionsMap|[|mergeKey|]'s {{PAHistogramContribution/
value}}.
1. Otherwise, [=map/set=] |mergedContributionsMap|[|mergeKey|] to
|contribution|.
1. Let |mergedContributions| be the |mergedContributionsMap|'s [=map/values=].
1. [=Assert=]: |mergedContributions| has a [=list/size=] less than or equal to
|effectiveMaxContributions|,
1. If |mergedContributions| [=list/is empty=] and |isDeterministicReport| is
false, return.
1. Let |report| be the result of [=obtaining an aggregatable report=] given
|reportingOrigin|, |api|, |mergedContributions|, |debugDetails|,
|aggregationCoordinator|, |preSpecifiedParams|, |timeout| and
|currentWallTime|.
1. [=set/Append=] |report| to the user agent's [=aggregatable report cache=].
</div>
<div algorithm>
To <dfn>compile all unmerged contributions</dfn> given an [=origin=]
|reportingOrigin|, a [=context type=] |api|, a [=pending contributions=]
|pendingContributions|, a [=pre-specified report parameters=]
|preSpecifiedParams|, a [=moment=] or null |timeout|, and a [=moment=]
|currentWallTime|, perform the following steps. They return a [=list=] of
{{PAHistogramContribution}}s.
1. Let |wasTimeoutReached| be the [=boolean=] indicating whether both
|isDeterministicReport| is true and |timeout| is null.
Issue: Update the timeout being sent from Shared Storage to align.
1. [=Record the internal error event result=] given |pendingContributions|,
"<code>[=internal error event/contribution-timeout-reached=]</code>" and
|wasTimeoutReached|.
1. Let |provisionalBudgetResults| be the result of [=querying the budget=] given
|pendingContributions|' [=pending contributions/unconditional
contributions=], |reportingOrigin|, |api|, |currentWallTime| and false.
1. [=Assert=]: |provisionalBudgetResults|' [=list/size=] equals
|pendingContributions|' [=pending contributions/unconditional
contributions=]' [=list/size=].
1. [=set/For each=] |i| of [=the exclusive range|the range=] 0 to
|provisionalBudgetResults|' [=list/size=], exclusive:
1. If |provisionalBudgetResults|[|i|] is false, set |pendingContributions|'
[=pending contributions/unconditional contributions=][|i|]'s
{{PAHistogramContribution/value}} to 0.
1. [=list/Remove=] all items from |pendingContributions|' [=pending
contributions/unconditional contributions=] that have a
{{PAHistogramContribution/value}} of 0.
1. Let |insufficientBudget| be a [=boolean=] indicating whether any value in
|provisionalBudgetResults| is false.
1. [=Record the internal error event result=] given |pendingContributions|,
"<code>[=internal error event/insufficient-budget=]</code>" and
|insufficientBudget|.
1. Let |pendingReportLimitReached| be a [=boolean=] determined by an
[=implementation-defined=] algorithm.