Skip to content

Commit 06c92f4

Browse files
CreatmanCEOclaude
andauthored
security: replace hardcoded BOT_TOKEN/CHAT_ID/ORIGIN with Wrangler secrets (#2)
⚠️ The previous src/index.js shipped a real Telegram bot token, chat id, and production origin in the source. The token was publicly leaked in this repo from 2026-02-10 (GitHub secret-scanning alert #1, never resolved). Changes: - src/index.js — read BOT_TOKEN, CHAT_ID, ALLOWED_ORIGIN from env (Wrangler bindings), return 500 with a clear setup message if any is missing. No hardcoded values remain. - .env.example — document the required secrets and how to set them via `wrangler secret put`. The file contains placeholder values only. Note: this commit does NOT remove the leaked token from git history. The token must be revoked via @Botfather as a separate operational step (rotation, then `wrangler secret put BOT_TOKEN <new-token>`). After revoke, the GitHub secret-scanning alert can be closed as "revoked": https://github.com/CreatmanCEO/telegram-form-worker/security/secret-scanning/1 Co-authored-by: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
1 parent 174512e commit 06c92f4

2 files changed

Lines changed: 33 additions & 5 deletions

File tree

.env.example

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
# telegram-form-worker — required secrets
2+
#
3+
# These are NOT loaded from this file at runtime. This file documents the
4+
# variable names and shapes; the actual values must be set as Cloudflare
5+
# Wrangler secrets (encrypted, never committed):
6+
#
7+
# wrangler secret put BOT_TOKEN
8+
# wrangler secret put CHAT_ID
9+
# wrangler secret put ALLOWED_ORIGIN
10+
#
11+
# The Worker reads them at runtime as `env.BOT_TOKEN`, `env.CHAT_ID`,
12+
# `env.ALLOWED_ORIGIN`. If any is missing the Worker responds 500.
13+
14+
# Telegram bot token from @BotFather. Format: <numeric-id>:<base64-ish-payload>.
15+
# IMPORTANT: never paste a real token here — keep this file as documentation only.
16+
BOT_TOKEN=000000000:AAEXAMPLE_REPLACE_WITH_BOT_FATHER_TOKEN
17+
18+
# Telegram numeric chat id (positive for users, negative for groups/channels).
19+
CHAT_ID=000000000
20+
21+
# Allowed CORS origin (the site that hosts the contact form).
22+
ALLOWED_ORIGIN=https://your-site.example

src/index.js

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,14 @@
11
export default {
22
async fetch(request, env, ctx) {
3-
const BOT_TOKEN = '8157141771:AAHxRzh3_kCS1amiPTaXw3FTYnN-GrBdt-g';
4-
const CHAT_ID = '338930874';
5-
const ALLOWED_ORIGIN = 'https://itpovar.ru';
3+
// Secrets (set via `wrangler secret put BOT_TOKEN` etc.) — never commit values to source.
4+
// See .env.example for the full list of required secrets and how to set them.
5+
const BOT_TOKEN = env.BOT_TOKEN;
6+
const CHAT_ID = env.CHAT_ID;
7+
const ALLOWED_ORIGIN = env.ALLOWED_ORIGIN; // e.g. 'https://your-site.example'
8+
9+
if (!BOT_TOKEN || !CHAT_ID || !ALLOWED_ORIGIN) {
10+
return new Response('Worker is not configured. Set BOT_TOKEN, CHAT_ID, ALLOWED_ORIGIN as Wrangler secrets.', { status: 500 });
11+
}
612

713
if (request.method === 'OPTIONS') {
814
return new Response(null, {
@@ -21,7 +27,7 @@ export default {
2127

2228
try {
2329
const requestData = await request.json();
24-
30+
2531
const message = `
2632
🔥 Новая заявка с сайта!
2733
@@ -63,4 +69,4 @@ ${requestData.message}
6369
});
6470
}
6571
}
66-
};
72+
};

0 commit comments

Comments
 (0)