Security: mandatory Turnstile when configured, admin-only test email, roles on create, safer client IP
- Turnstile is on only when both keys are set (panel or env); then submitForm requires a valid token, so a bot can no longer skip the check by omitting it. Not configured -> no widget, no check. New getTurnstileConfig() for layouts. - /api/ipal/test-email now requires the admin role (403 for other users). - roles field: create access is admin-only, so open sign-up can't self-assign admin. - clientIp reads X-Forwarded-For from the right, accepts Headers, can be pinned via option or IPAL_IP_HEADER; exposed on search/MCP routes. - Pluggable shared rate-limit store (setRateLimitStore) for multi-instance setups. - Replace the template int.spec with real unit tests in test/ (44 tests). Co-Authored-By: Claude Opus 5.5 <[email protected]>
This commit is contained in:
@@ -2,6 +2,8 @@ import type { Endpoint, PayloadRequest } from 'payload'
|
||||
|
||||
import { addDataAndFileToRequest } from 'payload'
|
||||
|
||||
import { isAdmin } from '../../access/predicates.js'
|
||||
|
||||
/**
|
||||
* Custom endpoint: send a test email to a given address through whatever
|
||||
* transport is currently active (SMTP or Graph — mailAdapter reads the panel
|
||||
@@ -17,10 +19,14 @@ import { addDataAndFileToRequest } from 'payload'
|
||||
*/
|
||||
export const testEmailEndpoint: Endpoint = {
|
||||
handler: async (req: PayloadRequest) => {
|
||||
// Auth: only signed-in admins may trigger a send.
|
||||
// Auth: only admins may trigger a send — the same gate as the
|
||||
// SiteIntegrations global that holds the transport settings.
|
||||
if (!req.user) {
|
||||
return Response.json({ error: 'Unauthorized', ok: false }, { status: 401 })
|
||||
}
|
||||
if (!isAdmin(req.user)) {
|
||||
return Response.json({ error: 'Forbidden', ok: false }, { status: 403 })
|
||||
}
|
||||
|
||||
await addDataAndFileToRequest(req)
|
||||
const to = (req.data?.to as string | undefined)?.trim()
|
||||
|
||||
Reference in New Issue
Block a user