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:
co-authored by
Claude Opus 5.5
parent
97c62f21f0
commit
03f5cf1a8d
@@ -0,0 +1,38 @@
|
||||
/** The plugin's panel actions refuse other origins (adminSameOriginSuite.ts). */
|
||||
import { describe, expect, test, vi } from 'vitest'
|
||||
|
||||
import { guardAdminEndpoints } from '../src/modules/security/adminSameOrigin.js'
|
||||
import { clearReportedOrigins } from '../src/modules/security/totp/sameOrigin.js'
|
||||
import { ACTIONS, adminSite, SIBLING } from './adminSameOriginSuite.js'
|
||||
|
||||
vi.mock('server-only', () => ({}))
|
||||
vi.mock('next/headers.js', async () => (await import('./http/server.js')).nextHeadersMock)
|
||||
|
||||
const { action, state } = adminSite()
|
||||
|
||||
describe('adminSameOrigin (default): panel actions only from the site\'s own origin', () => {
|
||||
test('a page on a sibling subdomain, or a cross-site page, gets 403 on every panel action, with the admin cookie', async () => {
|
||||
clearReportedOrigins()
|
||||
for (const path of ACTIONS) {
|
||||
expect([path, (await action(path, SIBLING)).status]).toEqual([path, 403])
|
||||
expect([path, (await action(path, { 'sec-fetch-site': 'cross-site' })).status]).toEqual([path, 403])
|
||||
}
|
||||
// said in the log once per origin, naming this option
|
||||
const lines = state.warn.filter((l) => l.includes('blog.site.example'))
|
||||
expect(lines).toHaveLength(1)
|
||||
expect(lines[0]).toMatch(/adminSameOrigin/)
|
||||
})
|
||||
|
||||
test('the site\'s own page and a script without browser headers still reach them', async () => {
|
||||
const own = await action('/ipal/cookie-approval', { origin: state.server.url, 'sec-fetch-site': 'same-origin' }, '{"ids":[]}')
|
||||
expect(own.status).toBe(200)
|
||||
const script = await action('/ipal/cookie-approval', {}, '{"ids":[]}')
|
||||
expect(script.status).toBe(200)
|
||||
})
|
||||
|
||||
test('a project\'s own endpoint on one of these paths is left as it is', () => {
|
||||
const own = { handler: () => Response.json({ ok: true }), method: 'post' as const, path: '/ipal/test-email' }
|
||||
const config = guardAdminEndpoints({ endpoints: [own] } as never, new Set([own]), undefined)
|
||||
expect(config.endpoints?.[0]).toBe(own)
|
||||
})
|
||||
})
|
||||
Reference in New Issue
Block a user