Add a function that checks a Cloudflare Turnstile token on the server
メンテナーはふだん 1 日以内に返信
評価
- 難易度
- 2/5
- 見積もり時間
- 1〜3時間
- 初心者へのやさしさ
- 88/100
- issue の種類
- 機能追加
- 明瞭さ
- 明確に書かれている
- 活発さ
- 活発
- 技術スタック
- typescript
調査の方向性
既存の fetch タイムアウトのパターンを確認するために packages/server/src/webhook.ts を読み、fetch のモック方法を確認するために packages/server/tests/webhook-delivery.test.ts を読んでください。packages/server/src/security/turnstile.ts を実装し、指定されたテストを packages/server/tests/security/turnstile.test.ts に追加してください。リクエストフィールド、不一致のケース、例外を投げず secret を公開しない失敗を含め、受け入れ基準を満たしたら完了です。
索引モデルが issue の本文から書いたものです。
説明
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.
- 主要言語
- TypeScript
- スター
- 13
- フォーク
- 7
- 平均マージ
- 3時間 41分
- マージ済み PR(30日)
- 155
環境構築
- Dockerfile・Docker Compose ファイルなし
- プルリクエストのテンプレートあり
- コントリビューションガイドを読む
はじめの一歩
- issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
- 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
- リポジトリをフォークし、ブランチを切って変更します。
- issue 番号を参照したプルリクエストを送ります。
codercops/chatcops のほかの issue
-
Document the pre-chat form対応中かも @masyarakatai が 5 日前に担当しました。 オープンdocumentation good first issue hacktoberfest widget
難易度 2/5 1〜3時間 初心者へのやさしさ 88/100
codercops/chatcops#70 · コメント 5 件 ·
メンテナーはふだん 1 日以内に返信
-
docs: update the providers page for openai-compatible, registerProvider and provider imports対応中かも @prakashNalla が今日担当しました。 オープンdocumentation good first issue hacktoberfest website
難易度 3/5 1〜2日 初心者へのやさしさ 76/100
codercops/chatcops#291 · コメント 1 件 ·
メンテナーはふだん 1 日以内に返信
-
docs: add a protocol reference page for custom clients対応中かも @kachamsiddarth が今日担当しました。 オープンdocumentation good first issue hacktoberfest website
codercops/chatcops#286 · コメント 2 件 · 担当者 1 名 ·
メンテナーはふだん 1 日以内に返信
-
Create @chatcops/store-cloudflare (D1, KV and a Durable Object counter)対応中かも @bhushan4work が今日担当しました。 オープンenhancement hacktoberfest help wanted server
難易度 5/5 1週間以上 初心者へのやさしさ 25/100
codercops/chatcops#249 · コメント 2 件 · 担当者 1 名 ·
メンテナーはふだん 1 日以内に返信
-
Create @chatcops/store-sqlite, a store for single-server setups対応中かも @srikar-naidu が今日担当しました。 オープンenhancement hacktoberfest help wanted server
難易度 5/5 1週間以上 初心者へのやさしさ 35/100
codercops/chatcops#247 · コメント 3 件 · 担当者 1 名 ·
メンテナーはふだん 1 日以内に返信
codercops/chatcops の issue をすべて見る
似ている issue
-
agent/scanner help wanted hive/claimed-by-scanner kind/bug stage/020-claimed
難易度 2/5 1〜3時間 初心者へのやさしさ 90/100
hivecommons/rationguard#315 ·
メンテナーはふだん 1 日以内に返信
-
agent-ready area: ui-sdk priority: p3 type: chore
難易度 2/5 1〜3時間 初心者へのやさしさ 76/100
schlessera/brain-kit#2534 ·
メンテナーはふだん 1 日以内に返信
-
bug lane:gh-5
難易度 2/5 1〜3時間 初心者へのやさしさ 72/100
LLM-4-People/bridlewise-testing#122 ·
メンテナーはふだん 1 日以内に返信
-
bug priority: P2
難易度 1/5 1時間未満 初心者へのやさしさ 78/100
メンテナーはふだん 1 日以内に返信
-
enhancement priority:low ready-for-dev
難易度 2/5 1〜3時間 初心者へのやさしさ 67/100
メンテナーはふだん 1 日以内に返信