Skip to content

Commit 8050937

Browse files
committed
Add permissions policies and remove worker support
Closes #18. Closes #25.
1 parent ed23184 commit 8050937

File tree

3 files changed

+28
-8
lines changed

3 files changed

+28
-8
lines changed

README.md

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -303,6 +303,18 @@ Another way in which this API might enhance the web's fingerprinting surface is
303303

304304
Finally, we intend to prohibit (in the specification) any use of user-specific information in producing the results. For example, it would not be permissible to fine-tune the translation model based on information the user has entered into the browser in the past.
305305

306+
### Permissions policy, iframes, and workers
307+
308+
By default, these APIs are only available to top-level `Window`s, and to their same-origin iframes. Access to the APIs can be delegated to cross-origin iframes using the [Permissions Policy](https://developer.mozilla.org/en-US/docs/Web/HTTP/Permissions_Policy) `allow=""` attribute:
309+
310+
```html
311+
<iframe src="https://example.com/" allow="translator language-detector"></iframe>
312+
```
313+
314+
These APIs are currently not available in workers, due to the complexity of establishing a responsible document for each worker in order to check the permissions policy status. See [this discussion](https://github.com/webmachinelearning/translation-api/issues/18#issuecomment-2705630392) for more. It may be possible to loosen this restriction over time, if use cases arise.
315+
316+
Note that although the APIs are not exposed to web platform workers, a browser could expose them to extension service workers, which are outside the scope of web platform specifications and have a different permissions model.
317+
306318
## Alternatives considered and under consideration
307319

308320
### Streaming input support

index.bs

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ For now, see the [explainer](https://github.com/webmachinelearning/translation-a
4141
<h2 id="translator-api">The translator API</h2>
4242

4343
<xmp class="idl">
44-
[Exposed=(Window,Worker), SecureContext]
44+
[Exposed=Window, SecureContext]
4545
interface Translator {
4646
static Promise<Translator> create(TranslatorCreateOptions options);
4747
static Promise<Availability> availability(TranslatorCreateCoreOptions options);
@@ -86,7 +86,7 @@ dictionary TranslatorTranslateOptions {
8686
<div algorithm>
8787
The static <dfn method for="Translator">create(|options|)</dfn> method steps are:
8888

89-
1. Return the result of [=creating an AI model object=] given |options|, [=validate and canonicalize translator options=], [=compute translator options availability=], [=download the translation model=], [=initialize the translation model=], and [=create the translator object=].
89+
1. Return the result of [=creating an AI model object=] given |options|, "{{translator}}", [=validate and canonicalize translator options=], [=compute translator options availability=], [=download the translation model=], [=initialize the translation model=], and [=create the translator object=].
9090
</div>
9191

9292
<div algorithm>
@@ -151,7 +151,7 @@ dictionary TranslatorTranslateOptions {
151151
<div algorithm>
152152
The static <dfn method for="Translator">availability(|options|)</dfn> method steps are:
153153

154-
1. Return the result of [=computing AI model availability=] given |options|, [=validate and canonicalize translator options=], and [=compute translator options availability=].
154+
1. Return the result of [=computing AI model availability=] given |options|, "{{translator}}", [=validate and canonicalize translator options=], and [=compute translator options availability=].
155155
</div>
156156

157157
<div algorithm>
@@ -451,10 +451,14 @@ When translation fails, the following possible reasons may be surfaced to the we
451451

452452
<p class="note">This table does not give the complete list of exceptions that can be surfaced by the translator API. It only contains those which can come from certain [=implementation-defined=] steps.
453453

454+
<h3 id="translator-permissions-policy">Permissions policy integration</h3>
455+
456+
Access to the translator API is gated behind the [=policy-controlled feature=] "<dfn permission>translator</dfn>", which has a [=policy-controlled feature/default allowlist=] of <code>[=default allowlist/'self'=]</code>.
457+
454458
<h2 id="language-detector-api">The language detector API</h2>
455459

456460
<xmp class="idl">
457-
[Exposed=(Window,Worker), SecureContext]
461+
[Exposed=Window, SecureContext]
458462
interface LanguageDetector {
459463
Promise<LanguageDetector> create(
460464
optional LanguageDetectorCreateOptions options = {}
@@ -502,7 +506,7 @@ dictionary LanguageDetectionResult {
502506
<div algorithm>
503507
The static <dfn method for="LanguageDetector">create(|options|)</dfn> method steps are:
504508

505-
1. Return the result of [=creating an AI model object=] given |options|, [=validate and canonicalize language detector options=], [=compute language detector options availability=], [=download the language detector model=], [=initialize the language detector model=], and [=create the language detector object=].
509+
1. Return the result of [=creating an AI model object=] given |options|, "{{language-detector}}", [=validate and canonicalize language detector options=], [=compute language detector options availability=], [=download the language detector model=], [=initialize the language detector model=], and [=create the language detector object=].
506510
</div>
507511

508512
<div algorithm>
@@ -562,7 +566,7 @@ dictionary LanguageDetectionResult {
562566
<div algorithm>
563567
The static <dfn method for="LanguageDetector">availability(|options|)</dfn> method steps are:
564568

565-
1. Return the result of [=computing AI model availability=] given |options|, [=validate and canonicalize language detector options=], and [=compute language detector options availability=].
569+
1. Return the result of [=computing AI model availability=] given |options|, "{{language-detector}}", [=validate and canonicalize language detector options=], and [=compute language detector options availability=].
566570
</div>
567571

568572
<!-- TODO: consider deduping this with writing assistance APIs, as it's very similar. (Not similar to translator though!) -->
@@ -784,3 +788,7 @@ When language detection fails, the following possible reasons may be surfaced to
784788
</table>
785789

786790
<p class="note">This table does not give the complete list of exceptions that can be surfaced by the language detector API. It only contains those which can come from certain [=implementation-defined=] steps.
791+
792+
<h3 id="language-detector-permissions-policy">Permissions policy integration</h3>
793+
794+
Access to the language detector API is gated behind the [=policy-controlled feature=] "<dfn permission>language-detector</dfn>", which has a [=policy-controlled feature/default allowlist=] of <code>[=default allowlist/'self'=]</code>.

security-privacy-questionnaire.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -67,9 +67,9 @@ None.
6767
> 13. How does this specification distinguish between behavior in first-party and
6868
> third-party contexts?
6969
70-
We are not yet sure. Our default course of action is to give the same capabilities to both first- and third-party contexts. It is easy to imagine use cases where this could be useful, e.g. a third party customer-support widget that provides translation functionality.
70+
We use permissions policy to disallow the usage of these features by default in third-party (cross-origin) contexts. However, the top-level site can delegate to cross-origin iframes.
7171

72-
However, it seems likely that some of the mitigations for the [anti-fingerprinting considerations](./README.md#privacy-considerations) will require some sort of distinction between first- and third-party contexts. For example, partitioning download status, or only using the top-level site's detected language, or similar.
72+
It's also possible that the [anti-fingerprinting considerations](./README.md#privacy-considerations) will require some sort of distinction between first- and third-party contexts. For example, partitioning download status, or only using the top-level site's detected language, or similar.
7373

7474
> 14. How do the features in this specification work in the context of a browser’s
7575
> Private Browsing or Incognito mode?

0 commit comments

Comments
 (0)