|
| 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