M1 (2, 3): the Turnstile env secret is deprecated; doctor rules access-missing, turnstile-degraded, turnstile-env-key

(2) Stage one of the deprecation: TURNSTILE_SECRET_KEY from the environment still
works when the panel field is empty, logs once that it is deprecated, and the
doctor's deep status reports it (rule turnstile-env-key, warning). Nothing is
removed.
(3) access-missing (static, warning): ipalKit without `access` means every panel
account is an admin. turnstile-degraded (deep): Turnstile is not checking forms —
warning, error after a day. The deep status carries the recorded state and where
the secret comes from, never a key.

Co-Authored-By: Claude Fable 5.2 <[email protected]>
This commit is contained in:
Radosław Smoliński
2026-11-25 00:39:12 +01:00
co-authored by Claude Fable 5.2
parent 8fa71238ce
commit 42fdad8c2d
8 changed files with 214 additions and 16 deletions
+25 -1
View File
@@ -19,6 +19,27 @@ export type TurnstileConfig = {
}
let warnedPartial = false
let warnedEnvSecret = false
/**
* True when the secret key in use comes from the environment (`TURNSTILE_SECRET_KEY`) because
* the panel field is empty. **Deprecated:** the panel is the source of the secret; the
* environment value keeps working for now and will be removed in a later, announced release.
*/
export function turnstileSecretFromEnv(integrations: IntegrationsWithTurnstileKeys): boolean {
return !integrations.turnstileSecretKey?.trim() && Boolean(process.env[TURNSTILE_SECRET_ENV]?.trim())
}
/** Says once per process that the secret came from the environment (see turnstileSecretFromEnv). */
export function warnTurnstileEnvSecret(integrations: IntegrationsWithTurnstileKeys): void {
if (warnedEnvSecret || !turnstileSecretFromEnv(integrations)) {return}
warnedEnvSecret = true
console.warn(
`[ipal] Deprecated: the Turnstile secret key comes from the ${TURNSTILE_SECRET_ENV} environment variable. ` +
'Put it into Site integrations → Spam protection → Secret key (the panel is the source of this secret). ' +
'The environment value keeps working for now and will be removed in a later release, named in the changelog.',
)
}
function resolveKeys(integrations: IntegrationsWithTurnstileKeys) {
return {
@@ -69,7 +90,10 @@ export async function getTurnstileConfig(payload: BasePayload): Promise<Turnstil
const integrations = await getSiteIntegrations<IntegrationsWithTurnstileKeys>(payload)
const { secret, siteKey } = resolveKeys(integrations)
if (siteKey && secret) {return { enabled: true, siteKey }}
if (siteKey && secret) {
warnTurnstileEnvSecret(integrations)
return { enabled: true, siteKey }
}
if ((siteKey || secret) && !warnedPartial) {
warnedPartial = true
+1 -1
View File
@@ -83,7 +83,7 @@ const LOG_DETAIL: Record<string, string> = {
/**
* Verifies a Turnstile token with Cloudflare and classifies the result (server-only).
*
* Secret: SiteIntegrations → Turnstile (panel) first, then TURNSTILE_SECRET_KEY.
* Secret: SiteIntegrations → Turnstile (panel) first, then TURNSTILE_SECRET_KEY (deprecated: turnstile/config.ts).
* Every result is logged when not `pass`, and the integration status on
* SiteIntegrations is updated (throttled) so the panel shows failures.
*/