Mail relay: contract 1.7.0 — X-Intecion-Site on every request with a token, host-mismatch

contracts/mail-relay refreshed from IWDL 6cd99f7 (64 files). A token the service knows as another
site's is forgotten without revoking and the site enrols as itself; a hand-issued one is refused.
The fake requires the header and answers host-mismatch.

Co-Authored-By: Claude Fable 5.2 <[email protected]>
This commit is contained in:
Radosław Smoliński
2026-11-25 22:13:58 +01:00
co-authored by Claude Fable 5.2
parent a2b07b1dc1
commit fef2c51bae
60 changed files with 326 additions and 118 deletions
+14 -1
View File
@@ -1,6 +1,19 @@
# Changelog of the wire contract # 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: <own host>` 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 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. contract's words. What a client built against 1.5.0 has to change is marked.
+46 -44
View File
@@ -1,8 +1,8 @@
a5cc857363323400a6d24b45804c8fd964392cd0e61e99a8b120b354ac803e33 README.md 9b254d1aebe0e3e11539f95bb9eabba8984a77f27ea1a12ab9c259f3a3f2df94 README.md
05d026ddc45ee9824534ce13f5b8f14bd1475688fe98949e3297f90548e3abb0 CHANGELOG.md cf9e7137ac9190773856b5d284544d04c188c852a3f3a92f6f68f561060c8626 CHANGELOG.md
cb1d9a30bc4ab8a397f39b7d786bb82aca0b816077eefc35d7c822017d75f6a5 VERSION bb7320d831e7a151aa901c35e7326c752fa2ef5024f30768c42319b8bed171ed VERSION
275ee643112eac77430dba9ea3f93c8f53dc1676b8d56ba95a25dd3f35a8746f schema.json 2ff0ad5b6a245365c0fa8733fa17b7bbd3ab91d4825981709d0fd02b762b939f schema.json
913d3776b27076bf1d89639ef903f80c1c1b9bcd702851e9913def2588d73d83 runner.mjs 766fe0ed81037c230ab64e9fea2f9e6e5e828c5744bd90c61d9a2ad374a83100 runner.mjs
7c46860adee597e570832c72bcdb418752a20b9f7d1b2d7a656ed065f9632b2a checksums.mjs 7c46860adee597e570832c72bcdb418752a20b9f7d1b2d7a656ed065f9632b2a checksums.mjs
df6015faf02a7cf7e9b5816b9e22b2e82968678ddd72a61c1f9665a8c0897ddf examples/callback-confirm-wordpress.json df6015faf02a7cf7e9b5816b9e22b2e82968678ddd72a61c1f9665a8c0897ddf examples/callback-confirm-wordpress.json
f5018ca4fb7d25794ee92168d715aaf47feeba3d907c0550651b16c10a691ceb examples/callback-confirm.json f5018ca4fb7d25794ee92168d715aaf47feeba3d907c0550651b16c10a691ceb examples/callback-confirm.json
@@ -21,42 +21,44 @@ e86e6ab23088c1c985ba18f287f66b49c50f51a584a7ca679b8b768597130efd examples/enrol
fe38f1fd1394a7fd42b1a1b0b74aa604578f17ab52590bf95a462a0c0f7d6087 examples/enrol-unlisted-pending.json fe38f1fd1394a7fd42b1a1b0b74aa604578f17ab52590bf95a462a0c0f7d6087 examples/enrol-unlisted-pending.json
b9f71fe993dc39bdbc07e775e925a37175e18e1682fd8bffcc72b3581919be17 examples/health.json b9f71fe993dc39bdbc07e775e925a37175e18e1682fd8bffcc72b3581919be17 examples/health.json
5dff4194764f6f61b01a3f7f504907e578306a486d214e22d1a70b1a207e5ca3 examples/not-found.json 5dff4194764f6f61b01a3f7f504907e578306a486d214e22d1a70b1a207e5ca3 examples/not-found.json
7df29aaf11934bb3a73f6899c66c4f73cfcc048c804ca52871b60376323cb222 examples/revoke-ok.json 94943f85503cd891f1fb6f0258ab97b2eb48ec10e5f7ea233d349d4da97b8a1b examples/revoke-ok.json
148ae206781250f5de72d8d8f024fb1a0ba9c61c3f14c2866cdbda5244940097 examples/rotate-ok.json 1b467eac1040d56369276e5b8c12540a84942c8b7e3c2e458fc8da5b4f027c86 examples/rotate-ok.json
81b6eeec98cdc35860241b1a958ab35cf6de2872bf1ffcdb24629156f5308996 examples/rotate-previous-token.json 348f96a160c168797ab27ff0739b17df1762cc2ffdd72cb0a2b3ec2c695093bc examples/rotate-previous-token.json
2e9b2d088310ed1965639ad48e3aa4753ca277bb4c7119b8b58b082d25a5f46c examples/send-attachments-too-large.json 39774a2ce0434dc791d79f9efb4b14f23203b7e8d58138acc7654265a875609b examples/send-attachments-too-large.json
3585fde1439db56351a99c40e8262f606a3884eb4035546c76591279adbba0e8 examples/send-backend-failed.json 75ec4de22780b36b41f198f065e38937beb4a50879fd204e080bdb935c2b5e8f examples/send-backend-failed.json
938761bbe576ca2da017cff8a42c4586bee971b9f5ce27a2fa024f7643fa1d3e examples/send-bearer-any-case.json e3331a33604c2239c91c889d3dd338e473fd9b5d80fccb84a39491810bcceac0 examples/send-bearer-any-case.json
dbfdf96f791057e7a228330dba706cdcdf07f87d46d37734e2f4a3a49d557db0 examples/send-day-quota.json 26f4f8a2929d132598bcb87e813616cef7b6277249c657cc618f4ede4cb4d906 examples/send-day-quota.json
93455791565a0b2f8d464aed858cc470a014bf16c943d3883383a145e43424f9 examples/send-display-name-recipient.json 660dbe2a747686077788f46fe45f269c3eb57e4579225979f91841e9f00fae7b examples/send-display-name-recipient.json
01d7927fa99572fee0adf73c9d079ca7a544c3bf90d90c068e4b85137b59b53d examples/send-executable-attachment.json 1c6bd0ed454f51acf545f0213fe6108f3639af975fb0751ef8d23bd92da9d4c7 examples/send-executable-attachment.json
54db430c75ae132fda615f5a27a2e8d0f53157acdceedaba2c035edd1938f0e9 examples/send-from-browser.json ed6869754e418cc5e2a809e52a0242680d79f1bbc2eedd391de04375f29f7b9a examples/send-from-browser.json
650c8a79f38901e0027d3e105ad8e8edaab776f091011930093b7b1bc96bad66 examples/send-from-field.json e39d197f857b56103726b0f165c67a3476a06207961a59c6f6a1cf333bc3e7e9 examples/send-from-field.json
f9db7bdf34887406fdf80e037c83212e9523c553a2566fe7d1a9411a491cd85c examples/send-headers-field.json 5c826cd0c297c773510ce37b66a0f6a6425e6282abc1ad30094fd5b545ae9193 examples/send-headers-field.json
5679e08b88d2206dc6810f73bb2139a8f7f46b7fd0470420081f8543e4466889 examples/send-hour-quota-account.json 3918635b33b32783db96ae17ebbd4296d2deca05d092b55573c574be172601ec examples/send-host-mismatch.json
40828edcba271529de9d452239fb218afc63a1dd6606c5e201ad622f2748ba09 examples/send-hour-quota.json a6809a8d475106f8e31ba432e56b46e9bf8683a0eca9d62378b1392cd6c44305 examples/send-hour-quota-account.json
60e2eb9841a379c3985ae53e0c821a9e8a6f1de1cffc41f55f63a2bf91ffb315 examples/send-key-reused.json c46852c9d9fc7eb83ac6bc3ca2a7c5b79100d2cae93a5cee6720b702b4c22490 examples/send-hour-quota.json
6b10a5fce8dc51188cad654804bf742d9221e3825f04c688d724c2c8893bc2af examples/send-no-sender-name.json dc0f9c1c946d256aded0de70588c1d1f95740d333b234127f9bce8a4ed8beefb examples/send-key-reused.json
1c37294029f41bb3953245950bde50ef6f550f9459aa16df525d4f8897f6f610 examples/send-no-token.json 69edbf23c9723337f6327484e587b8cb7603c23e4b4954ebd275a0a794171325 examples/send-no-sender-name.json
3408947e979677ab07bdac2939c716083c78bdf75ac0e06993cc68fcdbae071f examples/send-ok.json bcbf5adcd0c224edb81c3b4188f261252835f715f541030db10432fa7ebd71a4 examples/send-no-token.json
3660c55e7a359183793fd06c73a8c8c1529670e720cd9aa933a0a915b7f18a9f examples/send-pending.json 32125ac9ff5460991633cce55febcb310247ca518eae7c650ef634e3f86376e0 examples/send-ok.json
cec3126afeffbc18ee02a23556c184dc9195f05a0fc9cff8a31be7bbd444a557 examples/send-previous-token.json 7d8b14d372730f013ee7192021dda68859f779337b8d535bc564ac955a00e325 examples/send-pending.json
b3b8ca0aae457e1d7afaa557b73ba1ab9c6c6427727c5d159e5290427f05ad8c examples/send-recipient-quota-other-kinds.json e3bbb041217d0a4f378285c06584a093d5e808d223d564e735c559f461fae8b8 examples/send-previous-token.json
9ac1a9cccea648f5a54c55abd7d2271ac8b1916d789138f09bbacff1960c45eb examples/send-recipient-quota.json 53132e3e2177937dc2a35f7fe87f2f383f45ab001fc0306490941b44bb466e3c examples/send-recipient-quota-other-kinds.json
84d37df95af790ade19255736868fc38295e2674082dfec1c13f64031f88571c examples/send-recipient-suppressed.json aff454882faab57d4a697be7250fdbac0272bcc2e0c099a6a27c50e0a980ac70 examples/send-recipient-quota.json
5243b6a33a200c4e57f1f32bf285bd7a1499663e3073462e057548c2e1201d9f examples/send-replay.json d514bc65a75f522389c90f1239d9afa43d96c7c2e7bd31fe0e85dd4c9d543ebd examples/send-recipient-suppressed.json
40b86320ccfbe321b2831672035df618b4f5a6b3a70e398260698b4690b9c9a8 examples/send-security-alert.json eb68d83a8d582a3722bf99330246d3d641e49a53e08bbe48e04e09a970cbb866 examples/send-replay.json
af073fb884954c55f606fd2c6f7dc0bbedc29ec6b0daff4c77e91c16c129ac6d examples/send-sender-name-replaced.json 189dbdb3df1f0da0b6a1e8fdd0e90babf9dbfe9cfcaeb423ba24e2d59802b663 examples/send-security-alert.json
bf0ce766240ad5df96176a8a6e0f54e7eaa533262657c8105ce342f957f156fb examples/send-subject-direction-mark.json f299bc4f5193de0619d78551653a0b133a4ae5774dba93b23812b689a074a87d examples/send-sender-name-replaced.json
47824ad6a90c27da507a98fef4e31486f8fac445d4f0657c6f98312752884da0 examples/send-subject-imitates-service.json 39a09b2bd01fc12d0e8cb2f93b71b24f31a4f2d0f639fe93b6bf37a7357be0ae examples/send-subject-direction-mark.json
85d43f2c6855accbece8bf09c281544355421de308850846fe28b7aa457fab21 examples/send-subject-line-break.json ce4cbea2306f73bd5905249c10ab451a2599cb779e2386828971f40c97b8c591 examples/send-subject-imitates-service.json
be98bd6277fadc03eacfa901ac15c9f69895ddfb3b01fbf40d849e9eeded61fe examples/send-subject-visitor-text.json 247619f5575e898bd558ff7f7674f241c39f3a1e0ae51f589eb6a6dc2fe21e2b examples/send-subject-line-break.json
a5dddf15899dfb6d7212b63f5bc32819d7f35a14872daae4f46324555bffa0e1 examples/send-suspended.json 59175981e46a6f782ce3b4ed9c885699d7766823d660e5a524e89a4f2c6c459a examples/send-subject-visitor-text.json
bcf24c613cfb4eb223667ab2eee8ca6ebe91a6f97b86e6545b9d9316c63ca728 examples/send-text-plain.json 987a2b4433161b4f2a6502d0487bf18f512f7a630a930ac66b1038cd6e000dc3 examples/send-suspended.json
725fc1f4b059dc192f49955f67df4263f4a67f618b7314ca87ddfd7647e4514e examples/send-to-intecion-marked.json 91cd894526eef28e4dfb2456e476ba0be381e6d621ea833761cc9c63fe247e03 examples/send-text-plain.json
aac0a3d17fe69e8d6c0adbcd3513650c2802b7f43c2103d5cd3de5a0346456c0 examples/send-too-many-recipients.json 9c6278fcb13d7e06e0dd38ef34eba1abfbcb9c75100994b93c1c5a5444c35f85 examples/send-to-intecion-marked.json
4833a6b7cf81eba320f20c33fd44cb990681144186218332c2fb97a043b774cf examples/send-unknown-address.json 1a1faf5a451220a35f2f0d66bb906e0d9944ed0a71c8209e07da419734a82567 examples/send-too-many-recipients.json
1ad0d24c691ab35b5603d63f5b29c5a3a3e50265aea9524fd26d314c0b7c1437 examples/send-unknown-token.json 43d04c99549a4fe3c64af6f68b598299e92486af5a52432a2c93c3f9564f7959 examples/send-unknown-address.json
cd2812d7b33698851116dd96fc1019e7ddfcc7f0b14511c6fa8f1b94acbfdb7e examples/status-active.json 28e05f3c53cab6433b6af4d425511fa6655d0673df2e840af1fed9d25294a123 examples/send-unknown-token.json
e1bbb759fc3f7084d4bc027fa7d490cf0d24bc8ca124bd9a82e5dde372eb7bcd examples/status-pending.json f105c38ab11ab5fc508ba0ed3f23f69108c318765c2670029b230b5b9a83912a examples/status-active.json
daaf53c17b92e61049b230e6a91edf9450967d920c05d23b3da67959e27474e4 examples/status-unknown-address.json 89009ee9ab8f38e9ec290fb5412f206e1be28ad10fce6a7071d4406ac52dd4f0 examples/status-no-site-header.json
c9f49fa0dae1f0beacaacfe01660b467d06f990228c35a653307c8793f3c97a5 examples/status-pending.json
afdb07ba8279479b6bbfdc4289efda657d4e5a9eccd94b8de165ec728b4a2386 examples/status-unknown-address.json
+33 -7
View File
@@ -1,6 +1,6 @@
# Intecion Notifications Webservice — wire contract # 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 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 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 | `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 | `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 | `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 | — | — | | 403 | `browser-not-allowed` | The request came from a browser | no | — | — |
| 404 | `not-found` | No such route | no | Report a bug | — | | 404 | `not-found` | No such route | no | Report a bug | — |
| 405 | `method-not-allowed` | Wrong method | 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": "<lowercase hex SHA-256 of nonce + \".\" + token>" } { "confirmation": "<lowercase hex SHA-256 of nonce + \".\" + token>" }
``` ```
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, **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 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_… Authorization: Bearer ims_…
X-Intecion-Site: example.com
Idempotency-Key: <16 to 128 characters of A–Z a–z 0–9 _ -> Idempotency-Key: <16 to 128 characters of A–Z a–z 0–9 _ ->
Content-Type: application/json Content-Type: application/json
``` ```
@@ -350,7 +360,7 @@ not go out ([`StatusResponse`](schema.json)):
```json ```json
{ "ok": true, "state": "active", "host": "example.com", "product": "iapl", { "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": "[email protected]" }, "sender": { "address": "[email protected]" },
"limits": { "messagesPerHour": 30, "messagesPerDay": 200, "recipientsPerMessage": 10, "limits": { "messagesPerHour": 30, "messagesPerDay": 200, "recipientsPerMessage": 10,
"perRecipientPerDay": 10, "newRecipientsPerDay": 50, "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 - 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` 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. 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 site's own public host>`** (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 ## 9. Versions
@@ -492,9 +515,12 @@ hand-edited copy fails. The copy's `VERSION` says which contract the client spea
Checklist for a client: Checklist for a client:
1. Constants: the base address, the contract version. No secret. 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 2. A confirm endpoint (public; `404` unless it holds the nonce; the nonce looked up before any limiter, and
use, answers the confirmation as the only output, keeps the earlier token until the new one is accepted). 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. 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 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 issued by hand: then stop and report (§2). Guard against two processes enrolling at once
(`enrolment-in-progress`). (`enrolment-in-progress`).
+1 -1
View File
@@ -1 +1 @@
1.6.0 1.7.0
+2 -1
View File
@@ -8,7 +8,8 @@
"method": "POST", "method": "POST",
"path": "/v1/revoke", "path": "/v1/revoke",
"headers": { "headers": {
"authorization": "Bearer {{token}}" "authorization": "Bearer {{token}}",
"x-intecion-site": "{{host}}"
} }
}, },
"response": { "response": {
+2 -1
View File
@@ -8,7 +8,8 @@
"method": "POST", "method": "POST",
"path": "/v1/rotate", "path": "/v1/rotate",
"headers": { "headers": {
"authorization": "Bearer {{token}}" "authorization": "Bearer {{token}}",
"x-intecion-site": "{{host}}"
} }
}, },
"response": { "response": {
@@ -9,7 +9,8 @@
"method": "POST", "method": "POST",
"path": "/v1/rotate", "path": "/v1/rotate",
"headers": { "headers": {
"authorization": "Bearer {{token}}" "authorization": "Bearer {{token}}",
"x-intecion-site": "{{host}}"
} }
}, },
"response": { "response": {
@@ -10,7 +10,8 @@
"headers": { "headers": {
"authorization": "Bearer {{token}}", "authorization": "Bearer {{token}}",
"idempotency-key": "{{idempotencyKey}}", "idempotency-key": "{{idempotencyKey}}",
"content-type": "application/json" "content-type": "application/json",
"x-intecion-site": "{{host}}"
}, },
"schema": "SendRequest", "schema": "SendRequest",
"body": { "body": {
@@ -11,7 +11,8 @@
"headers": { "headers": {
"authorization": "Bearer {{token}}", "authorization": "Bearer {{token}}",
"idempotency-key": "{{idempotencyKey}}", "idempotency-key": "{{idempotencyKey}}",
"content-type": "application/json" "content-type": "application/json",
"x-intecion-site": "{{host}}"
}, },
"schema": "SendRequest", "schema": "SendRequest",
"body": { "body": {
@@ -10,7 +10,8 @@
"headers": { "headers": {
"authorization": "bearer {{token}}", "authorization": "bearer {{token}}",
"idempotency-key": "{{idempotencyKey}}", "idempotency-key": "{{idempotencyKey}}",
"content-type": "application/json" "content-type": "application/json",
"x-intecion-site": "{{host}}"
}, },
"schema": "SendRequest", "schema": "SendRequest",
"body": { "body": {
@@ -11,7 +11,8 @@
"headers": { "headers": {
"authorization": "Bearer {{token}}", "authorization": "Bearer {{token}}",
"idempotency-key": "{{idempotencyKey}}", "idempotency-key": "{{idempotencyKey}}",
"content-type": "application/json" "content-type": "application/json",
"x-intecion-site": "{{host}}"
}, },
"schema": "SendRequest", "schema": "SendRequest",
"body": { "body": {
@@ -10,7 +10,8 @@
"headers": { "headers": {
"authorization": "Bearer {{token}}", "authorization": "Bearer {{token}}",
"idempotency-key": "{{idempotencyKey}}", "idempotency-key": "{{idempotencyKey}}",
"content-type": "application/json" "content-type": "application/json",
"x-intecion-site": "{{host}}"
}, },
"body": { "body": {
"product": "iapl", "product": "iapl",
@@ -10,7 +10,8 @@
"headers": { "headers": {
"authorization": "Bearer {{token}}", "authorization": "Bearer {{token}}",
"idempotency-key": "{{idempotencyKey}}", "idempotency-key": "{{idempotencyKey}}",
"content-type": "application/json" "content-type": "application/json",
"x-intecion-site": "{{host}}"
}, },
"schema": "SendRequest", "schema": "SendRequest",
"body": { "body": {
@@ -11,7 +11,8 @@
"authorization": "Bearer {{token}}", "authorization": "Bearer {{token}}",
"idempotency-key": "{{idempotencyKey}}", "idempotency-key": "{{idempotencyKey}}",
"content-type": "application/json", "content-type": "application/json",
"origin": "https://evil.example.net" "origin": "https://evil.example.net",
"x-intecion-site": "{{host}}"
}, },
"schema": "SendRequest", "schema": "SendRequest",
"body": { "body": {
@@ -10,7 +10,8 @@
"headers": { "headers": {
"authorization": "Bearer {{token}}", "authorization": "Bearer {{token}}",
"idempotency-key": "{{idempotencyKey}}", "idempotency-key": "{{idempotencyKey}}",
"content-type": "application/json" "content-type": "application/json",
"x-intecion-site": "{{host}}"
}, },
"body": { "body": {
"product": "iapl", "product": "iapl",
@@ -10,7 +10,8 @@
"headers": { "headers": {
"authorization": "Bearer {{token}}", "authorization": "Bearer {{token}}",
"idempotency-key": "{{idempotencyKey}}", "idempotency-key": "{{idempotencyKey}}",
"content-type": "application/json" "content-type": "application/json",
"x-intecion-site": "{{host}}"
}, },
"body": { "body": {
"product": "iapl", "product": "iapl",
@@ -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": "[email protected]",
"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
}
}
@@ -11,7 +11,8 @@
"headers": { "headers": {
"authorization": "Bearer {{token}}", "authorization": "Bearer {{token}}",
"idempotency-key": "{{idempotencyKey}}", "idempotency-key": "{{idempotencyKey}}",
"content-type": "application/json" "content-type": "application/json",
"x-intecion-site": "{{host}}"
}, },
"schema": "SendRequest", "schema": "SendRequest",
"body": { "body": {
@@ -11,7 +11,8 @@
"headers": { "headers": {
"authorization": "Bearer {{token}}", "authorization": "Bearer {{token}}",
"idempotency-key": "{{idempotencyKey}}", "idempotency-key": "{{idempotencyKey}}",
"content-type": "application/json" "content-type": "application/json",
"x-intecion-site": "{{host}}"
}, },
"schema": "SendRequest", "schema": "SendRequest",
"body": { "body": {
@@ -11,7 +11,8 @@
"headers": { "headers": {
"authorization": "Bearer {{token}}", "authorization": "Bearer {{token}}",
"idempotency-key": "{{idempotencyKey}}", "idempotency-key": "{{idempotencyKey}}",
"content-type": "application/json" "content-type": "application/json",
"x-intecion-site": "{{host}}"
}, },
"schema": "SendRequest", "schema": "SendRequest",
"body": { "body": {
@@ -10,7 +10,8 @@
"headers": { "headers": {
"authorization": "Bearer {{token}}", "authorization": "Bearer {{token}}",
"idempotency-key": "{{idempotencyKey}}", "idempotency-key": "{{idempotencyKey}}",
"content-type": "application/json" "content-type": "application/json",
"x-intecion-site": "{{host}}"
}, },
"schema": "SendRequest", "schema": "SendRequest",
"body": { "body": {
@@ -11,7 +11,8 @@
"headers": { "headers": {
"authorization": "Bearer {{token}}", "authorization": "Bearer {{token}}",
"idempotency-key": "{{idempotencyKey}}", "idempotency-key": "{{idempotencyKey}}",
"content-type": "application/json" "content-type": "application/json",
"x-intecion-site": "{{host}}"
}, },
"schema": "SendRequest", "schema": "SendRequest",
"body": { "body": {
+2 -1
View File
@@ -10,7 +10,8 @@
"headers": { "headers": {
"authorization": "Bearer {{token}}", "authorization": "Bearer {{token}}",
"idempotency-key": "{{idempotencyKey}}", "idempotency-key": "{{idempotencyKey}}",
"content-type": "application/json" "content-type": "application/json",
"x-intecion-site": "{{host}}"
}, },
"schema": "SendRequest", "schema": "SendRequest",
"body": { "body": {
@@ -10,7 +10,8 @@
"headers": { "headers": {
"authorization": "Bearer {{token}}", "authorization": "Bearer {{token}}",
"idempotency-key": "{{idempotencyKey}}", "idempotency-key": "{{idempotencyKey}}",
"content-type": "application/json" "content-type": "application/json",
"x-intecion-site": "{{host}}"
}, },
"schema": "SendRequest", "schema": "SendRequest",
"body": { "body": {
@@ -11,7 +11,8 @@
"headers": { "headers": {
"authorization": "Bearer {{token}}", "authorization": "Bearer {{token}}",
"idempotency-key": "{{idempotencyKey}}", "idempotency-key": "{{idempotencyKey}}",
"content-type": "application/json" "content-type": "application/json",
"x-intecion-site": "{{host}}"
}, },
"schema": "SendRequest", "schema": "SendRequest",
"body": { "body": {
@@ -11,7 +11,8 @@
"headers": { "headers": {
"authorization": "Bearer {{token}}", "authorization": "Bearer {{token}}",
"idempotency-key": "{{idempotencyKey}}", "idempotency-key": "{{idempotencyKey}}",
"content-type": "application/json" "content-type": "application/json",
"x-intecion-site": "{{host}}"
}, },
"schema": "SendRequest", "schema": "SendRequest",
"body": { "body": {
@@ -11,7 +11,8 @@
"headers": { "headers": {
"authorization": "Bearer {{token}}", "authorization": "Bearer {{token}}",
"idempotency-key": "{{idempotencyKey}}", "idempotency-key": "{{idempotencyKey}}",
"content-type": "application/json" "content-type": "application/json",
"x-intecion-site": "{{host}}"
}, },
"schema": "SendRequest", "schema": "SendRequest",
"body": { "body": {
@@ -11,7 +11,8 @@
"headers": { "headers": {
"authorization": "Bearer {{token}}", "authorization": "Bearer {{token}}",
"idempotency-key": "{{idempotencyKey}}", "idempotency-key": "{{idempotencyKey}}",
"content-type": "application/json" "content-type": "application/json",
"x-intecion-site": "{{host}}"
}, },
"schema": "SendRequest", "schema": "SendRequest",
"body": { "body": {
@@ -11,7 +11,8 @@
"headers": { "headers": {
"authorization": "Bearer {{token}}", "authorization": "Bearer {{token}}",
"idempotency-key": "{{idempotencyKey}}", "idempotency-key": "{{idempotencyKey}}",
"content-type": "application/json" "content-type": "application/json",
"x-intecion-site": "{{host}}"
}, },
"schema": "SendRequest", "schema": "SendRequest",
"body": { "body": {
@@ -10,7 +10,8 @@
"headers": { "headers": {
"authorization": "Bearer {{token}}", "authorization": "Bearer {{token}}",
"idempotency-key": "{{idempotencyKey}}", "idempotency-key": "{{idempotencyKey}}",
"content-type": "application/json" "content-type": "application/json",
"x-intecion-site": "{{host}}"
}, },
"schema": "SendRequest", "schema": "SendRequest",
"body": { "body": {
@@ -10,7 +10,8 @@
"headers": { "headers": {
"authorization": "Bearer {{token}}", "authorization": "Bearer {{token}}",
"idempotency-key": "{{idempotencyKey}}", "idempotency-key": "{{idempotencyKey}}",
"content-type": "application/json" "content-type": "application/json",
"x-intecion-site": "{{host}}"
}, },
"schema": "SendRequest", "schema": "SendRequest",
"body": { "body": {
@@ -10,7 +10,8 @@
"headers": { "headers": {
"authorization": "Bearer {{token}}", "authorization": "Bearer {{token}}",
"idempotency-key": "{{idempotencyKey}}", "idempotency-key": "{{idempotencyKey}}",
"content-type": "application/json" "content-type": "application/json",
"x-intecion-site": "{{host}}"
}, },
"schema": "SendRequest", "schema": "SendRequest",
"body": { "body": {
@@ -10,7 +10,8 @@
"headers": { "headers": {
"authorization": "Bearer {{token}}", "authorization": "Bearer {{token}}",
"idempotency-key": "{{idempotencyKey}}", "idempotency-key": "{{idempotencyKey}}",
"content-type": "application/json" "content-type": "application/json",
"x-intecion-site": "{{host}}"
}, },
"schema": "SendRequest", "schema": "SendRequest",
"body": { "body": {
@@ -10,7 +10,8 @@
"headers": { "headers": {
"authorization": "Bearer {{token}}", "authorization": "Bearer {{token}}",
"idempotency-key": "{{idempotencyKey}}", "idempotency-key": "{{idempotencyKey}}",
"content-type": "application/json" "content-type": "application/json",
"x-intecion-site": "{{host}}"
}, },
"schema": "SendRequest", "schema": "SendRequest",
"body": { "body": {
@@ -10,7 +10,8 @@
"headers": { "headers": {
"authorization": "Bearer {{token}}", "authorization": "Bearer {{token}}",
"idempotency-key": "{{idempotencyKey}}", "idempotency-key": "{{idempotencyKey}}",
"content-type": "application/json" "content-type": "application/json",
"x-intecion-site": "{{host}}"
}, },
"schema": "SendRequest", "schema": "SendRequest",
"body": { "body": {
@@ -10,7 +10,8 @@
"headers": { "headers": {
"authorization": "Bearer {{token}}", "authorization": "Bearer {{token}}",
"idempotency-key": "{{idempotencyKey}}", "idempotency-key": "{{idempotencyKey}}",
"content-type": "application/json" "content-type": "application/json",
"x-intecion-site": "{{host}}"
}, },
"schema": "SendRequest", "schema": "SendRequest",
"body": { "body": {
@@ -10,7 +10,8 @@
"headers": { "headers": {
"authorization": "Bearer {{token}}", "authorization": "Bearer {{token}}",
"idempotency-key": "{{idempotencyKey}}", "idempotency-key": "{{idempotencyKey}}",
"content-type": "text/plain" "content-type": "text/plain",
"x-intecion-site": "{{host}}"
}, },
"schema": "SendRequest", "schema": "SendRequest",
"body": { "body": {
@@ -10,7 +10,8 @@
"headers": { "headers": {
"authorization": "Bearer {{token}}", "authorization": "Bearer {{token}}",
"idempotency-key": "{{idempotencyKey}}", "idempotency-key": "{{idempotencyKey}}",
"content-type": "application/json" "content-type": "application/json",
"x-intecion-site": "{{host}}"
}, },
"schema": "SendRequest", "schema": "SendRequest",
"body": { "body": {
@@ -10,7 +10,8 @@
"headers": { "headers": {
"authorization": "Bearer {{token}}", "authorization": "Bearer {{token}}",
"idempotency-key": "{{idempotencyKey}}", "idempotency-key": "{{idempotencyKey}}",
"content-type": "application/json" "content-type": "application/json",
"x-intecion-site": "{{host}}"
}, },
"schema": "SendRequest", "schema": "SendRequest",
"body": { "body": {
@@ -11,7 +11,8 @@
"headers": { "headers": {
"authorization": "Bearer {{token}}", "authorization": "Bearer {{token}}",
"idempotency-key": "{{idempotencyKey}}", "idempotency-key": "{{idempotencyKey}}",
"content-type": "application/json" "content-type": "application/json",
"x-intecion-site": "{{host}}"
}, },
"schema": "SendRequest", "schema": "SendRequest",
"body": { "body": {
@@ -11,7 +11,8 @@
"headers": { "headers": {
"authorization": "Bearer {{token}}", "authorization": "Bearer {{token}}",
"idempotency-key": "{{idempotencyKey}}", "idempotency-key": "{{idempotencyKey}}",
"content-type": "application/json" "content-type": "application/json",
"x-intecion-site": "{{host}}"
}, },
"schema": "SendRequest", "schema": "SendRequest",
"body": { "body": {
@@ -8,7 +8,8 @@
"method": "GET", "method": "GET",
"path": "/v1/status", "path": "/v1/status",
"headers": { "headers": {
"authorization": "Bearer {{token}}" "authorization": "Bearer {{token}}",
"x-intecion-site": "{{host}}"
} }
}, },
"response": { "response": {
@@ -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
}
}
@@ -8,7 +8,8 @@
"method": "GET", "method": "GET",
"path": "/v1/status", "path": "/v1/status",
"headers": { "headers": {
"authorization": "Bearer {{token}}" "authorization": "Bearer {{token}}",
"x-intecion-site": "{{host}}"
} }
}, },
"response": { "response": {
@@ -9,7 +9,8 @@
"method": "GET", "method": "GET",
"path": "/v1/status", "path": "/v1/status",
"headers": { "headers": {
"authorization": "Bearer {{token}}" "authorization": "Bearer {{token}}",
"x-intecion-site": "{{host}}"
} }
}, },
"response": { "response": {
+1 -1
View File
@@ -2,7 +2,7 @@
// No dependency. Works in Node 20+ and in the Workers runtime (uses only WebCrypto, btoa and TextEncoder). // 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". // 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 { export class ContractError extends Error {
constructor(exampleId, message) { constructor(exampleId, message) {
+1
View File
@@ -556,6 +556,7 @@
"enrolment-closed", "enrolment-closed",
"enrolment-in-progress", "enrolment-in-progress",
"callback-failed", "callback-failed",
"host-mismatch",
"browser-not-allowed", "browser-not-allowed",
"not-found", "not-found",
"method-not-allowed", "method-not-allowed",
+1 -1
View File
@@ -116,7 +116,7 @@ once there are more than 20.
`withMailKind`, `runWithMailKind`, `mailKindOf`, `expectMailTo`, `buildFormMailKindHook`, `createFakeRelay` (the `withMailKind`, `runWithMailKind`, `mailKindOf`, `expectMailTo`, `buildFormMailKindHook`, `createFakeRelay` (the
service in memory, for tests), the constants `RELAY_*`, `MAIL_KINDS`, `MAIL_KIND`, `GRAPH_DEPRECATION_NOTICE`, and service in memory, for tests), the constants `RELAY_*`, `MAIL_KINDS`, `MAIL_KIND`, `GRAPH_DEPRECATION_NOTICE`, and
their types; `MailRelayStatus` from `/admin`. 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. 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. - **`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 Information, not a defect. A warning only for `iapl-doctor.json` and `ipal-doctor.json` side by side, or one variable
+2
View File
@@ -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 - 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, 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. attachment, reply address or recipient address) for 30 days.
- Every request that carries the token also names the site (`X-Intecion-Site: <host>`): 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: <host>` and `X-Intecion-Product: iapl` to every mail. - The service adds `X-Intecion-Site: <host>` 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 - 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. client's processing agreement before a client site sends through the service.
+1 -1
View File
@@ -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://<host>/api/iapl/mail-relay/confirm` with the nonce and a token, and only an answer that hashes both makes the token valid | | **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://<host>/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 | | **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 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 | | **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: <host>` on every mail. It cannot set `From`, `Return-Path` or any header, and cannot address a security alert | | **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: <host>` on every mail. It cannot set `From`, `Return-Path` or any header, and cannot address a security alert |
+6
View File
@@ -30,6 +30,11 @@ export type RelayCall = {
method: 'GET' | 'POST' method: 'GET' | 'POST'
/** Relative to the base address: `/v1/send`. */ /** Relative to the base address: `/v1/send`. */
path: string 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 timeoutMs?: number
token?: string token?: string
/** Base address, host and path prefix together; joined with `path` as text. */ /** Base address, host and path prefix together; joined with `path` as text. */
@@ -57,6 +62,7 @@ export async function relayRequest<T = Record<string, unknown>>(call: RelayCall)
'user-agent': `${RELAY_PRODUCT}/${PLUGIN_VERSION}`, 'user-agent': `${RELAY_PRODUCT}/${PLUGIN_VERSION}`,
...(call.body ? { 'content-type': 'application/json' } : {}), ...(call.body ? { 'content-type': 'application/json' } : {}),
...(call.token ? { authorization: `Bearer ${call.token}` } : {}), ...(call.token ? { authorization: `Bearer ${call.token}` } : {}),
...(call.token && call.site ? { 'x-intecion-site': call.site } : {}),
...(call.idempotencyKey ? { 'idempotency-key': call.idempotencyKey } : {}), ...(call.idempotencyKey ? { 'idempotency-key': call.idempotencyKey } : {}),
}, },
method: call.method, method: call.method,
+1 -1
View File
@@ -7,7 +7,7 @@
/** Base address: host and path together, joined with a path as text. Override: `mail: { relay: { url } }`. */ /** 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' export const RELAY_BASE_URL = 'https://webservices.intecion.net/mail'
/** The version of the copied contract this client speaks (`contracts/mail-relay/VERSION`). */ /** 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. */ /** The `product` value of this plugin. */
export const RELAY_PRODUCT = 'iapl' export const RELAY_PRODUCT = 'iapl'
/** The service's name, for docs, logs and the doctor. */ /** The service's name, for docs, logs and the doctor. */
+4
View File
@@ -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 || (!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.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.')} 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 // used most recently last: beyond the limit the address used longest ago is dropped
site.addresses = [...site.addresses.filter((a) => a !== address), address] site.addresses = [...site.addresses.filter((a) => a !== address), address]
return { current, site } return { current, site }
+4 -2
View File
@@ -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 // 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. // service does not know, is refused and the site's present connection stays as it is.
const ownHost = relayHost(req.payload, options) 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 }) const asked = await relayRequest<{ host?: string }>({ fetchImpl: options.fetchImpl, method: 'GET', path: '/v1/status', site: ownHost, 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)} // 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 === '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)} if (!asked.ok && asked.code !== 'reverify') {return json({ error: serverText(i18n, 'mailRelayLoadFailed'), ok: false }, 502)}
await setRelayToken(req.payload, pasted, { host: ownHost || undefined }) await setRelayToken(req.payload, pasted, { host: ownHost || undefined })
+4 -2
View File
@@ -9,6 +9,7 @@ import { type RelayAnswer, type RelayRefusal, relayRequest } from './client.js'
import { RELAY_DEFAULTS, type RelayStatusCode, relayStatusFor } from './constants.js' import { RELAY_DEFAULTS, type RelayStatusCode, relayStatusFor } from './constants.js'
import { currentMailKind, type MailKind, mailKindOf, takeExpectedMail } from './kinds.js' import { currentMailKind, type MailKind, mailKindOf, takeExpectedMail } from './kinds.js'
import { bareAddresses, buildRelayMessage, type RelaySendRequest } from './message.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 { LOCAL_CODES, readSiteStore, refreshRelayStatus, rotateRelayToken, type TokenUse, withRelayToken } from './session.js'
import { readRelayStore, sha256Hex, updateRelayStore } from './store.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') { 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.`) 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) const status = relayStatusFor(answer.code, answer.retryable)
// The mail back end failed without saying whether the message can still go out. // 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)) { 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 hash = createHash('sha256').update(body).digest('hex')
const idempotencyKey = keyFor(hash) const idempotencyKey = keyFor(hash)
const use: TokenUse = { deadline } const use: TokenUse = { deadline }
const site = relayHost(payload, options)
const budget = RELAY_DEFAULTS.waitBudgetMs const budget = RELAY_DEFAULTS.waitBudgetMs
let attempts = 0 let attempts = 0
let waited = 0 let waited = 0
@@ -205,7 +207,7 @@ export async function sendThroughRelay(payload: BasePayload, options: ResolvedRe
options, options,
(token) => { (token) => {
attempts += 1 attempts += 1
return relayRequest<SendBody>({ 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<SendBody>({ 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, use,
) )
+19 -5
View File
@@ -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 * `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. * `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. */ /** Whether an answer shows that the service accepted the token it was sent with. */
export const provesToken = (answer: RelayAnswer<unknown>): boolean => answer.ok || (!answer.noAnswer && TOKEN_SEEN.has(answer.code)) export const provesToken = (answer: RelayAnswer<unknown>): 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; * - 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 * - 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` 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 * 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 * 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 * 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<T>(
if (failed) {return use.enrolment && !use.enrolment.ok ? failed : answer} if (failed) {return use.enrolment && !use.enrolment.ok ? failed : answer}
continue 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 && !provesToken(answer)) {return answer} // says nothing about the token: both stay as they are
if (candidate) { if (candidate) {
// Seen accepted: this is the token now. // Seen accepted: this is the token now.
@@ -287,7 +301,7 @@ export async function refreshRelayStatus(payload: BasePayload, options: Resolved
const answer = await withRelayToken<StatusBody>( const answer = await withRelayToken<StatusBody>(
payload, payload,
options, options,
(token) => relayRequest<StatusBody>({ fetchImpl: options.fetchImpl, method: 'GET', path: '/v1/status', timeoutMs, token, url: options.url }), (token) => relayRequest<StatusBody>({ fetchImpl: options.fetchImpl, method: 'GET', path: '/v1/status', site: relayHost(payload, options), timeoutMs, token, url: options.url }),
timeoutMs === undefined ? {} : { deadline: Date.now() + timeoutMs }, timeoutMs === undefined ? {} : { deadline: Date.now() + timeoutMs },
{ first: false }, { 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 const due = stored.service?.rotateAfter ? Date.parse(stored.service.rotateAfter) : Number.NaN
if (!force && !(due <= Date.now())) {return 'not-due'} if (!force && !(due <= Date.now())) {return 'not-due'}
const used = stored.token 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) { if (answer.ok && typeof answer.body.token === 'string' && answer.body.token) {
const fresh = answer.body.token const fresh = answer.body.token
await updateRelayStore(payload, (current) => ({ 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) // (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) const stored = await readSiteStore(payload, options)
if (stored.token && options.token === undefined) { 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). // 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)) { 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 // Not confirmed: the site stops using the token now, but it still works at the service. It is kept so
+30 -8
View File
@@ -252,7 +252,7 @@ describe('when the service asks the site to enrol again', () => {
const { fake, options, payload } = relaySite({ fake: { allow: [HOST] } }) const { fake, options, payload } = relaySite({ fake: { allow: [HOST] } })
await sendThroughRelay(payload, options, MESSAGE) await sendThroughRelay(payload, options, MESSAGE)
const old = (await readRelayStore(payload)).token! 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 sendThroughRelay(payload, options, { ...MESSAGE, subject: 'Again' })).sent).toBe(true)
expect((await readRelayStore(payload)).token).not.toBe(old) expect((await readRelayStore(payload)).token).not.toBe(old)
}) })
@@ -585,7 +585,7 @@ describe('the token over time', () => {
const fresh = (await readRelayStore(b.payload)).token const fresh = (await readRelayStore(b.payload)).token
expect(fresh).not.toBe(old) 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 // 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 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 sendThroughRelay(b.payload, a.options, { ...MESSAGE, subject: 'From B' })).sent).toBe(true)
expect((await readRelayStore(a.payload)).token).toBe(fresh) expect((await readRelayStore(a.payload)).token).toBe(fresh)
@@ -596,7 +596,7 @@ describe('the token over time', () => {
await sendThroughRelay(payload, options, MESSAGE) await sendThroughRelay(payload, options, MESSAGE)
const old = (await readRelayStore(payload)).token! const old = (await readRelayStore(payload)).token!
// another process rotated and its answer was lost: the store still has the old 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 rotateRelayToken(payload, options, { force: true })).toBe('failed')
expect((await readRelayStore(payload)).token).toBeUndefined() expect((await readRelayStore(payload)).token).toBeUndefined()
expect((await sendThroughRelay(payload, options, { ...MESSAGE, subject: 'Healed' })).sent).toBe(true) 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! const old = (await readRelayStore(payload)).token!
await disconnectRelay(payload, options) await disconnectRelay(payload, options)
expect(await readRelayStore(payload)).toEqual({ disconnected: true, v: 1 }) 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) expect(refusedByService.status).toBe(401)
const before = fake.requests.length const before = fake.requests.length
expect(await sendThroughRelay(payload, options, MESSAGE)).toMatchObject({ code: 'relay-disconnected', sent: false }) 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' } }) expect(await mailPanelState({ payload }, options)).toMatchObject({ relay: { connected: true, refusal: { code: 'reverify' }, tokenSource: 'manual' } })
fake.clientAddress = '203.0.113.10' 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' }) const gone = await sendThroughRelay(payload, options, { ...MESSAGE, subject: 'Gone' })
expect(gone).toMatchObject({ cause: 'invalid-token', code: 'relay-refused', sent: false }) expect(gone).toMatchObject({ cause: 'invalid-token', code: 'relay-refused', sent: false })
expect(gone.sent === false && gone.detail).toMatch(/ask Intecion for a new token/) 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 readRelayStore(payload)).token).toBeUndefined()
expect((await getRelayStatus(payload, options)).refusal).toMatchObject({ code: 'client-foreign-token' }) expect((await getRelayStatus(payload, options)).refusal).toMatchObject({ code: 'client-foreign-token' })
// the other site's token still works there // 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 // the site's own token, issued by hand for its host, passes the same check
await setRelayToken(payload, fake.issueToken(HOST)) await setRelayToken(payload, fake.issueToken(HOST))
expect((await sendThroughRelay(payload, options, MESSAGE)).sent).toBe(true) 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 }) 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 () => { 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 { fake, options, payload } = relaySite({ fake: { allow: [HOST] } })
const confirm = callConfirmRoute(payload) // every call comes from one address, as the service's does 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 }) expect(await getRelayStatus(payload, options)).toMatchObject({ connected: false, disconnected: true, revokePending: true })
fake.intercept = undefined fake.intercept = undefined
// the token still works at the service — that is why the panel must not say "done" // 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 }) expect(await sendThroughRelay(payload, options, MESSAGE)).toMatchObject({ code: 'relay-disconnected', sent: false })
// pressed again with the service back: revoked and forgotten // pressed again with the service back: revoked and forgotten
expect(await disconnectRelay(payload, options)).toEqual({ revoked: true }) expect(await disconnectRelay(payload, options)).toEqual({ revoked: true })
expect(await readRelayStore(payload)).toEqual({ disconnected: true, v: 1 }) 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 () => { test('R-6: without the confirm route in the config the site does not ask to be enrolled', async () => {
+2 -2
View File
@@ -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') token = fake.setSite(HOST, given.site as 'active')
if (given.token === 'previous') { if (given.token === 'previous') {
// the token in {{token}} was replaced a moment ago // 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) expect(rotated.status).toBe(200)
} }
if (given.token === 'unknown') {token = `ims_${'u'.repeat(43)}`} 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<string, unknown> const body = expand(example.request.body, vars, example.id) as Record<string, unknown>
const first = await fake.handle(new Request(`${fake.url}/v1/send`, { const first = await fake.handle(new Request(`${fake.url}/v1/send`, {
body: JSON.stringify(given.idempotency === 'sent-same' ? body : { ...body, subject: 'Another message' }), 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', method: 'POST',
})) }))
expect(first.status).toBe(200) expect(first.status).toBe(200)
+1 -1
View File
@@ -228,7 +228,7 @@ describe('the state routes are for admins', () => {
expect(refused.status).toBe(400) expect(refused.status).toBe(400)
expect(await refused.text()).not.toContain('ims_') expect(await refused.text()).not.toContain('ims_')
expect((await readRelayStore(payload)).token).toBeUndefined() 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 // 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) }) 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' } }) expect(await own.json()).toMatchObject({ ok: true, relay: { connected: true, tokenSource: 'manual' } })
+2 -2
View File
@@ -174,14 +174,14 @@ describe.skipIf(!SERVICE || !local)('against the real service code, run locally'
const fresh = (await readRelayStore(payload)).token! const fresh = (await readRelayStore(payload)).token!
expect(fresh).not.toBe(old) expect(fresh).not.toBe(old)
expect((await sendThroughRelay(payload, options, { ...MESSAGE, subject: 'After rotation' })).sent).toBe(true) 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 }) expect(again).toMatchObject({ code: 'already-rotated', ok: false, retryable: false })
}) })
test('"Disconnect" revokes: the token stops working at once; "Connect again" enrols anew', async () => { test('"Disconnect" revokes: the token stops working at once; "Connect again" enrols anew', async () => {
const token = (await readRelayStore(payload)).token! const token = (await readRelayStore(payload)).token!
await disconnectRelay(payload, options) 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 sendThroughRelay(payload, options, MESSAGE)).toMatchObject({ code: 'relay-disconnected', sent: false })
expect(await enrolRelay(payload, options, { force: true })).toEqual({ ok: true, state: 'active' }) expect(await enrolRelay(payload, options, { force: true })).toEqual({ ok: true, state: 'active' })
expect((await sendThroughRelay(payload, options, { ...MESSAGE, subject: 'Back' })).sent).toBe(true) expect((await sendThroughRelay(payload, options, { ...MESSAGE, subject: 'Back' })).sent).toBe(true)