Hacktoberfest 2026: die Issues, die Maintainer für den Oktober markiert haben – offen und einsteigerfreundlich. Hacktoberfest-Issues durchsuchen

Add a function that checks a Cloudflare Turnstile token on the server

Geschlossen Anfängerfreundlich
#228 0 Kommentare 0 Reaktionen 0 zugewiesene Personen Auf GitHub ansehen

Maintainer antworten meist innerhalb von 1 Tag

@bhushan4work arbeitet bereits daran.

Seit 21.10.2026.

  • #282 von @bhushan4work — gemerged

Bewertung

Schwierigkeit
2/5
Geschätzter Aufwand
1-3 Stunden
Anfängerfreundlichkeit
88/100
Issue-Typ
Feature
Klarheit
Klar beschrieben
Aktivitätsstatus
Aktiv
Tech-Stack
typescript
Bereich
backend, security

Rechercherichtung

Lies packages/server/src/webhook.ts, um das bestehende Muster für Fetch-Timeouts zu verstehen, und packages/server/tests/webhook-delivery.test.ts zum Mocken von Fetch. Implementiere packages/server/src/security/turnstile.ts und füge die angegebenen Tests in packages/server/tests/security/turnstile.test.ts hinzu. Die Arbeit ist abgeschlossen, wenn die Akzeptanzkriterien erfüllt sind, einschließlich der Anfragefelder, der Fälle mit Abweichungen und der Fehler, die weder eine Exception auslösen noch das Secret offenlegen.

Vom Indexierungsmodell aus dem Issue-Text verfasst.

Beschreibung

enhancement hacktoberfest help wanted server

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/siteverify as described in Cloudflare's server-side validation docs, with secret, response, remoteip (when given) and idempotency_key (when given).
  • A token can only be redeemed once. The idempotency_key lets the server retry the same check after a network error without it failing as already used, so pass it through.
  • Return missing_token without calling the API when the token is empty, and unavailable when the request fails, times out (AbortSignal.timeout) or doesn't return JSON. Never throw.
  • Check hostname and action from 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.ts has a similar fetch with a timeout
  • packages/server/tests/webhook-delivery.test.ts shows how the tests fake fetch

Acceptance criteria

  • New packages/server/src/security/turnstile.ts and packages/server/tests/security/turnstile.test.ts
  • Tests cover success, success: false with 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_key and remoteip
  • The secret never appears in a returned value or in a log line
  • Not exported from @chatcops/server yet, and no changeset needed (pnpm changeset --empty)
  • pnpm test:coverage and pnpm lint pass

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.

Vorherrschende Sprache
TypeScript
Sterne
13
Forks
7
Ø Merge
3 Std. 41 Min.
Gemergte PRs (30 T.)
155

Entwicklungsumgebung

Erste Schritte

  1. Lesen Sie das ganze Issue und danach den Beitragsleitfaden des Projekts.
  2. Schreiben Sie ins Issue, dass Sie es übernehmen — das erspart doppelte Arbeit.
  3. Forken Sie das Repository und arbeiten Sie in einem Branch.
  4. Öffnen Sie einen Pull Request, der die Issue-Nummer nennt.

Mehr aus codercops/chatcops

Alle Issues in codercops/chatcops

Ähnliche Issues

Weitere Issues zu TypeScript

Neue Issues direkt in Ihr Postfach

Eine kurze Übersicht über anfängerfreundliche GitHub-Issues.