Panel actions only from the site's own origin (adminSameOrigin); doctor reads serverURL from the running config

The plugin's panel actions (mail service connect / disconnect, test e-mail,
cookie scan, approval, crawl) act with the panel's login cookie and read a
text/plain body, which another origin sends without a CORS preflight; a
sibling subdomain is same-site and Payload's csrf list is empty without
serverURL. On 1.17.1 such a page reached connect with an admin's cookie
(it called the mail service). Now each refuses a request a browser marks as
coming from elsewhere (403 before anything is read), the rule of the 2FA
endpoints; only endpoints the plugin added; logged once per origin, naming
adminSameOrigin. adminSameOrigin: false / { origins } (owner's Q6).
iapl-doctor csrf-empty: the deep status reports originKnown (serverURL or
csrf in the running config, never the value) and it wins over the file.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
This commit is contained in:
Radosław Smoliński
2026-12-01 10:46:05 +01:00
co-authored by Claude Opus 5.5
parent 97c62f21f0
commit 03f5cf1a8d
19 changed files with 308 additions and 10 deletions
+6
View File
@@ -50,6 +50,7 @@ import { withFillLocales } from './modules/hooks/fillEmptyLocales.js'
import { buildLocalizationConfig, validateI18nConfig } from './modules/i18n/index.js'
import { serverText } from './modules/integrations/texts.js'
import { buildSystemPagesFields } from './modules/pages/index.js'
import { guardAdminEndpoints } from './modules/security/adminSameOrigin.js'
import { missingImportMapEntries } from './modules/security/totp/importMapCheck.js'
import { changedViewKeys, copyViews, SAFE_TOTP_VIEW, wrapTotpViews } from './modules/security/totp/safeBack.js'
import { reportRefusedOrigin, requestFromOwnOrigin } from './modules/security/totp/sameOrigin.js'
@@ -130,6 +131,8 @@ export const iapl = (options: IaplOptions): Plugin => {
async function transform(incomingConfig: Config): Promise<Config> {
let config = { ...incomingConfig }
/** The project's own endpoints: the panel-action origin rule (adminSameOrigin) is for the plugin's only. */
const projectEndpoints = new Set<unknown>(incomingConfig.endpoints ?? [])
// Text written in one language fills the empty languages of the same field (cookie list, cookie review).
const fillDefaults = { 'cookie-review': ['purpose', 'retention'], 'cookie-settings': ['cookies.purpose', 'cookies.duration'] }
@@ -1101,6 +1104,9 @@ export const iapl = (options: IaplOptions): Plugin => {
const panel = config.admin?.user ?? (config.collections ?? []).find((c) => c.auth)?.slug
config = markSeenAuthCollections(config, staffCollectionSlugs({ admin: { user: panel }, custom: config.custom }))
}
// The plugin's panel actions (mail service connect / disconnect, test e-mail, cookie scan / approval / crawl)
// only from the site's own origin (adminSameOrigin).
config = guardAdminEndpoints(config, projectEndpoints, options.adminSameOrigin)
return config
}
}