Add a function that checks a Cloudflare Turnstile token on the server
I maintainer di solito rispondono entro 1 giorno
Valutazione
- Difficoltà
- 2/5
- Tempo stimato
- 1-3 ore
- Idoneità per principianti
- 88/100
- Tipo di issue
- Funzionalità
- Chiarezza
- Specificata chiaramente
- Stato di attività
- Attiva
- Stack tecnologico
- typescript
Direzione di ricerca
Leggi packages/server/src/webhook.ts per vedere il modello esistente di timeout di fetch e packages/server/tests/webhook-delivery.test.ts per vedere come simulare fetch. Implementa packages/server/src/security/turnstile.ts e aggiungi i test specificati in packages/server/tests/security/turnstile.test.ts. Il lavoro è completato quando i criteri di accettazione sono soddisfatti, inclusi i campi della richiesta, i casi di mancata corrispondenza e gli errori che non devono generare eccezioni né esporre il secret.
Scritto dal modello di indicizzazione a partire dal testo della issue.
Descrizione
ChatCops is getting optional Cloudflare Turnstile checks: the widget gets a token from Turnstile when a visitor first opens the chat, and the server checks it before it starts a session. This issue is the server half of that check, as one small function in a new file. Wiring it into a route comes later, so this PR doesn't touch anything else.
What to do
Create packages/server/src/security/turnstile.ts with:
export interface TurnstileConfig {
secretKey: string;
/** The action set in the widget, if any. A token for another action is rejected. */
action?: string;
/** Hostnames the token may come from. Unset means any. */
expectedHostnames?: string[];
/** Default 5000. */
timeoutMs?: number;
}
export type TurnstileResult =
| { ok: true; hostname?: string; action?: string }
| { ok: false; code: 'missing_token' | 'invalid_token' | 'hostname_mismatch' | 'action_mismatch' | 'unavailable'; errorCodes?: string[] };
export async function verifyTurnstile(
token: string | undefined,
config: TurnstileConfig,
opts?: { remoteIp?: string; idempotencyKey?: string; fetch?: typeof fetch }
): Promise<TurnstileResult>;
- POST to
https://challenges.cloudflare.com/turnstile/v0/siteverifyas described in Cloudflare's server-side validation docs, withsecret,response,remoteip(when given) andidempotency_key(when given). - A token can only be redeemed once. The
idempotency_keylets the server retry the same check after a network error without it failing as already used, so pass it through. - Return
missing_tokenwithout calling the API when the token is empty, andunavailablewhen the request fails, times out (AbortSignal.timeout) or doesn't return JSON. Never throw. - Check
hostnameandactionfrom the response against the config. - Use
opts.fetch ?? globalThis.fetch, so tests can pass a fake. Don't import anything from Node; this has to run on Workers too.
Where to look
packages/server/src/webhook.tshas a similar fetch with a timeoutpackages/server/tests/webhook-delivery.test.tsshows how the tests fakefetch
Acceptance criteria
- New
packages/server/src/security/turnstile.tsandpackages/server/tests/security/turnstile.test.ts - Tests cover success,
success: falsewith error codes, hostname and action mismatch, an empty token (no request sent), a network error, a timeout and a non-JSON reply - A test checks the request body, including
idempotency_keyandremoteip - The secret never appears in a returned value or in a log line
- Not exported from
@chatcops/serveryet, and no changeset needed (pnpm changeset --empty) -
pnpm test:coverageandpnpm lintpass
Want to work on this? Comment below and I'll assign it to you. Please take one issue at a time, branch off dev, and open your PR against dev with Closes #<this issue number>. Setup notes (pnpm, build before test) are in CONTRIBUTING.md.
- Lingua principale
- TypeScript
- Stelle
- 13
- Fork
- 7
- Merge medio
- 3h 41m
- PR unite (30g)
- 155
Preparare l'ambiente
- Nessun Dockerfile né file Docker Compose
- Ha un modello di pull request
- Leggi la guida per i contributori
Come iniziare
- Leggi tutta la issue e poi la guida ai contributi del progetto.
- Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
- Fai un fork del repository e lavora su un branch.
- Apri una pull request che faccia riferimento al numero della issue.
Altre issue di codercops/chatcops
-
Document the pre-chat formForse già presa @masyarakatai l’ha presa 5 giorni fa. Apertadocumentation good first issue hacktoberfest widget
Difficoltà 2/5 1-3 ore Idoneità per principianti 88/100
codercops/chatcops#70 · 5 commenti ·
I maintainer di solito rispondono entro 1 giorno
-
docs: update the providers page for openai-compatible, registerProvider and provider importsForse già presa @prakashNalla l’ha presa oggi. Apertadocumentation good first issue hacktoberfest website
Difficoltà 3/5 1-2 giorni Idoneità per principianti 76/100
codercops/chatcops#291 · 1 commento ·
I maintainer di solito rispondono entro 1 giorno
-
docs: add a protocol reference page for custom clientsForse già presa @kachamsiddarth l’ha presa oggi. Apertadocumentation good first issue hacktoberfest website
codercops/chatcops#286 · 2 commenti · 1 assegnatario ·
I maintainer di solito rispondono entro 1 giorno
-
Create @chatcops/store-cloudflare (D1, KV and a Durable Object counter)Forse già presa @bhushan4work l’ha presa oggi. Apertaenhancement hacktoberfest help wanted server
Difficoltà 5/5 Più di una settimana Idoneità per principianti 25/100
codercops/chatcops#249 · 2 commenti · 1 assegnatario ·
I maintainer di solito rispondono entro 1 giorno
-
Create @chatcops/store-sqlite, a store for single-server setupsForse già presa @srikar-naidu l’ha presa oggi. Apertaenhancement hacktoberfest help wanted server
Difficoltà 5/5 Più di una settimana Idoneità per principianti 35/100
codercops/chatcops#247 · 3 commenti · 1 assegnatario ·
I maintainer di solito rispondono entro 1 giorno
Tutte le issue di codercops/chatcops
Issue simili
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 74/100
paperclipai/paperclip#17151 ·
I maintainer di solito rispondono entro 1 giorno
-
needs-triage
Difficoltà 2/5 1-3 ore Idoneità per principianti 83/100
AgoraIO-Extensions/agent-infra#3159 ·
I maintainer di solito rispondono entro 1 giorno
-
blocklist addition
Difficoltà 1/5 Meno di un'ora Idoneità per principianti 66/100
MetaMask/eth-phishing-detect#304596 ·
I maintainer di solito rispondono entro 1 giorno
-
friction
Difficoltà 2/5 1-3 ore Idoneità per principianti 70/100
kentcdodds/kody#4142 ·
-
[Bug] Statistics | Task statistics are always empty on MikroORM with MySQL or SQLiteForse già presa @NdekoCode l’ha presa oggi. Aperta
Difficoltà 2/5 1-3 ore Idoneità per principianti 76/100
ever-co/ever-gauzy#11214 ·
I maintainer di solito rispondono entro 1 giorno