diff --git a/contracts/mail-relay/CHANGELOG.md b/contracts/mail-relay/CHANGELOG.md index 6374e98..ae44985 100644 --- a/contracts/mail-relay/CHANGELOG.md +++ b/contracts/mail-relay/CHANGELOG.md @@ -1,6 +1,19 @@ # Changelog of the wire contract -## 1.6.0 — 2026-11-25 (not released; no tag yet) +## 1.7.0 — 2026-11-25 (not released; no tag yet) + +From the independent review of the first client. What a client built against 1.6.0 has to change is marked. + +- **New, required: the header `X-Intecion-Site: ` on every request that carries a token.** Missing: + `400 invalid-request`. Not the token's host: the new code **`403 host-mismatch`** (forget the token, enrol as + yourself). **Client: send the header; handle the code.** All examples with a token carry it; two new + examples (`send-host-mismatch`, `status-no-site-header`). +- **A client stores the host with the token and compares it with its own before use**, and compares the `host` + of `/v1/status` (§8, checklist 3). **Client: add the check.** +- **The confirm endpoint's limiter counts only refused calls**, after the nonce was looked up; never by the + caller's address first (§2). **Client: check the order.** + +## 1.6.0 — 2026-11-25 (never released) From the first client built against the contract (IAPL's). **The service did not change**; these are the contract's words. What a client built against 1.5.0 has to change is marked. diff --git a/contracts/mail-relay/CHECKSUMS b/contracts/mail-relay/CHECKSUMS index 487681e..d47d2e5 100644 --- a/contracts/mail-relay/CHECKSUMS +++ b/contracts/mail-relay/CHECKSUMS @@ -1,8 +1,8 @@ -a5cc857363323400a6d24b45804c8fd964392cd0e61e99a8b120b354ac803e33 README.md -05d026ddc45ee9824534ce13f5b8f14bd1475688fe98949e3297f90548e3abb0 CHANGELOG.md -cb1d9a30bc4ab8a397f39b7d786bb82aca0b816077eefc35d7c822017d75f6a5 VERSION -275ee643112eac77430dba9ea3f93c8f53dc1676b8d56ba95a25dd3f35a8746f schema.json -913d3776b27076bf1d89639ef903f80c1c1b9bcd702851e9913def2588d73d83 runner.mjs +9b254d1aebe0e3e11539f95bb9eabba8984a77f27ea1a12ab9c259f3a3f2df94 README.md +cf9e7137ac9190773856b5d284544d04c188c852a3f3a92f6f68f561060c8626 CHANGELOG.md +bb7320d831e7a151aa901c35e7326c752fa2ef5024f30768c42319b8bed171ed VERSION +2ff0ad5b6a245365c0fa8733fa17b7bbd3ab91d4825981709d0fd02b762b939f schema.json +766fe0ed81037c230ab64e9fea2f9e6e5e828c5744bd90c61d9a2ad374a83100 runner.mjs 7c46860adee597e570832c72bcdb418752a20b9f7d1b2d7a656ed065f9632b2a checksums.mjs df6015faf02a7cf7e9b5816b9e22b2e82968678ddd72a61c1f9665a8c0897ddf examples/callback-confirm-wordpress.json f5018ca4fb7d25794ee92168d715aaf47feeba3d907c0550651b16c10a691ceb examples/callback-confirm.json @@ -21,42 +21,44 @@ e86e6ab23088c1c985ba18f287f66b49c50f51a584a7ca679b8b768597130efd examples/enrol fe38f1fd1394a7fd42b1a1b0b74aa604578f17ab52590bf95a462a0c0f7d6087 examples/enrol-unlisted-pending.json b9f71fe993dc39bdbc07e775e925a37175e18e1682fd8bffcc72b3581919be17 examples/health.json 5dff4194764f6f61b01a3f7f504907e578306a486d214e22d1a70b1a207e5ca3 examples/not-found.json -7df29aaf11934bb3a73f6899c66c4f73cfcc048c804ca52871b60376323cb222 examples/revoke-ok.json -148ae206781250f5de72d8d8f024fb1a0ba9c61c3f14c2866cdbda5244940097 examples/rotate-ok.json -81b6eeec98cdc35860241b1a958ab35cf6de2872bf1ffcdb24629156f5308996 examples/rotate-previous-token.json -2e9b2d088310ed1965639ad48e3aa4753ca277bb4c7119b8b58b082d25a5f46c examples/send-attachments-too-large.json -3585fde1439db56351a99c40e8262f606a3884eb4035546c76591279adbba0e8 examples/send-backend-failed.json -938761bbe576ca2da017cff8a42c4586bee971b9f5ce27a2fa024f7643fa1d3e examples/send-bearer-any-case.json -dbfdf96f791057e7a228330dba706cdcdf07f87d46d37734e2f4a3a49d557db0 examples/send-day-quota.json -93455791565a0b2f8d464aed858cc470a014bf16c943d3883383a145e43424f9 examples/send-display-name-recipient.json -01d7927fa99572fee0adf73c9d079ca7a544c3bf90d90c068e4b85137b59b53d examples/send-executable-attachment.json -54db430c75ae132fda615f5a27a2e8d0f53157acdceedaba2c035edd1938f0e9 examples/send-from-browser.json -650c8a79f38901e0027d3e105ad8e8edaab776f091011930093b7b1bc96bad66 examples/send-from-field.json -f9db7bdf34887406fdf80e037c83212e9523c553a2566fe7d1a9411a491cd85c examples/send-headers-field.json -5679e08b88d2206dc6810f73bb2139a8f7f46b7fd0470420081f8543e4466889 examples/send-hour-quota-account.json -40828edcba271529de9d452239fb218afc63a1dd6606c5e201ad622f2748ba09 examples/send-hour-quota.json -60e2eb9841a379c3985ae53e0c821a9e8a6f1de1cffc41f55f63a2bf91ffb315 examples/send-key-reused.json -6b10a5fce8dc51188cad654804bf742d9221e3825f04c688d724c2c8893bc2af examples/send-no-sender-name.json -1c37294029f41bb3953245950bde50ef6f550f9459aa16df525d4f8897f6f610 examples/send-no-token.json -3408947e979677ab07bdac2939c716083c78bdf75ac0e06993cc68fcdbae071f examples/send-ok.json -3660c55e7a359183793fd06c73a8c8c1529670e720cd9aa933a0a915b7f18a9f examples/send-pending.json -cec3126afeffbc18ee02a23556c184dc9195f05a0fc9cff8a31be7bbd444a557 examples/send-previous-token.json -b3b8ca0aae457e1d7afaa557b73ba1ab9c6c6427727c5d159e5290427f05ad8c examples/send-recipient-quota-other-kinds.json -9ac1a9cccea648f5a54c55abd7d2271ac8b1916d789138f09bbacff1960c45eb examples/send-recipient-quota.json -84d37df95af790ade19255736868fc38295e2674082dfec1c13f64031f88571c examples/send-recipient-suppressed.json -5243b6a33a200c4e57f1f32bf285bd7a1499663e3073462e057548c2e1201d9f examples/send-replay.json -40b86320ccfbe321b2831672035df618b4f5a6b3a70e398260698b4690b9c9a8 examples/send-security-alert.json -af073fb884954c55f606fd2c6f7dc0bbedc29ec6b0daff4c77e91c16c129ac6d examples/send-sender-name-replaced.json -bf0ce766240ad5df96176a8a6e0f54e7eaa533262657c8105ce342f957f156fb examples/send-subject-direction-mark.json -47824ad6a90c27da507a98fef4e31486f8fac445d4f0657c6f98312752884da0 examples/send-subject-imitates-service.json -85d43f2c6855accbece8bf09c281544355421de308850846fe28b7aa457fab21 examples/send-subject-line-break.json -be98bd6277fadc03eacfa901ac15c9f69895ddfb3b01fbf40d849e9eeded61fe examples/send-subject-visitor-text.json -a5dddf15899dfb6d7212b63f5bc32819d7f35a14872daae4f46324555bffa0e1 examples/send-suspended.json -bcf24c613cfb4eb223667ab2eee8ca6ebe91a6f97b86e6545b9d9316c63ca728 examples/send-text-plain.json -725fc1f4b059dc192f49955f67df4263f4a67f618b7314ca87ddfd7647e4514e examples/send-to-intecion-marked.json -aac0a3d17fe69e8d6c0adbcd3513650c2802b7f43c2103d5cd3de5a0346456c0 examples/send-too-many-recipients.json -4833a6b7cf81eba320f20c33fd44cb990681144186218332c2fb97a043b774cf examples/send-unknown-address.json -1ad0d24c691ab35b5603d63f5b29c5a3a3e50265aea9524fd26d314c0b7c1437 examples/send-unknown-token.json -cd2812d7b33698851116dd96fc1019e7ddfcc7f0b14511c6fa8f1b94acbfdb7e examples/status-active.json -e1bbb759fc3f7084d4bc027fa7d490cf0d24bc8ca124bd9a82e5dde372eb7bcd examples/status-pending.json -daaf53c17b92e61049b230e6a91edf9450967d920c05d23b3da67959e27474e4 examples/status-unknown-address.json +94943f85503cd891f1fb6f0258ab97b2eb48ec10e5f7ea233d349d4da97b8a1b examples/revoke-ok.json +1b467eac1040d56369276e5b8c12540a84942c8b7e3c2e458fc8da5b4f027c86 examples/rotate-ok.json +348f96a160c168797ab27ff0739b17df1762cc2ffdd72cb0a2b3ec2c695093bc examples/rotate-previous-token.json +39774a2ce0434dc791d79f9efb4b14f23203b7e8d58138acc7654265a875609b examples/send-attachments-too-large.json +75ec4de22780b36b41f198f065e38937beb4a50879fd204e080bdb935c2b5e8f examples/send-backend-failed.json +e3331a33604c2239c91c889d3dd338e473fd9b5d80fccb84a39491810bcceac0 examples/send-bearer-any-case.json +26f4f8a2929d132598bcb87e813616cef7b6277249c657cc618f4ede4cb4d906 examples/send-day-quota.json +660dbe2a747686077788f46fe45f269c3eb57e4579225979f91841e9f00fae7b examples/send-display-name-recipient.json +1c6bd0ed454f51acf545f0213fe6108f3639af975fb0751ef8d23bd92da9d4c7 examples/send-executable-attachment.json +ed6869754e418cc5e2a809e52a0242680d79f1bbc2eedd391de04375f29f7b9a examples/send-from-browser.json +e39d197f857b56103726b0f165c67a3476a06207961a59c6f6a1cf333bc3e7e9 examples/send-from-field.json +5c826cd0c297c773510ce37b66a0f6a6425e6282abc1ad30094fd5b545ae9193 examples/send-headers-field.json +3918635b33b32783db96ae17ebbd4296d2deca05d092b55573c574be172601ec examples/send-host-mismatch.json +a6809a8d475106f8e31ba432e56b46e9bf8683a0eca9d62378b1392cd6c44305 examples/send-hour-quota-account.json +c46852c9d9fc7eb83ac6bc3ca2a7c5b79100d2cae93a5cee6720b702b4c22490 examples/send-hour-quota.json +dc0f9c1c946d256aded0de70588c1d1f95740d333b234127f9bce8a4ed8beefb examples/send-key-reused.json +69edbf23c9723337f6327484e587b8cb7603c23e4b4954ebd275a0a794171325 examples/send-no-sender-name.json +bcbf5adcd0c224edb81c3b4188f261252835f715f541030db10432fa7ebd71a4 examples/send-no-token.json +32125ac9ff5460991633cce55febcb310247ca518eae7c650ef634e3f86376e0 examples/send-ok.json +7d8b14d372730f013ee7192021dda68859f779337b8d535bc564ac955a00e325 examples/send-pending.json +e3bbb041217d0a4f378285c06584a093d5e808d223d564e735c559f461fae8b8 examples/send-previous-token.json +53132e3e2177937dc2a35f7fe87f2f383f45ab001fc0306490941b44bb466e3c examples/send-recipient-quota-other-kinds.json +aff454882faab57d4a697be7250fdbac0272bcc2e0c099a6a27c50e0a980ac70 examples/send-recipient-quota.json +d514bc65a75f522389c90f1239d9afa43d96c7c2e7bd31fe0e85dd4c9d543ebd examples/send-recipient-suppressed.json +eb68d83a8d582a3722bf99330246d3d641e49a53e08bbe48e04e09a970cbb866 examples/send-replay.json +189dbdb3df1f0da0b6a1e8fdd0e90babf9dbfe9cfcaeb423ba24e2d59802b663 examples/send-security-alert.json +f299bc4f5193de0619d78551653a0b133a4ae5774dba93b23812b689a074a87d examples/send-sender-name-replaced.json +39a09b2bd01fc12d0e8cb2f93b71b24f31a4f2d0f639fe93b6bf37a7357be0ae examples/send-subject-direction-mark.json +ce4cbea2306f73bd5905249c10ab451a2599cb779e2386828971f40c97b8c591 examples/send-subject-imitates-service.json +247619f5575e898bd558ff7f7674f241c39f3a1e0ae51f589eb6a6dc2fe21e2b examples/send-subject-line-break.json +59175981e46a6f782ce3b4ed9c885699d7766823d660e5a524e89a4f2c6c459a examples/send-subject-visitor-text.json +987a2b4433161b4f2a6502d0487bf18f512f7a630a930ac66b1038cd6e000dc3 examples/send-suspended.json +91cd894526eef28e4dfb2456e476ba0be381e6d621ea833761cc9c63fe247e03 examples/send-text-plain.json +9c6278fcb13d7e06e0dd38ef34eba1abfbcb9c75100994b93c1c5a5444c35f85 examples/send-to-intecion-marked.json +1a1faf5a451220a35f2f0d66bb906e0d9944ed0a71c8209e07da419734a82567 examples/send-too-many-recipients.json +43d04c99549a4fe3c64af6f68b598299e92486af5a52432a2c93c3f9564f7959 examples/send-unknown-address.json +28e05f3c53cab6433b6af4d425511fa6655d0673df2e840af1fed9d25294a123 examples/send-unknown-token.json +f105c38ab11ab5fc508ba0ed3f23f69108c318765c2670029b230b5b9a83912a examples/status-active.json +89009ee9ab8f38e9ec290fb5412f206e1be28ad10fce6a7071d4406ac52dd4f0 examples/status-no-site-header.json +c9f49fa0dae1f0beacaacfe01660b467d06f990228c35a653307c8793f3c97a5 examples/status-pending.json +afdb07ba8279479b6bbfdc4289efda657d4e5a9eccd94b8de165ec728b4a2386 examples/status-unknown-address.json diff --git a/contracts/mail-relay/README.md b/contracts/mail-relay/README.md index b266380..f11fc17 100644 --- a/contracts/mail-relay/README.md +++ b/contracts/mail-relay/README.md @@ -1,6 +1,6 @@ # Intecion Notifications Webservice — wire contract -Version: see [`VERSION`](VERSION) (this text describes **1.6.0**). Path prefix of this major version: `/v1`. +Version: see [`VERSION`](VERSION) (this text describes **1.7.0**). Path prefix of this major version: `/v1`. This is the whole agreement between the Intecion Notifications Webservice ("the service" below) and a client (the mail transport built into a site's plugin). It names no product: nothing here says Payload, WordPress, IAPL or IAWL except the values of @@ -67,6 +67,7 @@ Every refusal has the same body ([`Error`](schema.json)) — with one exception: | 403 | `site-suspended` | Stopped by Intecion | no | Keep the token; show it; do not enrol again | `relay-suspended` | | 403 | `host-not-allowed` | Enrolment: the host is not a public DNS name | no | Show it (a local or private site cannot use the service) | `relay-refused` | | 403 | `enrolment-closed` | Enrolment is closed for this product, or altogether | no | Show it | `relay-refused` | +| 403 | `host-mismatch` | The token is good and comes from a known address, but the request's `X-Intecion-Site` names another site than the token's | no | Forget the token (it is another site's — a copied database, a token pasted into the wrong site), enrol as your own host, then send once more | — | | 403 | `browser-not-allowed` | The request came from a browser | no | — | — | | 404 | `not-found` | No such route | no | Report a bug | — | | 405 | `method-not-allowed` | Wrong method | no | Report a bug | — | @@ -161,7 +162,15 @@ A site gets its token by proving that it is served at its host. No authenticatio { "confirmation": "" } ``` - In every other case it answers `404` and changes nothing. It is a public route: rate-limit it. + In every other case it answers `404` and changes nothing. + + **It is a public route: limit it — but only the calls it refuses.** Look the nonce up **first**. A call that + carries the nonce the site holds is the service's and is always answered; only calls that do **not** match + a held nonce count towards a limit. Do not limit by the caller's address before that look-up: the service's + calls come from addresses that every Worker on Cloudflare shares, so a stranger who sends a few requests + from a Worker of their own would use up "the service's" allowance and block the site's enrolment. (When the + site holds no nonce at all — it started no enrolment in the last five minutes — every call is a refused one + and can be answered `404` without any work.) **Exactly this answer and nothing else.** Status `200` (not 201, not 204). The body is the JSON object alone, UTF-8, at most 1024 bytes, the hex in lower case. Anything printed before or after it — a PHP notice, a @@ -237,6 +246,7 @@ Headers (`Bearer` in any case; one space; then the token exactly): ``` Authorization: Bearer ims_… +X-Intecion-Site: example.com Idempotency-Key: <16 to 128 characters of A–Z a–z 0–9 _ -> Content-Type: application/json ``` @@ -350,7 +360,7 @@ not go out ([`StatusResponse`](schema.json)): ```json { "ok": true, "state": "active", "host": "example.com", "product": "iapl", - "service": { "name": "Intecion Notifications Webservice", "version": "1.0.0", "contract": "1.6.0" }, + "service": { "name": "Intecion Notifications Webservice", "version": "1.0.0", "contract": "1.7.0" }, "sender": { "address": "notification@webservices.intecion.net" }, "limits": { "messagesPerHour": 30, "messagesPerDay": 200, "recipientsPerMessage": 10, "perRecipientPerDay": 10, "newRecipientsPerDay": 50, @@ -393,7 +403,20 @@ No authentication. `200 { "ok": true }` or `503 { "ok": false }`, nothing else. - Every route except `/v1/enrol` and `/health` needs it, **and** needs the request to come from a server address the site enrolled from (IPv6: the same `/64`). A good token from another address gets `401 reverify` and nothing else — not even the site's state. -- A token belongs to one host and cannot act for another. +- **A token belongs to one host and cannot act for another — and both sides hold it to that.** + - **Every request with a token carries `X-Intecion-Site: `** (the host it + enrolled as, lower case). Without the header: `400 invalid-request`. With a host that is not the token's: + `403 host-mismatch` — nothing is sent, read, rotated or revoked. + - **A client stores the host together with the token** (at the confirm endpoint: the host it is enrolling + as) and, before it uses a token, compares that stored host with its own public host of this moment. When + they differ the token is not its own — the database was copied from another site (staging from + production, a restored backup of another project), or somebody pasted a foreign token: the client does not + use it, forgets it, and enrols as itself. + - A client that reads `/v1/status` compares the `host` in the answer with its own the same way. + + This is a guard against an honest mistake, not against a thief — whoever steals a token can name its host; + the address binding is what stops them. Without the guard, a copy of a site running on the same server as + the original would send mail as the original, on the original's limits. ## 9. Versions @@ -492,9 +515,12 @@ hand-edited copy fails. The copy's `VERSION` says which contract the client spea Checklist for a client: 1. Constants: the base address, the contract version. No secret. -2. A confirm endpoint (public, rate-limited, `404` unless it holds the nonce, constant-time compare, single - use, answers the confirmation as the only output, keeps the earlier token until the new one is accepted). -3. A token store that is never readable from outside and never printed. +2. A confirm endpoint (public; `404` unless it holds the nonce; the nonce looked up before any limiter, and + only refused calls counted by it; constant-time compare, single use, answers the confirmation as the only output, keeps the earlier token until the new one is accepted). +3. A token store that is never readable from outside and never printed — holding the token **and the host it + was issued to**. Before every use: is that host still this site's own public host? If not, do not use the + token; enrol as this site. Send `X-Intecion-Site` with every request that carries a token; on + `403 host-mismatch` forget the token and enrol. 4. Enrol on the first send without a token, after `invalid-token` and after `reverify` — unless the token was issued by hand: then stop and report (§2). Guard against two processes enrolling at once (`enrolment-in-progress`). diff --git a/contracts/mail-relay/VERSION b/contracts/mail-relay/VERSION index dc1e644..bd8bf88 100644 --- a/contracts/mail-relay/VERSION +++ b/contracts/mail-relay/VERSION @@ -1 +1 @@ -1.6.0 +1.7.0 diff --git a/contracts/mail-relay/examples/revoke-ok.json b/contracts/mail-relay/examples/revoke-ok.json index 83515b9..bd48cc1 100644 --- a/contracts/mail-relay/examples/revoke-ok.json +++ b/contracts/mail-relay/examples/revoke-ok.json @@ -8,7 +8,8 @@ "method": "POST", "path": "/v1/revoke", "headers": { - "authorization": "Bearer {{token}}" + "authorization": "Bearer {{token}}", + "x-intecion-site": "{{host}}" } }, "response": { diff --git a/contracts/mail-relay/examples/rotate-ok.json b/contracts/mail-relay/examples/rotate-ok.json index d825e3a..a197fea 100644 --- a/contracts/mail-relay/examples/rotate-ok.json +++ b/contracts/mail-relay/examples/rotate-ok.json @@ -8,7 +8,8 @@ "method": "POST", "path": "/v1/rotate", "headers": { - "authorization": "Bearer {{token}}" + "authorization": "Bearer {{token}}", + "x-intecion-site": "{{host}}" } }, "response": { diff --git a/contracts/mail-relay/examples/rotate-previous-token.json b/contracts/mail-relay/examples/rotate-previous-token.json index ea0dd4d..ec4fe7a 100644 --- a/contracts/mail-relay/examples/rotate-previous-token.json +++ b/contracts/mail-relay/examples/rotate-previous-token.json @@ -9,7 +9,8 @@ "method": "POST", "path": "/v1/rotate", "headers": { - "authorization": "Bearer {{token}}" + "authorization": "Bearer {{token}}", + "x-intecion-site": "{{host}}" } }, "response": { diff --git a/contracts/mail-relay/examples/send-attachments-too-large.json b/contracts/mail-relay/examples/send-attachments-too-large.json index 8f5dabf..35502f9 100644 --- a/contracts/mail-relay/examples/send-attachments-too-large.json +++ b/contracts/mail-relay/examples/send-attachments-too-large.json @@ -10,7 +10,8 @@ "headers": { "authorization": "Bearer {{token}}", "idempotency-key": "{{idempotencyKey}}", - "content-type": "application/json" + "content-type": "application/json", + "x-intecion-site": "{{host}}" }, "schema": "SendRequest", "body": { diff --git a/contracts/mail-relay/examples/send-backend-failed.json b/contracts/mail-relay/examples/send-backend-failed.json index 644c79e..1fbc219 100644 --- a/contracts/mail-relay/examples/send-backend-failed.json +++ b/contracts/mail-relay/examples/send-backend-failed.json @@ -11,7 +11,8 @@ "headers": { "authorization": "Bearer {{token}}", "idempotency-key": "{{idempotencyKey}}", - "content-type": "application/json" + "content-type": "application/json", + "x-intecion-site": "{{host}}" }, "schema": "SendRequest", "body": { diff --git a/contracts/mail-relay/examples/send-bearer-any-case.json b/contracts/mail-relay/examples/send-bearer-any-case.json index 2f96416..146da25 100644 --- a/contracts/mail-relay/examples/send-bearer-any-case.json +++ b/contracts/mail-relay/examples/send-bearer-any-case.json @@ -10,7 +10,8 @@ "headers": { "authorization": "bearer {{token}}", "idempotency-key": "{{idempotencyKey}}", - "content-type": "application/json" + "content-type": "application/json", + "x-intecion-site": "{{host}}" }, "schema": "SendRequest", "body": { diff --git a/contracts/mail-relay/examples/send-day-quota.json b/contracts/mail-relay/examples/send-day-quota.json index a9ac848..ffea8de 100644 --- a/contracts/mail-relay/examples/send-day-quota.json +++ b/contracts/mail-relay/examples/send-day-quota.json @@ -11,7 +11,8 @@ "headers": { "authorization": "Bearer {{token}}", "idempotency-key": "{{idempotencyKey}}", - "content-type": "application/json" + "content-type": "application/json", + "x-intecion-site": "{{host}}" }, "schema": "SendRequest", "body": { diff --git a/contracts/mail-relay/examples/send-display-name-recipient.json b/contracts/mail-relay/examples/send-display-name-recipient.json index 0a84d1b..0d22ccb 100644 --- a/contracts/mail-relay/examples/send-display-name-recipient.json +++ b/contracts/mail-relay/examples/send-display-name-recipient.json @@ -10,7 +10,8 @@ "headers": { "authorization": "Bearer {{token}}", "idempotency-key": "{{idempotencyKey}}", - "content-type": "application/json" + "content-type": "application/json", + "x-intecion-site": "{{host}}" }, "body": { "product": "iapl", diff --git a/contracts/mail-relay/examples/send-executable-attachment.json b/contracts/mail-relay/examples/send-executable-attachment.json index bf0b164..6bbc789 100644 --- a/contracts/mail-relay/examples/send-executable-attachment.json +++ b/contracts/mail-relay/examples/send-executable-attachment.json @@ -10,7 +10,8 @@ "headers": { "authorization": "Bearer {{token}}", "idempotency-key": "{{idempotencyKey}}", - "content-type": "application/json" + "content-type": "application/json", + "x-intecion-site": "{{host}}" }, "schema": "SendRequest", "body": { diff --git a/contracts/mail-relay/examples/send-from-browser.json b/contracts/mail-relay/examples/send-from-browser.json index 4634f0b..e977e86 100644 --- a/contracts/mail-relay/examples/send-from-browser.json +++ b/contracts/mail-relay/examples/send-from-browser.json @@ -11,7 +11,8 @@ "authorization": "Bearer {{token}}", "idempotency-key": "{{idempotencyKey}}", "content-type": "application/json", - "origin": "https://evil.example.net" + "origin": "https://evil.example.net", + "x-intecion-site": "{{host}}" }, "schema": "SendRequest", "body": { diff --git a/contracts/mail-relay/examples/send-from-field.json b/contracts/mail-relay/examples/send-from-field.json index f07e277..82de556 100644 --- a/contracts/mail-relay/examples/send-from-field.json +++ b/contracts/mail-relay/examples/send-from-field.json @@ -10,7 +10,8 @@ "headers": { "authorization": "Bearer {{token}}", "idempotency-key": "{{idempotencyKey}}", - "content-type": "application/json" + "content-type": "application/json", + "x-intecion-site": "{{host}}" }, "body": { "product": "iapl", diff --git a/contracts/mail-relay/examples/send-headers-field.json b/contracts/mail-relay/examples/send-headers-field.json index be99dc0..3c6fefe 100644 --- a/contracts/mail-relay/examples/send-headers-field.json +++ b/contracts/mail-relay/examples/send-headers-field.json @@ -10,7 +10,8 @@ "headers": { "authorization": "Bearer {{token}}", "idempotency-key": "{{idempotencyKey}}", - "content-type": "application/json" + "content-type": "application/json", + "x-intecion-site": "{{host}}" }, "body": { "product": "iapl", diff --git a/contracts/mail-relay/examples/send-host-mismatch.json b/contracts/mail-relay/examples/send-host-mismatch.json new file mode 100644 index 0000000..2fb192e --- /dev/null +++ b/contracts/mail-relay/examples/send-host-mismatch.json @@ -0,0 +1,47 @@ +{ + "id": "send-host-mismatch", + "title": "A token used by a site that names another host (a copy of the site's database, a token pasted into the wrong site) is refused", + "given": { + "site": "active" + }, + "request": { + "method": "POST", + "path": "/v1/send", + "headers": { + "authorization": "Bearer {{token}}", + "idempotency-key": "{{idempotencyKey}}", + "content-type": "application/json", + "x-intecion-site": "copy-of-{{host}}" + }, + "schema": "SendRequest", + "body": { + "product": "iapl", + "productVersion": "1.17.0", + "kind": "form-notification", + "to": [ + "{{recipient}}" + ], + "replyTo": "visitor@example.org", + "senderName": "Kancelaria Example", + "subject": "New enquiry", + "text": "Hello." + } + }, + "response": { + "status": 403, + "schema": "Error", + "body": { + "ok": false, + "code": "host-mismatch", + "retryable": false + } + }, + "then": { + "mails": 0 + }, + "client": { + "retry": false, + "reEnrol": true, + "status": null + } +} diff --git a/contracts/mail-relay/examples/send-hour-quota-account.json b/contracts/mail-relay/examples/send-hour-quota-account.json index 134ae95..67ae6d3 100644 --- a/contracts/mail-relay/examples/send-hour-quota-account.json +++ b/contracts/mail-relay/examples/send-hour-quota-account.json @@ -11,7 +11,8 @@ "headers": { "authorization": "Bearer {{token}}", "idempotency-key": "{{idempotencyKey}}", - "content-type": "application/json" + "content-type": "application/json", + "x-intecion-site": "{{host}}" }, "schema": "SendRequest", "body": { diff --git a/contracts/mail-relay/examples/send-hour-quota.json b/contracts/mail-relay/examples/send-hour-quota.json index cef1e92..5b783d0 100644 --- a/contracts/mail-relay/examples/send-hour-quota.json +++ b/contracts/mail-relay/examples/send-hour-quota.json @@ -11,7 +11,8 @@ "headers": { "authorization": "Bearer {{token}}", "idempotency-key": "{{idempotencyKey}}", - "content-type": "application/json" + "content-type": "application/json", + "x-intecion-site": "{{host}}" }, "schema": "SendRequest", "body": { diff --git a/contracts/mail-relay/examples/send-key-reused.json b/contracts/mail-relay/examples/send-key-reused.json index 6509d4d..904950e 100644 --- a/contracts/mail-relay/examples/send-key-reused.json +++ b/contracts/mail-relay/examples/send-key-reused.json @@ -11,7 +11,8 @@ "headers": { "authorization": "Bearer {{token}}", "idempotency-key": "{{idempotencyKey}}", - "content-type": "application/json" + "content-type": "application/json", + "x-intecion-site": "{{host}}" }, "schema": "SendRequest", "body": { diff --git a/contracts/mail-relay/examples/send-no-sender-name.json b/contracts/mail-relay/examples/send-no-sender-name.json index 86cb0ce..5e45c12 100644 --- a/contracts/mail-relay/examples/send-no-sender-name.json +++ b/contracts/mail-relay/examples/send-no-sender-name.json @@ -10,7 +10,8 @@ "headers": { "authorization": "Bearer {{token}}", "idempotency-key": "{{idempotencyKey}}", - "content-type": "application/json" + "content-type": "application/json", + "x-intecion-site": "{{host}}" }, "schema": "SendRequest", "body": { diff --git a/contracts/mail-relay/examples/send-no-token.json b/contracts/mail-relay/examples/send-no-token.json index 13c40e2..4cfd4c9 100644 --- a/contracts/mail-relay/examples/send-no-token.json +++ b/contracts/mail-relay/examples/send-no-token.json @@ -11,7 +11,8 @@ "headers": { "authorization": "Bearer {{token}}", "idempotency-key": "{{idempotencyKey}}", - "content-type": "application/json" + "content-type": "application/json", + "x-intecion-site": "{{host}}" }, "schema": "SendRequest", "body": { diff --git a/contracts/mail-relay/examples/send-ok.json b/contracts/mail-relay/examples/send-ok.json index d80bfbf..7e30f7d 100644 --- a/contracts/mail-relay/examples/send-ok.json +++ b/contracts/mail-relay/examples/send-ok.json @@ -10,7 +10,8 @@ "headers": { "authorization": "Bearer {{token}}", "idempotency-key": "{{idempotencyKey}}", - "content-type": "application/json" + "content-type": "application/json", + "x-intecion-site": "{{host}}" }, "schema": "SendRequest", "body": { diff --git a/contracts/mail-relay/examples/send-pending.json b/contracts/mail-relay/examples/send-pending.json index d107737..027b32c 100644 --- a/contracts/mail-relay/examples/send-pending.json +++ b/contracts/mail-relay/examples/send-pending.json @@ -10,7 +10,8 @@ "headers": { "authorization": "Bearer {{token}}", "idempotency-key": "{{idempotencyKey}}", - "content-type": "application/json" + "content-type": "application/json", + "x-intecion-site": "{{host}}" }, "schema": "SendRequest", "body": { diff --git a/contracts/mail-relay/examples/send-previous-token.json b/contracts/mail-relay/examples/send-previous-token.json index 2554187..ad01de2 100644 --- a/contracts/mail-relay/examples/send-previous-token.json +++ b/contracts/mail-relay/examples/send-previous-token.json @@ -11,7 +11,8 @@ "headers": { "authorization": "Bearer {{token}}", "idempotency-key": "{{idempotencyKey}}", - "content-type": "application/json" + "content-type": "application/json", + "x-intecion-site": "{{host}}" }, "schema": "SendRequest", "body": { diff --git a/contracts/mail-relay/examples/send-recipient-quota-other-kinds.json b/contracts/mail-relay/examples/send-recipient-quota-other-kinds.json index 23bbcd4..761a886 100644 --- a/contracts/mail-relay/examples/send-recipient-quota-other-kinds.json +++ b/contracts/mail-relay/examples/send-recipient-quota-other-kinds.json @@ -11,7 +11,8 @@ "headers": { "authorization": "Bearer {{token}}", "idempotency-key": "{{idempotencyKey}}", - "content-type": "application/json" + "content-type": "application/json", + "x-intecion-site": "{{host}}" }, "schema": "SendRequest", "body": { diff --git a/contracts/mail-relay/examples/send-recipient-quota.json b/contracts/mail-relay/examples/send-recipient-quota.json index d6aba27..e48b237 100644 --- a/contracts/mail-relay/examples/send-recipient-quota.json +++ b/contracts/mail-relay/examples/send-recipient-quota.json @@ -11,7 +11,8 @@ "headers": { "authorization": "Bearer {{token}}", "idempotency-key": "{{idempotencyKey}}", - "content-type": "application/json" + "content-type": "application/json", + "x-intecion-site": "{{host}}" }, "schema": "SendRequest", "body": { diff --git a/contracts/mail-relay/examples/send-recipient-suppressed.json b/contracts/mail-relay/examples/send-recipient-suppressed.json index 316629a..79588a0 100644 --- a/contracts/mail-relay/examples/send-recipient-suppressed.json +++ b/contracts/mail-relay/examples/send-recipient-suppressed.json @@ -11,7 +11,8 @@ "headers": { "authorization": "Bearer {{token}}", "idempotency-key": "{{idempotencyKey}}", - "content-type": "application/json" + "content-type": "application/json", + "x-intecion-site": "{{host}}" }, "schema": "SendRequest", "body": { diff --git a/contracts/mail-relay/examples/send-replay.json b/contracts/mail-relay/examples/send-replay.json index fa49231..5330835 100644 --- a/contracts/mail-relay/examples/send-replay.json +++ b/contracts/mail-relay/examples/send-replay.json @@ -11,7 +11,8 @@ "headers": { "authorization": "Bearer {{token}}", "idempotency-key": "{{idempotencyKey}}", - "content-type": "application/json" + "content-type": "application/json", + "x-intecion-site": "{{host}}" }, "schema": "SendRequest", "body": { diff --git a/contracts/mail-relay/examples/send-security-alert.json b/contracts/mail-relay/examples/send-security-alert.json index 3ffc984..ff30689 100644 --- a/contracts/mail-relay/examples/send-security-alert.json +++ b/contracts/mail-relay/examples/send-security-alert.json @@ -10,7 +10,8 @@ "headers": { "authorization": "Bearer {{token}}", "idempotency-key": "{{idempotencyKey}}", - "content-type": "application/json" + "content-type": "application/json", + "x-intecion-site": "{{host}}" }, "schema": "SendRequest", "body": { diff --git a/contracts/mail-relay/examples/send-sender-name-replaced.json b/contracts/mail-relay/examples/send-sender-name-replaced.json index 2b8729b..b525428 100644 --- a/contracts/mail-relay/examples/send-sender-name-replaced.json +++ b/contracts/mail-relay/examples/send-sender-name-replaced.json @@ -10,7 +10,8 @@ "headers": { "authorization": "Bearer {{token}}", "idempotency-key": "{{idempotencyKey}}", - "content-type": "application/json" + "content-type": "application/json", + "x-intecion-site": "{{host}}" }, "schema": "SendRequest", "body": { diff --git a/contracts/mail-relay/examples/send-subject-direction-mark.json b/contracts/mail-relay/examples/send-subject-direction-mark.json index e07648a..cf0e431 100644 --- a/contracts/mail-relay/examples/send-subject-direction-mark.json +++ b/contracts/mail-relay/examples/send-subject-direction-mark.json @@ -10,7 +10,8 @@ "headers": { "authorization": "Bearer {{token}}", "idempotency-key": "{{idempotencyKey}}", - "content-type": "application/json" + "content-type": "application/json", + "x-intecion-site": "{{host}}" }, "schema": "SendRequest", "body": { diff --git a/contracts/mail-relay/examples/send-subject-imitates-service.json b/contracts/mail-relay/examples/send-subject-imitates-service.json index 22e1dfb..e1bf701 100644 --- a/contracts/mail-relay/examples/send-subject-imitates-service.json +++ b/contracts/mail-relay/examples/send-subject-imitates-service.json @@ -10,7 +10,8 @@ "headers": { "authorization": "Bearer {{token}}", "idempotency-key": "{{idempotencyKey}}", - "content-type": "application/json" + "content-type": "application/json", + "x-intecion-site": "{{host}}" }, "schema": "SendRequest", "body": { diff --git a/contracts/mail-relay/examples/send-subject-line-break.json b/contracts/mail-relay/examples/send-subject-line-break.json index e1efc0f..95ef49c 100644 --- a/contracts/mail-relay/examples/send-subject-line-break.json +++ b/contracts/mail-relay/examples/send-subject-line-break.json @@ -10,7 +10,8 @@ "headers": { "authorization": "Bearer {{token}}", "idempotency-key": "{{idempotencyKey}}", - "content-type": "application/json" + "content-type": "application/json", + "x-intecion-site": "{{host}}" }, "schema": "SendRequest", "body": { diff --git a/contracts/mail-relay/examples/send-subject-visitor-text.json b/contracts/mail-relay/examples/send-subject-visitor-text.json index ab88437..6e97f62 100644 --- a/contracts/mail-relay/examples/send-subject-visitor-text.json +++ b/contracts/mail-relay/examples/send-subject-visitor-text.json @@ -10,7 +10,8 @@ "headers": { "authorization": "Bearer {{token}}", "idempotency-key": "{{idempotencyKey}}", - "content-type": "application/json" + "content-type": "application/json", + "x-intecion-site": "{{host}}" }, "schema": "SendRequest", "body": { diff --git a/contracts/mail-relay/examples/send-suspended.json b/contracts/mail-relay/examples/send-suspended.json index 1f3bdbd..8e4374d 100644 --- a/contracts/mail-relay/examples/send-suspended.json +++ b/contracts/mail-relay/examples/send-suspended.json @@ -10,7 +10,8 @@ "headers": { "authorization": "Bearer {{token}}", "idempotency-key": "{{idempotencyKey}}", - "content-type": "application/json" + "content-type": "application/json", + "x-intecion-site": "{{host}}" }, "schema": "SendRequest", "body": { diff --git a/contracts/mail-relay/examples/send-text-plain.json b/contracts/mail-relay/examples/send-text-plain.json index ca585c1..68a3108 100644 --- a/contracts/mail-relay/examples/send-text-plain.json +++ b/contracts/mail-relay/examples/send-text-plain.json @@ -10,7 +10,8 @@ "headers": { "authorization": "Bearer {{token}}", "idempotency-key": "{{idempotencyKey}}", - "content-type": "text/plain" + "content-type": "text/plain", + "x-intecion-site": "{{host}}" }, "schema": "SendRequest", "body": { diff --git a/contracts/mail-relay/examples/send-to-intecion-marked.json b/contracts/mail-relay/examples/send-to-intecion-marked.json index 7565ceb..2a27ba1 100644 --- a/contracts/mail-relay/examples/send-to-intecion-marked.json +++ b/contracts/mail-relay/examples/send-to-intecion-marked.json @@ -10,7 +10,8 @@ "headers": { "authorization": "Bearer {{token}}", "idempotency-key": "{{idempotencyKey}}", - "content-type": "application/json" + "content-type": "application/json", + "x-intecion-site": "{{host}}" }, "schema": "SendRequest", "body": { diff --git a/contracts/mail-relay/examples/send-too-many-recipients.json b/contracts/mail-relay/examples/send-too-many-recipients.json index 054fbe1..457b507 100644 --- a/contracts/mail-relay/examples/send-too-many-recipients.json +++ b/contracts/mail-relay/examples/send-too-many-recipients.json @@ -10,7 +10,8 @@ "headers": { "authorization": "Bearer {{token}}", "idempotency-key": "{{idempotencyKey}}", - "content-type": "application/json" + "content-type": "application/json", + "x-intecion-site": "{{host}}" }, "schema": "SendRequest", "body": { diff --git a/contracts/mail-relay/examples/send-unknown-address.json b/contracts/mail-relay/examples/send-unknown-address.json index afc01f8..20023d7 100644 --- a/contracts/mail-relay/examples/send-unknown-address.json +++ b/contracts/mail-relay/examples/send-unknown-address.json @@ -11,7 +11,8 @@ "headers": { "authorization": "Bearer {{token}}", "idempotency-key": "{{idempotencyKey}}", - "content-type": "application/json" + "content-type": "application/json", + "x-intecion-site": "{{host}}" }, "schema": "SendRequest", "body": { diff --git a/contracts/mail-relay/examples/send-unknown-token.json b/contracts/mail-relay/examples/send-unknown-token.json index befb26a..e1ca023 100644 --- a/contracts/mail-relay/examples/send-unknown-token.json +++ b/contracts/mail-relay/examples/send-unknown-token.json @@ -11,7 +11,8 @@ "headers": { "authorization": "Bearer {{token}}", "idempotency-key": "{{idempotencyKey}}", - "content-type": "application/json" + "content-type": "application/json", + "x-intecion-site": "{{host}}" }, "schema": "SendRequest", "body": { diff --git a/contracts/mail-relay/examples/status-active.json b/contracts/mail-relay/examples/status-active.json index a4382ce..03a856f 100644 --- a/contracts/mail-relay/examples/status-active.json +++ b/contracts/mail-relay/examples/status-active.json @@ -8,7 +8,8 @@ "method": "GET", "path": "/v1/status", "headers": { - "authorization": "Bearer {{token}}" + "authorization": "Bearer {{token}}", + "x-intecion-site": "{{host}}" } }, "response": { diff --git a/contracts/mail-relay/examples/status-no-site-header.json b/contracts/mail-relay/examples/status-no-site-header.json new file mode 100644 index 0000000..d65d654 --- /dev/null +++ b/contracts/mail-relay/examples/status-no-site-header.json @@ -0,0 +1,28 @@ +{ + "id": "status-no-site-header", + "title": "Every request with a token names its site", + "given": { + "site": "active" + }, + "request": { + "method": "GET", + "path": "/v1/status", + "headers": { + "authorization": "Bearer {{token}}" + } + }, + "response": { + "status": 400, + "schema": "Error", + "body": { + "ok": false, + "code": "invalid-request", + "field": "X-Intecion-Site" + } + }, + "client": { + "retry": false, + "reEnrol": false, + "status": null + } +} diff --git a/contracts/mail-relay/examples/status-pending.json b/contracts/mail-relay/examples/status-pending.json index 91e2a88..e337e65 100644 --- a/contracts/mail-relay/examples/status-pending.json +++ b/contracts/mail-relay/examples/status-pending.json @@ -8,7 +8,8 @@ "method": "GET", "path": "/v1/status", "headers": { - "authorization": "Bearer {{token}}" + "authorization": "Bearer {{token}}", + "x-intecion-site": "{{host}}" } }, "response": { diff --git a/contracts/mail-relay/examples/status-unknown-address.json b/contracts/mail-relay/examples/status-unknown-address.json index ee9b5b7..6659662 100644 --- a/contracts/mail-relay/examples/status-unknown-address.json +++ b/contracts/mail-relay/examples/status-unknown-address.json @@ -9,7 +9,8 @@ "method": "GET", "path": "/v1/status", "headers": { - "authorization": "Bearer {{token}}" + "authorization": "Bearer {{token}}", + "x-intecion-site": "{{host}}" } }, "response": { diff --git a/contracts/mail-relay/runner.mjs b/contracts/mail-relay/runner.mjs index fb2ccc7..8159fc3 100644 --- a/contracts/mail-relay/runner.mjs +++ b/contracts/mail-relay/runner.mjs @@ -2,7 +2,7 @@ // No dependency. Works in Node 20+ and in the Workers runtime (uses only WebCrypto, btoa and TextEncoder). // How to use it: README.md, "The examples and the runner". -export const CONTRACT_VERSION = '1.6.0' +export const CONTRACT_VERSION = '1.7.0' export class ContractError extends Error { constructor(exampleId, message) { diff --git a/contracts/mail-relay/schema.json b/contracts/mail-relay/schema.json index 1ad55a8..d346ede 100644 --- a/contracts/mail-relay/schema.json +++ b/contracts/mail-relay/schema.json @@ -556,6 +556,7 @@ "enrolment-closed", "enrolment-in-progress", "callback-failed", + "host-mismatch", "browser-not-allowed", "not-found", "method-not-allowed", diff --git a/docs/CHANGELOG.md b/docs/CHANGELOG.md index 175c5bb..80e64d3 100644 --- a/docs/CHANGELOG.md +++ b/docs/CHANGELOG.md @@ -116,7 +116,7 @@ once there are more than 20. `withMailKind`, `runWithMailKind`, `mailKindOf`, `expectMailTo`, `buildFormMailKindHook`, `createFakeRelay` (the service in memory, for tests), the constants `RELAY_*`, `MAIL_KINDS`, `MAIL_KIND`, `GRAPH_DEPRECATION_NOTICE`, and their types; `MailRelayStatus` from `/admin`. -- The wire contract of the service (version 1.6.0) is copied in the repository (`contracts/mail-relay/`) with a +- The wire contract of the service (version 1.7.0) is copied in the repository (`contracts/mail-relay/`) with a checksum test; every example of it runs against the plugin's fake service and against the plugin's client. - **`iapl-doctor` rule `legacy-names`** (info): lists the old names a project still uses, each with the new one. Information, not a defect. A warning only for `iapl-doctor.json` and `ipal-doctor.json` side by side, or one variable diff --git a/docs/email.md b/docs/email.md index d42c52b..2c642f6 100644 --- a/docs/email.md +++ b/docs/email.md @@ -91,6 +91,8 @@ catcher such as Mailpit) or the fake service ("Testing"). - With every message: recipients, subject, text and HTML, attachments, the sender name, the reply address, the kind of the message, and an idempotency key. The service keeps a log of metadata only (no subject, body, attachment, reply address or recipient address) for 30 days. +- Every request that carries the token also names the site (`X-Intecion-Site: `): the service refuses a token + used under another host's name (`403 host-mismatch` — the site then forgets that token and enrols as itself). - The service adds `X-Intecion-Site: ` and `X-Intecion-Product: iapl` to every mail. - Recipients' addresses and message bodies pass through Cloudflare (the service's mail back end). Name it in the client's processing agreement before a client site sends through the service. diff --git a/docs/security.md b/docs/security.md index 66351b1..a97fb85 100644 --- a/docs/security.md +++ b/docs/security.md @@ -1005,7 +1005,7 @@ token. What protects it, and what the new public route can and cannot do: |---|---| | **No key in the package** | The plugin carries the service's address and nothing else. A site gets its token by proving it is served at its host: it makes a nonce, the service calls `POST https:///api/iapl/mail-relay/confirm` with the nonce and a token, and only an answer that hashes both makes the token valid | | **Where the token is** | `payload-kv`, key `iapl:mail-relay`. The collection refuses every operation through access control (`read`, `create`, `update`, `delete` are `false`) and is hidden: REST, GraphQL and the panel cannot reach it — an admin included (test: `test/mailRelayHttp.test.ts`). Server code with the Local API can, like `smtpPassword`. It is stored as it is (no encryption at rest), never logged, never sent to a browser, never part of a route's answer | -| **A database copied to another host** | the token is tied to the host it was issued for: a copy on a staging domain does not use production's token — it forgets it, without revoking it, and enrols as itself | +| **A database copied to another host** | both sides hold a token to its host: every request names the site (`X-Intecion-Site`) and the service refuses another host's token (`host-mismatch`); and on the site the token is tied to the host it was issued for: a copy on a staging domain does not use production's token — it forgets it, without revoking it, and enrols as itself | | **A token of another site** (pasted into the access-key field, stored by a script) | refused: the service is asked which host the token is for before it is stored or used; a foreign one is not saved, not used, not revoked | | **A token read from a database dump** | **works from the same server** (a staging site on the machine production runs on shares its outgoing address) — which is why the store is tied to its host, above. From another server it does not work: the service accepts a token only from the addresses the site enrolled from (IPv6: the same `/64`) and answers anything else "enrol again" — which needs the call-back to the real site. It cannot send as another site, and the limits below apply | | **What a token can do at most** | send within the site's limits (30 an hour, 200 a day, 10 recipients, 10 MB by default) from the service's fixed address, under a sender name the service checks, with `X-Intecion-Site: ` on every mail. It cannot set `From`, `Return-Path` or any header, and cannot address a security alert | diff --git a/src/modules/email/relay/client.ts b/src/modules/email/relay/client.ts index 6dbfea5..a977728 100644 --- a/src/modules/email/relay/client.ts +++ b/src/modules/email/relay/client.ts @@ -30,6 +30,11 @@ export type RelayCall = { method: 'GET' | 'POST' /** Relative to the base address: `/v1/send`. */ path: string + /** + * The site's own public host, sent as `X-Intecion-Site` with every request that carries a token: the service + * refuses a token used under another host's name (`403 host-mismatch`). + */ + site?: string timeoutMs?: number token?: string /** Base address, host and path prefix together; joined with `path` as text. */ @@ -57,6 +62,7 @@ export async function relayRequest>(call: RelayCall) 'user-agent': `${RELAY_PRODUCT}/${PLUGIN_VERSION}`, ...(call.body ? { 'content-type': 'application/json' } : {}), ...(call.token ? { authorization: `Bearer ${call.token}` } : {}), + ...(call.token && call.site ? { 'x-intecion-site': call.site } : {}), ...(call.idempotencyKey ? { 'idempotency-key': call.idempotencyKey } : {}), }, method: call.method, diff --git a/src/modules/email/relay/constants.ts b/src/modules/email/relay/constants.ts index 6cfa410..b6ac36f 100644 --- a/src/modules/email/relay/constants.ts +++ b/src/modules/email/relay/constants.ts @@ -7,7 +7,7 @@ /** Base address: host and path together, joined with a path as text. Override: `mail: { relay: { url } }`. */ export const RELAY_BASE_URL = 'https://webservices.intecion.net/mail' /** The version of the copied contract this client speaks (`contracts/mail-relay/VERSION`). */ -export const RELAY_CONTRACT_VERSION = '1.6.0' +export const RELAY_CONTRACT_VERSION = '1.7.0' /** The `product` value of this plugin. */ export const RELAY_PRODUCT = 'iapl' /** The service's name, for docs, logs and the doctor. */ diff --git a/src/modules/email/relay/fake.ts b/src/modules/email/relay/fake.ts index f6d77c5..c001535 100644 --- a/src/modules/email/relay/fake.ts +++ b/src/modules/email/relay/fake.ts @@ -320,6 +320,10 @@ export function createFakeRelay(options: FakeRelayOptions = {}): FakeRelay { if (!site || (!current && !previous)) {throw new Refusal(401, 'invalid-token', 'No token, or one the service does not know.')} if (site.bindOnUse && site.addresses.length === 0) {site.addresses.push(address)} if (!site.addresses.includes(address)) {throw new Refusal(401, 'reverify', 'The token is good, but this server address is new for the site. Enrol again.')} + // every request with a token names its site; a token used under another host's name is refused (contract §8) + const named = request.headers.get('x-intecion-site') + if (!named) {throw invalid('X-Intecion-Site', 'The X-Intecion-Site header must name the site\'s own host.')} + if (named.toLowerCase() !== site.host) {throw new Refusal(403, 'host-mismatch', 'The token belongs to another site than the one named in X-Intecion-Site.')} // used most recently last: beyond the limit the address used longest ago is dropped site.addresses = [...site.addresses.filter((a) => a !== address), address] return { current, site } diff --git a/src/modules/email/relay/panel.ts b/src/modules/email/relay/panel.ts index fadb71d..25d6e24 100644 --- a/src/modules/email/relay/panel.ts +++ b/src/modules/email/relay/panel.ts @@ -138,8 +138,10 @@ export function relayPanelEndpoints(own?: false | RelayOptions): Endpoint[] { // Ask the service whose token this is BEFORE it replaces anything: a token of another site, or one the // service does not know, is refused and the site's present connection stays as it is. const ownHost = relayHost(req.payload, options) - const asked = await relayRequest<{ host?: string }>({ fetchImpl: options.fetchImpl, method: 'GET', path: '/v1/status', token: pasted, url: options.url }) - if (asked.ok && ownHost && asked.body.host && asked.body.host !== ownHost) {return json({ error: serverText(i18n, 'mailRelayTokenForeign'), ok: false }, 400)} + const asked = await relayRequest<{ host?: string }>({ fetchImpl: options.fetchImpl, method: 'GET', path: '/v1/status', site: ownHost, token: pasted, url: options.url }) + // the service refuses it under this site's name (`host-mismatch`), or names another host in its answer + const foreign = asked.ok ? Boolean(ownHost && asked.body.host && asked.body.host !== ownHost) : asked.code === 'host-mismatch' + if (foreign) {return json({ error: serverText(i18n, 'mailRelayTokenForeign'), ok: false }, 400)} if (!asked.ok && asked.code === 'invalid-token' && !asked.noAnswer) {return json({ error: serverText(i18n, 'mailRelayTokenInvalid'), ok: false }, 400)} if (!asked.ok && asked.code !== 'reverify') {return json({ error: serverText(i18n, 'mailRelayLoadFailed'), ok: false }, 502)} await setRelayToken(req.payload, pasted, { host: ownHost || undefined }) diff --git a/src/modules/email/relay/send.ts b/src/modules/email/relay/send.ts index c298780..06c386b 100644 --- a/src/modules/email/relay/send.ts +++ b/src/modules/email/relay/send.ts @@ -9,6 +9,7 @@ import { type RelayAnswer, type RelayRefusal, relayRequest } from './client.js' import { RELAY_DEFAULTS, type RelayStatusCode, relayStatusFor } from './constants.js' import { currentMailKind, type MailKind, mailKindOf, takeExpectedMail } from './kinds.js' import { bareAddresses, buildRelayMessage, type RelaySendRequest } from './message.js' +import { relayHost } from './options.js' import { LOCAL_CODES, readSiteStore, refreshRelayStatus, rotateRelayToken, type TokenUse, withRelayToken } from './session.js' import { readRelayStore, sha256Hex, updateRelayStore } from './store.js' @@ -90,7 +91,7 @@ function describeRefusal(answer: RelayRefusal): { sent: false } & RelaySendResul if (answer.code === 'callback-failed' && answer.reason === 'status') { return failure('relay-refused', answer.code, `${said} If the site serves its API at another path, ask Intecion to set this site's confirm address.`) } - if (answer.code === 'invalid-token' || answer.code === 'reverify') {return failure('relay-refused', answer.code, said)} + if (answer.code === 'invalid-token' || answer.code === 'reverify' || answer.code === 'host-mismatch') {return failure('relay-refused', answer.code, said)} const status = relayStatusFor(answer.code, answer.retryable) // The mail back end failed without saying whether the message can still go out. if (status === 'relay-unreachable' && !['enrolment-in-progress', 'rate-limited', 'unavailable'].includes(answer.code)) { @@ -193,6 +194,7 @@ export async function sendThroughRelay(payload: BasePayload, options: ResolvedRe const hash = createHash('sha256').update(body).digest('hex') const idempotencyKey = keyFor(hash) const use: TokenUse = { deadline } + const site = relayHost(payload, options) const budget = RELAY_DEFAULTS.waitBudgetMs let attempts = 0 let waited = 0 @@ -205,7 +207,7 @@ export async function sendThroughRelay(payload: BasePayload, options: ResolvedRe options, (token) => { attempts += 1 - return relayRequest({ body, fetchImpl: options.fetchImpl, idempotencyKey, method: 'POST', path: '/v1/send', timeoutMs: Math.max(1, Math.min(options.timeoutMs ?? RELAY_DEFAULTS.attemptTimeoutMs, left())), token, url: options.url }) + return relayRequest({ body, fetchImpl: options.fetchImpl, idempotencyKey, method: 'POST', path: '/v1/send', site, timeoutMs: Math.max(1, Math.min(options.timeoutMs ?? RELAY_DEFAULTS.attemptTimeoutMs, left())), token, url: options.url }) }, use, ) diff --git a/src/modules/email/relay/session.ts b/src/modules/email/relay/session.ts index 242d4c8..c026993 100644 --- a/src/modules/email/relay/session.ts +++ b/src/modules/email/relay/session.ts @@ -170,7 +170,7 @@ async function handIssued(payload: BasePayload, code: keyof typeof HAND_ISSUED): * `rate-limited` is not among them (its per-address gate runs before the token is looked at), nor are * `invalid-request`, `too-large`, `unavailable`, `internal` and the answers that are not the service's own. */ -const TOKEN_SEEN = new Set(['already-rotated', 'attachment-refused', 'backend-failed', 'idempotency-conflict', 'in-progress', 'quota-exceeded', 'recipient-suppressed', 'reverify', 'site-pending', 'site-suspended', 'too-many-recipients']) +const TOKEN_SEEN = new Set(['already-rotated', 'attachment-refused', 'backend-failed', 'host-mismatch', 'idempotency-conflict', 'in-progress', 'quota-exceeded', 'recipient-suppressed', 'reverify', 'site-pending', 'site-suspended', 'too-many-recipients']) /** Whether an answer shows that the service accepted the token it was sent with. */ export const provesToken = (answer: RelayAnswer): boolean => answer.ok || (!answer.noAnswer && TOKEN_SEEN.has(answer.code)) @@ -195,7 +195,8 @@ export type TokenUse = { * - no token yet → enrol first (when `enrol` is `'auto'`), then call; * - a token the call-back delivered but `/v1/enrol` never confirmed is tried first; on * `401 invalid-token` it is dropped and the earlier token is used again; - * - `401 invalid-token` or `401 reverify` → enrol again once, then call again. + * - `401 invalid-token` or `401 reverify` → enrol again once, then call again; + * - `403 host-mismatch` (the token is another site's) → forget it without revoking, enrol as this site. * A candidate becomes the token in use only when the service has SEEN IT ACCEPTED: a `200`, or a refusal * the service gives after it has checked the token (TOKEN_SEEN). No answer, an error page, the * per-address `rate-limited` and `browser-not-allowed` say nothing about a token — the candidate then stays @@ -250,6 +251,19 @@ export async function withRelayToken( if (failed) {return use.enrolment && !use.enrolment.ok ? failed : answer} continue } + if (!answer.ok && answer.code === 'host-mismatch') { + // The service knows this token as another site's (contract §8): a copied database or a token pasted into + // the wrong site that the comparison of the stored host did not catch. It is forgotten here — never + // revoked — and the site enrols as itself; a site that cannot be called back is told to ask for its own. + const message = `The token belongs to another site, not to "${relayHost(payload, options)}": it is not used. Ask Intecion for a token for this site.` + const now = new Date().toISOString() + await dropRelayCandidate(payload) + await updateRelayStore(payload, (current) => ({ ...current, hostChecked: false, manual: false, service: null, source: undefined, state: undefined, token: undefined, ...(stored.manual ? { refusal: { at: now, code: LOCAL_CODES.foreignToken, message, until: now } } : {}) })) + if (stored.manual) {return refusal(LOCAL_CODES.foreignToken, message)} + const failed = await enrolNow() + if (failed) {return use.enrolment && !use.enrolment.ok ? failed : answer} + continue + } if (candidate && !provesToken(answer)) {return answer} // says nothing about the token: both stay as they are if (candidate) { // Seen accepted: this is the token now. @@ -287,7 +301,7 @@ export async function refreshRelayStatus(payload: BasePayload, options: Resolved const answer = await withRelayToken( payload, options, - (token) => relayRequest({ fetchImpl: options.fetchImpl, method: 'GET', path: '/v1/status', timeoutMs, token, url: options.url }), + (token) => relayRequest({ fetchImpl: options.fetchImpl, method: 'GET', path: '/v1/status', site: relayHost(payload, options), timeoutMs, token, url: options.url }), timeoutMs === undefined ? {} : { deadline: Date.now() + timeoutMs }, { first: false }, ) @@ -332,7 +346,7 @@ export async function rotateRelayToken(payload: BasePayload, options: ResolvedRe const due = stored.service?.rotateAfter ? Date.parse(stored.service.rotateAfter) : Number.NaN if (!force && !(due <= Date.now())) {return 'not-due'} const used = stored.token - const answer = await relayRequest<{ token?: string }>({ fetchImpl: options.fetchImpl, method: 'POST', path: '/v1/rotate', timeoutMs, token: used, url: options.url }) + const answer = await relayRequest<{ token?: string }>({ fetchImpl: options.fetchImpl, method: 'POST', path: '/v1/rotate', site: relayHost(payload, options), timeoutMs, token: used, url: options.url }) if (answer.ok && typeof answer.body.token === 'string' && answer.body.token) { const fresh = answer.body.token await updateRelayStore(payload, (current) => ({ @@ -364,7 +378,7 @@ export async function disconnectRelay(payload: BasePayload, options: ResolvedRel // (a store copied from another host is dropped by this read: that site's token is never revoked from here) const stored = await readSiteStore(payload, options) if (stored.token && options.token === undefined) { - const answer = await relayRequest({ fetchImpl: options.fetchImpl, method: 'POST', path: '/v1/revoke', token: stored.token, url: options.url }) + const answer = await relayRequest({ fetchImpl: options.fetchImpl, method: 'POST', path: '/v1/revoke', site: relayHost(payload, options), token: stored.token, url: options.url }) // Only the service's own word counts: "done", or "I do not know this token" (it is gone already). if (!answer.ok && !(answer.code === 'invalid-token' && !answer.noAnswer)) { // Not confirmed: the site stops using the token now, but it still works at the service. It is kept so diff --git a/test/mailRelay.test.ts b/test/mailRelay.test.ts index 619ee2b..0caeeee 100644 --- a/test/mailRelay.test.ts +++ b/test/mailRelay.test.ts @@ -252,7 +252,7 @@ describe('when the service asks the site to enrol again', () => { const { fake, options, payload } = relaySite({ fake: { allow: [HOST] } }) await sendThroughRelay(payload, options, MESSAGE) const old = (await readRelayStore(payload)).token! - await fake.handle(new Request(`${fake.url}/v1/revoke`, { headers: { authorization: `Bearer ${old}` }, method: 'POST' })) + await fake.handle(new Request(`${fake.url}/v1/revoke`, { headers: { authorization: `Bearer ${old}`, 'x-intecion-site': HOST }, method: 'POST' })) expect((await sendThroughRelay(payload, options, { ...MESSAGE, subject: 'Again' })).sent).toBe(true) expect((await readRelayStore(payload)).token).not.toBe(old) }) @@ -585,7 +585,7 @@ describe('the token over time', () => { const fresh = (await readRelayStore(b.payload)).token expect(fresh).not.toBe(old) // a container that still held the old token asks too: already-rotated — the store has the newer one, nothing is lost - const late = await a.fake.handle(new Request(`${a.fake.url}/v1/rotate`, { headers: { authorization: `Bearer ${old}` }, method: 'POST' })) + const late = await a.fake.handle(new Request(`${a.fake.url}/v1/rotate`, { headers: { authorization: `Bearer ${old}`, 'x-intecion-site': HOST }, method: 'POST' })) expect(((await late.json()) as { code: string }).code).toBe('already-rotated') expect((await sendThroughRelay(b.payload, a.options, { ...MESSAGE, subject: 'From B' })).sent).toBe(true) expect((await readRelayStore(a.payload)).token).toBe(fresh) @@ -596,7 +596,7 @@ describe('the token over time', () => { await sendThroughRelay(payload, options, MESSAGE) const old = (await readRelayStore(payload)).token! // another process rotated and its answer was lost: the store still has the old token - await fake.handle(new Request(`${fake.url}/v1/rotate`, { headers: { authorization: `Bearer ${old}` }, method: 'POST' })) + await fake.handle(new Request(`${fake.url}/v1/rotate`, { headers: { authorization: `Bearer ${old}`, 'x-intecion-site': HOST }, method: 'POST' })) expect(await rotateRelayToken(payload, options, { force: true })).toBe('failed') expect((await readRelayStore(payload)).token).toBeUndefined() expect((await sendThroughRelay(payload, options, { ...MESSAGE, subject: 'Healed' })).sent).toBe(true) @@ -609,7 +609,7 @@ describe('the token over time', () => { const old = (await readRelayStore(payload)).token! await disconnectRelay(payload, options) expect(await readRelayStore(payload)).toEqual({ disconnected: true, v: 1 }) - const refusedByService = await fake.handle(new Request(`${fake.url}/v1/status`, { headers: { authorization: `Bearer ${old}` } })) + const refusedByService = await fake.handle(new Request(`${fake.url}/v1/status`, { headers: { authorization: `Bearer ${old}`, 'x-intecion-site': HOST } })) expect(refusedByService.status).toBe(401) const before = fake.requests.length expect(await sendThroughRelay(payload, options, MESSAGE)).toMatchObject({ code: 'relay-disconnected', sent: false }) @@ -636,7 +636,7 @@ describe('the token over time', () => { expect(await mailPanelState({ payload }, options)).toMatchObject({ relay: { connected: true, refusal: { code: 'reverify' }, tokenSource: 'manual' } }) fake.clientAddress = '203.0.113.10' - await fake.handle(new Request(`${fake.url}/v1/revoke`, { headers: { authorization: `Bearer ${token}` }, method: 'POST' })) + await fake.handle(new Request(`${fake.url}/v1/revoke`, { headers: { authorization: `Bearer ${token}`, 'x-intecion-site': HOST }, method: 'POST' })) const gone = await sendThroughRelay(payload, options, { ...MESSAGE, subject: 'Gone' }) expect(gone).toMatchObject({ cause: 'invalid-token', code: 'relay-refused', sent: false }) expect(gone.sent === false && gone.detail).toMatch(/ask Intecion for a new token/) @@ -790,7 +790,7 @@ describe('review of 7d766b6: R-1 to R-7, R-11, and four mutations it found uncau expect((await readRelayStore(payload)).token).toBeUndefined() expect((await getRelayStatus(payload, options)).refusal).toMatchObject({ code: 'client-foreign-token' }) // the other site's token still works there - expect((await fake.handle(new Request(`${fake.url}/v1/status`, { headers: { authorization: `Bearer ${foreign}` } }))).status).toBe(200) + expect((await fake.handle(new Request(`${fake.url}/v1/status`, { headers: { authorization: `Bearer ${foreign}`, 'x-intecion-site': 'other-client.example.org' } }))).status).toBe(200) // the site's own token, issued by hand for its host, passes the same check await setRelayToken(payload, fake.issueToken(HOST)) expect((await sendThroughRelay(payload, options, MESSAGE)).sent).toBe(true) @@ -801,6 +801,28 @@ describe('review of 7d766b6: R-1 to R-7, R-11, and four mutations it found uncau expect(await sendThroughRelay(payload, { ...options, totalTimeoutMs: 300 }, MESSAGE)).toMatchObject({ code: 'relay-unreachable', confirmed: true, sent: false }) }) + test('contract 1.7.0: every request with a token names the site, and 403 host-mismatch means "not yours: enrol as yourself"', async () => { + const { fake, options, payload } = relaySite({ fake: { allow: [HOST, 'other-client.example.org'] } }) + const headers: (null | string)[] = [] + fake.intercept = (request) => void (request.headers.has('authorization') && headers.push(request.headers.get('x-intecion-site'))) + await sendThroughRelay(payload, options, MESSAGE) + await refreshRelayStatus(payload, options) + await rotateRelayToken(payload, options, { force: true }) + expect(headers.length).toBeGreaterThanOrEqual(3) + expect(new Set(headers)).toEqual(new Set([HOST])) + // a token of another site sits in the store under this site's host (the comparison of hosts cannot see it) + const foreign = fake.issueToken('other-client.example.org') + await updateRelayStore(payload, (current) => ({ ...current, token: foreign })) + const before = fake.requests.length + expect((await sendThroughRelay(payload, options, { ...MESSAGE, subject: 'As myself' })).sent).toBe(true) + expect(fake.requests.slice(before).map((r) => r.path)).toEqual(['/v1/send', '/v1/enrol', '/v1/send']) + expect(fake.outbox.at(-1)).toMatchObject({ host: HOST, subject: 'As myself' }) + expect((await readRelayStore(payload)).token).not.toBe(foreign) + // forgotten here, not revoked there + expect(fake.requests.map((r) => r.path)).not.toContain('/v1/revoke') + expect((await fake.handle(new Request(`${fake.url}/v1/status`, { headers: { authorization: `Bearer ${foreign}`, 'x-intecion-site': 'other-client.example.org' } }))).status).toBe(200) + }) + test('R-3: junk calls to the confirm route do not keep the site\'s own enrolment out', async () => { const { fake, options, payload } = relaySite({ fake: { allow: [HOST] } }) const confirm = callConfirmRoute(payload) // every call comes from one address, as the service's does @@ -872,12 +894,12 @@ describe('review of 7d766b6: R-1 to R-7, R-11, and four mutations it found uncau expect(await getRelayStatus(payload, options)).toMatchObject({ connected: false, disconnected: true, revokePending: true }) fake.intercept = undefined // the token still works at the service — that is why the panel must not say "done" - expect((await fake.handle(new Request(`${fake.url}/v1/status`, { headers: { authorization: `Bearer ${token}` } }))).status).toBe(200) + expect((await fake.handle(new Request(`${fake.url}/v1/status`, { headers: { authorization: `Bearer ${token}`, 'x-intecion-site': HOST } }))).status).toBe(200) expect(await sendThroughRelay(payload, options, MESSAGE)).toMatchObject({ code: 'relay-disconnected', sent: false }) // pressed again with the service back: revoked and forgotten expect(await disconnectRelay(payload, options)).toEqual({ revoked: true }) expect(await readRelayStore(payload)).toEqual({ disconnected: true, v: 1 }) - expect((await fake.handle(new Request(`${fake.url}/v1/status`, { headers: { authorization: `Bearer ${token}` } }))).status).toBe(401) + expect((await fake.handle(new Request(`${fake.url}/v1/status`, { headers: { authorization: `Bearer ${token}`, 'x-intecion-site': HOST } }))).status).toBe(401) }) test('R-6: without the confirm route in the config the site does not ask to be enrolled', async () => { diff --git a/test/mailRelayContract.test.ts b/test/mailRelayContract.test.ts index c3b2643..4a38e2c 100644 --- a/test/mailRelayContract.test.ts +++ b/test/mailRelayContract.test.ts @@ -135,7 +135,7 @@ describe('the fake service speaks the contract (the contract\'s runner, every ex token = fake.setSite(HOST, given.site as 'active') if (given.token === 'previous') { // the token in {{token}} was replaced a moment ago - const rotated = await fake.handle(new Request(`${fake.url}/v1/rotate`, { headers: { authorization: `Bearer ${token}` }, method: 'POST' })) + const rotated = await fake.handle(new Request(`${fake.url}/v1/rotate`, { headers: { authorization: `Bearer ${token}`, 'x-intecion-site': HOST }, method: 'POST' })) expect(rotated.status).toBe(200) } if (given.token === 'unknown') {token = `ims_${'u'.repeat(43)}`} @@ -151,7 +151,7 @@ describe('the fake service speaks the contract (the contract\'s runner, every ex const body = expand(example.request.body, vars, example.id) as Record const first = await fake.handle(new Request(`${fake.url}/v1/send`, { body: JSON.stringify(given.idempotency === 'sent-same' ? body : { ...body, subject: 'Another message' }), - headers: { authorization: `Bearer ${token}`, 'content-type': 'application/json', 'idempotency-key': vars.idempotencyKey }, + headers: { authorization: `Bearer ${token}`, 'content-type': 'application/json', 'idempotency-key': vars.idempotencyKey, 'x-intecion-site': HOST }, method: 'POST', })) expect(first.status).toBe(200) diff --git a/test/mailRelayHttp.test.ts b/test/mailRelayHttp.test.ts index f59e491..012ff4e 100644 --- a/test/mailRelayHttp.test.ts +++ b/test/mailRelayHttp.test.ts @@ -228,7 +228,7 @@ describe('the state routes are for admins', () => { expect(refused.status).toBe(400) expect(await refused.text()).not.toContain('ims_') expect((await readRelayStore(payload)).token).toBeUndefined() - expect((await fake.handle(new Request(`${fake.url}/v1/status`, { headers: { authorization: `Bearer ${foreign}` } }))).status).toBe(200) + expect((await fake.handle(new Request(`${fake.url}/v1/status`, { headers: { authorization: `Bearer ${foreign}`, 'x-intecion-site': 'other-client.example.org' } }))).status).toBe(200) // a token issued by hand for THIS host is taken, and the state says where it came from const own = await post('/iapl/mail-relay/connect', admin, { token: fake.issueToken(HOST) }) expect(await own.json()).toMatchObject({ ok: true, relay: { connected: true, tokenSource: 'manual' } }) diff --git a/test/mailRelayService.test.ts b/test/mailRelayService.test.ts index 6d201d0..834ea4c 100644 --- a/test/mailRelayService.test.ts +++ b/test/mailRelayService.test.ts @@ -174,14 +174,14 @@ describe.skipIf(!SERVICE || !local)('against the real service code, run locally' const fresh = (await readRelayStore(payload)).token! expect(fresh).not.toBe(old) expect((await sendThroughRelay(payload, options, { ...MESSAGE, subject: 'After rotation' })).sent).toBe(true) - const again = await relayRequest({ method: 'POST', path: '/v1/rotate', token: old, url: SERVICE }) + const again = await relayRequest({ method: 'POST', path: '/v1/rotate', site: HOST, token: old, url: SERVICE }) expect(again).toMatchObject({ code: 'already-rotated', ok: false, retryable: false }) }) test('"Disconnect" revokes: the token stops working at once; "Connect again" enrols anew', async () => { const token = (await readRelayStore(payload)).token! await disconnectRelay(payload, options) - expect(await relayRequest({ method: 'GET', path: '/v1/status', token, url: SERVICE })).toMatchObject({ code: 'invalid-token', ok: false }) + expect(await relayRequest({ method: 'GET', path: '/v1/status', site: HOST, token, url: SERVICE })).toMatchObject({ code: 'invalid-token', ok: false }) expect(await sendThroughRelay(payload, options, MESSAGE)).toMatchObject({ code: 'relay-disconnected', sent: false }) expect(await enrolRelay(payload, options, { force: true })).toEqual({ ok: true, state: 'active' }) expect((await sendThroughRelay(payload, options, { ...MESSAGE, subject: 'Back' })).sent).toBe(true)