Add a function that checks a Cloudflare Turnstile token on the server
Maintainer thường phản hồi trong vòng 1 ngày
Đánh giá
- Độ khó
- 2/5
- Thời gian dự kiến
- 1-3 giờ
- Mức phù hợp với người mới
- 88/100
- Loại issue
- Tính năng
- Độ rõ ràng
- Đặc tả rõ ràng
- Mức độ hoạt động
- Sôi nổi
- Công nghệ
- typescript
Hướng nghiên cứu
Đọc packages/server/src/webhook.ts để xem mẫu timeout fetch hiện có và packages/server/tests/webhook-delivery.test.ts để xem cách giả lập fetch. Triển khai packages/server/src/security/turnstile.ts và thêm các bài kiểm thử được chỉ định vào packages/server/tests/security/turnstile.test.ts. Công việc hoàn tất khi đáp ứng các tiêu chí chấp nhận, bao gồm các trường của yêu cầu, các trường hợp không khớp và các lỗi không được ném ngoại lệ hoặc làm lộ secret.
Do mô hình lập chỉ mục viết ra từ nội dung của issue.
Mô tả
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.
- Ngôn ngữ chính
- TypeScript
- Star
- 13
- Fork
- 7
- Merge trung bình
- 3 giờ 33 phút
- Pull request đã merge (30 ngày)
- 176
Chuẩn bị môi trường
- Không có Dockerfile hay tệp Docker Compose
- Có mẫu pull request
- Đọc hướng dẫn đóng góp
Bắt đầu từ đâu
- Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
- Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
- Fork repository và làm thay đổi trên một nhánh.
- Mở pull request có tham chiếu số hiệu của issue.
Issue khác của codercops/chatcops
-
Add startup checks that catch weak or leaked security settingsCó thể đã có người làm @varun-pahuja đã nhận 3 ngày trước. Đang mởenhancement good first issue hacktoberfest server
codercops/chatcops#231 · 3 bình luận · 1 người được giao ·
Maintainer thường phản hồi trong vòng 1 ngày
-
Type-check the TypeScript samples in the docsCó thể đã có người làm @An16og đã nhận 2 ngày trước. Đang mởdocumentation hacktoberfest help wanted testing
Độ khó 4/5 3-5 ngày Mức phù hợp với người mới 70/100
codercops/chatcops#201 · 7 bình luận · 1 người được giao ·
Maintainer thường phản hồi trong vòng 1 ngày
-
Hacktoberfest 2026: start hereĐang mởhacktoberfest
Độ khó 1/5 Dưới một giờ Mức phù hợp với người mới 35/100
Maintainer thường phản hồi trong vòng 1 ngày
-
Add built-in translations to the widgetCó thể đã có người làm @piyusshhjangid đã nhận 1 ngày trước. Đang mởhelp wanted widget
Độ khó 4/5 3-5 ngày Mức phù hợp với người mới 52/100
codercops/chatcops#55 · 3 bình luận ·
Maintainer thường phản hồi trong vòng 1 ngày
Tất cả issue của codercops/chatcops
Issue tương tự
-
Độ khó 1/5 1-3 giờ Mức phù hợp với người mới 82/100
source-cooperative/docs.source.coop#41 · 1 bình luận ·
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 76/100
Nimblesite/SharpLsp#468 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 85/100
solidjs-community/solid-primitives#1082 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
enhancement
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 64/100
Maintainer thường phản hồi trong vòng 1 ngày
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 72/100
Maintainer thường phản hồi trong vòng 1 ngày