Hacktoberfest 2026:维护者为十月标记出来的 issue,仍然开放、适合新手。 浏览 Hacktoberfest issue

Require a bearer token for the Express analytics endpoint

已关闭
#232 2 条评论 0 个 reaction 已指派 1 人 在 GitHub 查看

维护者通常 1 天内回复

@anurag2787 已经在做这个了。

开始于 2026年10月20日。

  • #272 来自 @anurag2787 —— 已合并

评估

这个 Issue 还没有评估数据。

描述

enhancement good first issue hacktoberfest server

chatcopsAnalyticsHandler (packages/server/src/adapters/express.ts, lines 73 to 78) answers anyone who finds the URL. The stats aren't secret, but they show how much traffic and how many leads a site gets, which is nobody else's business.

What to do

  • Add analyticsToken?: string to ChatCopsServerConfig (packages/server/src/config.ts), with a short doc comment.
  • When it's set, chatcopsAnalyticsHandler only answers requests with Authorization: Bearer <token>. Anything else gets 401 with { "error": "unauthorized" } and a WWW-Authenticate: Bearer header.
  • Compare the tokens in constant time. Don't import node:crypto: this file is part of the same bundle Workers load. A small loop that compares every character, and checks the length, is enough.
  • When it isn't set, keep today's behavior so nothing breaks, but log one warning the first time the endpoint is hit, saying anyone can read the stats and how to set analyticsToken.
  • Update the "Reading Stats with Express" section of website/src/content/docs/core/analytics.mdx (line 18) with the option and a curl example.

Where to look

  • packages/server/src/adapters/express.ts, chatcopsAnalyticsHandler
  • packages/server/tests/adapters/express.test.ts, line 322, has the existing analytics test

Acceptance criteria

  • With analyticsToken set: the right token gets the stats, while a missing token, a wrong token and a token of a different length get 401
  • Without it: the stats are returned as today, and the warning is logged once across several requests
  • Docs updated
  • Changeset for @chatcops/server (minor, since it adds an option)
  • pnpm test:coverage and pnpm lint pass

Please get this merged by Oct 31.


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 分钟
30 天内合并 PR
155

环境准备

从这里开始

  1. 先读完整个 Issue,再读项目的贡献指南。
  2. 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
  3. Fork 仓库,在一个分支上完成修改。
  4. 提交 Pull Request,并在描述里引用这个 Issue 编号。

codercops/chatcops 的其他 Issue

查看 codercops/chatcops 的全部 Issue

相似的 Issue

更多 TypeScript Issue

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。