Skip to content

Commit e870bd6

Browse files
authored
Document Google AMP Cache requirements. (#300)
Document the set of requirements that the Google AMP Cache sets on signed exchanges, to enable independent signing implementations.
1 parent 8e9ab85 commit e870bd6

File tree

2 files changed

+84
-9
lines changed

2 files changed

+84
-9
lines changed

README.md

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -176,15 +176,10 @@ recommendations](https://gist.github.com/sleevi/5efe9ef98961ecfb4da8).
176176
177177
#### How will these web packages be discovered by Google?
178178
179-
For now, the presence of the `Vary: AMP-Cache-Transform` response header on an
180-
AMP HTML page will allow the Google AMP Cache to make a second request with
181-
`AMP-Cache-Transform: google` for the SXG.
182-
183-
The Google Search developer preview only runs on Chrome M71+ (as of 2018-11-12,
184-
Beta or Dev).
185-
186-
In the future, Googlebot may make all requests with `AMP-Cache-Transform: google`,
187-
eliminating the double fetch.
179+
Googlebot makes requests with an `AMP-Cache-Transform` header. Responses that
180+
are [acceptable AMP SXGs](docs/cache_requirements.md) will be eligible for
181+
display to SXG-supporting browsers, and the HTML payload will be extracted and
182+
eligible for use in the AMP viewer in other browsers.
188183
189184
### Limitations
190185

docs/cache_requirements.md

Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
1+
# AMP Cache SXG Requirements
2+
3+
## Audience
4+
5+
The audience for this document is people intending on implementing their own AMP
6+
signed exchange generator, independent of amppackager, and those implementing
7+
their own AMP SXG cache for the purposes of privacy-preserving prefetch. Users
8+
of `amppkg` need not read this, as the tool should automatically guarantee the
9+
following requirements are met.
10+
11+
## Google AMP cache
12+
13+
The Google AMP cache sets some requirements in addition to the ones set by the
14+
[SXG spec](https://wicg.github.io/webpackage/draft-yasskin-http-origin-signed-responses.html).
15+
These include:
16+
17+
* The signed `fallback URL` must equal the URL at which the SXG was delivered.
18+
* The payload must be:
19+
* non-empty.
20+
* valid transformed AMP. The canonical definition of transformed AMP is the
21+
return value of [`transform.Process()`](https://github.com/ampproject/amppackager/blob/e4bf0430ba152cfe82ccf063df92021dfc0f26a5/transformer/transformer.go#L219).
22+
If given a [valid AMP](https://github.com/ampproject/amphtml/tree/master/validator)
23+
doc as input, it should produce a valid transformed AMP doc. There may be
24+
other ways of achieving this, but they are unsupported (i.e. may
25+
arbitrarily break in the future).
26+
* unchanged after calling [`transform -config NONE`](https://github.com/ampproject/amppackager/tree/releases/transformer#how-to-use).
27+
* matching one of the versions requested by the `AMP-Cache-Transform` header.
28+
Note that this version range will increase over time, at a cadence TBD
29+
(likely 6-8 weeks with 2 or 3 supported latest versions).
30+
* If the signed `cache-control` header has a `no-cache` directive, it cannot
31+
have a value (i.e. `no-cache=some-header` is disallowed).
32+
* The signed `content-security-policy` header must be present and comply with
33+
these rules:
34+
* `default-src`, `script-src`, `object-src`, `style-src`, and `report-uri`
35+
must equal those from the [AMP cache CSP](https://github.com/ampproject/amppackager/blob/releases/packager/signer/signer.go#L272)
36+
* `base-uri`, `block-all-mixed-content`, `font-src`, `form-action`,
37+
`manifest-src`, `referrer`, and `upgrade-insecure-requests` may be omitted
38+
or have any value
39+
* all other directives are disallowed
40+
* The signed `link` header, if present, must look like [this](https://github.com/ampproject/amppackager/blob/e4bf0430ba152cfe82ccf063df92021dfc0f26a5/packager/signer/signer.go#L426)
41+
(the validation logic is currently very picky about its serialization); and
42+
have limits like [this](https://github.com/ampproject/amppackager/blob/e4bf0430ba152cfe82ccf063df92021dfc0f26a5/transformer/transformer.go#L177)
43+
(e.g. max 20 urls, rel=preload only, as=script|style only). URLs must be
44+
limited to `cdn.ampproject.org` and the allowlisted [font provider URLs](https://github.com/ampproject/amphtml/blob/b0ff92429923c86f3973009a84ff02f4f1868b4d/validator/validator-main.protoascii#L310).
45+
* The signature's duration (expiry minus date) must be >= 4 days.
46+
47+
The above is an attempt at a complete list of SXG-related requirements, but it
48+
is not guaranteed to be complete.
49+
50+
Some of the above limitations are overly strict for an AMP SXG cache's needs,
51+
and were implemented as such for the sake of expediency. They may be loosened
52+
over time, especially in response to publisher feedback.
53+
54+
## Other AMP caches
55+
56+
As other AMP caches adopt support for signed exchanges, they could define their
57+
own set of requirements. It would be most useful for publishers and users,
58+
however, if the requirements were the same across all caches. If you see a need
59+
for a different requirement on your cache, please contact the AMP Caching
60+
working group, for example via [Slack](https://amphtml.slack.com/) on the
61+
`#signed-exchanges` channel, via one of [these methods](https://github.com/ampproject/wg-caching#communication-channels).
62+
63+
## Testing
64+
65+
There is no known publicly available tool for validating an SXG against the
66+
above requirements, though one is certainly welcome. In the interim, one may
67+
issue a request against the Google AMP Cache and see if the response is a valid
68+
SXG.
69+
70+
Meets requirements:
71+
```
72+
$ curl -s -i -H 'Accept: application/signed-exchange;v=b3' https://amppackageexample-com.cdn.ampproject.org/wp/s/amppackageexample.com/ | grep -a -i content-type:
73+
content-type: application/signed-exchange;v=b3
74+
```
75+
76+
Does not meet requirements:
77+
```
78+
$ curl -s -i -H 'Accept: application/signed-exchange;v=b3' https://amppackageexample-com.cdn.ampproject.org/wp/s/amppackageexample.com/gen/invalid.sxg | grep META
79+
<META HTTP-EQUIV="refresh" content="1; url=https://amppackageexample.com/gen/invalid.sxg">
80+
```

0 commit comments

Comments
 (0)