From be308124231dd593bd9dde8ae76b009b0464d469 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rados=C5=82aw=20Smoli=C5=84ski?= Date: Tue, 1 Dec 2026 23:00:52 +0100 Subject: [PATCH] =?UTF-8?q?connect-link=20("Po=C5=82=C4=85cz=20z=20IWSN")?= =?UTF-8?q?=20is=20a=20panel=20action:=20only=20from=20the=20site's=20own?= =?UTF-8?q?=20origin=20(adminSameOrigin),=20like=20connect=20and=20disconn?= =?UTF-8?q?ect?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-Authored-By: Claude Opus 5.5 --- docs/email.md | 2 +- docs/security.md | 3 ++- src/modules/security/adminSameOrigin.ts | 3 ++- test/adminSameOriginSuite.ts | 2 +- 4 files changed, 6 insertions(+), 4 deletions(-) diff --git a/docs/email.md b/docs/email.md index fa4f092..49d6ed7 100644 --- a/docs/email.md +++ b/docs/email.md @@ -422,7 +422,7 @@ Routes (all four need the `admin` role: not logged in → 401, other role → 40 | `GET /api/iapl/mail-relay/status` | the transport and the stored state; `?refresh=1` asks the service | | `POST /api/iapl/mail-relay/connect` | enrol now; with `{ token }` store a token issued by hand — only with `accessKeyField: true`, otherwise `403` | | `POST /api/iapl/mail-relay/disconnect` | give the token up | -| `POST /api/iapl/mail-relay/connect-link` | "Połącz z IWSN": asks the service for the confirmation link (`POST /v1/connect`, enrolling first when there is no token) and answers it as `connectUrl` + `expiresAt`, `Cache-Control: no-store`; nothing is stored. Absent with `connectButton: false` (`RELAY_CONNECT_LINK_PATH`) | +| `POST /api/iapl/mail-relay/connect-link` | "Połącz z IWSN": asks the service for the confirmation link (`POST /v1/connect`, enrolling first when there is no token) and answers it as `connectUrl` + `expiresAt`, `Cache-Control: no-store`; nothing is stored. Admin only, from the site's own origin (`adminSameOrigin`). Absent with `connectButton: false` (`RELAY_CONNECT_LINK_PATH`) | | `POST /api/iapl/mail-relay/confirm` | **public** — the service's call-back. `404` and no change unless the site itself started an enrolment in the last 5 minutes; **refused** calls are rate-limited (10 a minute per address, `mail.relay.confirmRateLimit`) — a call that carries the nonce is never turned away by the limit, so junk from the same address cannot keep the site from enrolling | These are the first routes under `/api/iapl/`; the others stay under `/api/ipal/` until 2.0. The confirm path is diff --git a/docs/security.md b/docs/security.md index 6ef204e..6371d66 100644 --- a/docs/security.md +++ b/docs/security.md @@ -435,7 +435,8 @@ addition to real safeguards, not a replacement for them. ## Panel actions only from the site's own origin (`adminSameOrigin`, 1.17.2) The plugin's panel actions act with the panel's login cookie and read their body whatever its `Content-Type` -says: `POST /api/iapl/mail-relay/connect` and `/disconnect` (the mail service), `/api/ipal/test-email`, +says: `POST /api/iapl/mail-relay/connect`, `/connect-link` ("Połącz z IWSN", 1.18.0) and `/disconnect` (the mail +service), `/api/ipal/test-email`, `/api/ipal/cookie-scan`, `/api/ipal/cookie-approval`, `/api/ipal/cookie-crawl`. A `text/plain` POST needs no CORS preflight, a page on a sibling subdomain is "same site" (the browser sends the `SameSite=Lax` cookie), and Payload's own CSRF list is empty unless `serverURL` or `csrf` is set. So before 1.17.2 such a page could make a diff --git a/src/modules/security/adminSameOrigin.ts b/src/modules/security/adminSameOrigin.ts index 17b79c3..b166893 100644 --- a/src/modules/security/adminSameOrigin.ts +++ b/src/modules/security/adminSameOrigin.ts @@ -3,7 +3,7 @@ import type { Config, Endpoint, PayloadRequest } from 'payload' import { COOKIE_APPROVAL_PATH } from '../consent/scanner/approval.js' import { COOKIE_CRAWL_PATH } from '../consent/scanner/crawl/config.js' import { COOKIE_SCAN_PATH } from '../consent/scanner/endpoint.js' -import { RELAY_CONNECT_PATH, RELAY_DISCONNECT_PATH } from '../email/relay/constants.js' +import { RELAY_CONNECT_LINK_PATH, RELAY_CONNECT_PATH, RELAY_DISCONNECT_PATH } from '../email/relay/constants.js' import { reportRefusedOrigin, requestFromOwnOrigin } from './totp/sameOrigin.js' /** @@ -26,6 +26,7 @@ export type AdminSameOriginOption = { /** The panel actions the rule covers: method and path (relative to the API route). */ export const ADMIN_POST_ENDPOINTS: ReadonlyArray = [ ['post', RELAY_CONNECT_PATH], + ['post', RELAY_CONNECT_LINK_PATH], ['post', RELAY_DISCONNECT_PATH], ['post', '/ipal/test-email'], ['post', COOKIE_SCAN_PATH], diff --git a/test/adminSameOriginSuite.ts b/test/adminSameOriginSuite.ts index a02a300..7cd0262 100644 --- a/test/adminSameOriginSuite.ts +++ b/test/adminSameOriginSuite.ts @@ -21,7 +21,7 @@ const SECRET = 'JBSWY3DPEHPK3PXP' const PASSWORD = 'a-long-test-password-1' export const SIBLING = { origin: 'https://blog.site.example', 'sec-fetch-site': 'same-site' } /** Every panel action the rule covers (path under /api). */ -export const ACTIONS = ['/iapl/mail-relay/connect', '/iapl/mail-relay/disconnect', '/ipal/test-email', '/ipal/cookie-scan', '/ipal/cookie-approval', '/ipal/cookie-crawl'] +export const ACTIONS = ['/iapl/mail-relay/connect', '/iapl/mail-relay/connect-link', '/iapl/mail-relay/disconnect', '/ipal/test-email', '/ipal/cookie-scan', '/ipal/cookie-approval', '/ipal/cookie-crawl'] export function adminSite(adminSameOrigin?: false) { const state = {} as { cookie: string; payload: Payload; server: TestServer; warn: string[] }