Repository navigation
fix(traffic): keep the AI-bot Worker's secret in a Worker Secret, not its code - #1252
Merged
Merged
Conversation
… its code The generated Cloudflare Worker held the connection secret in its source, so anyone who could read the Worker, its versions or a screenshot of it had the secret. The Worker now reads it from a Worker Secret named ANSVISOR_BOT_SECRET (env.ANSVISOR_BOT_SECRET) and reports nothing until it's added, without affecting the site. The connect dialog adds the step and shows the secret on its own, with the name from the server's response (workerSecretName). Workers set up before, with the secret in their code, keep working. Follow-up to ansvisor#1179's review; passThroughOnException and origin plus pathname were already in place. Co-Authored-By: Claude Opus 5.5 <[email protected]>
Collaborator
Author
|
@gkhngyk the last generated-Worker note from #1179: the secret now lives in a Worker Secret ( |
gkhngyk
approved these changes
Oct 20, 2026
gkhngyk
left a comment
Contributor
There was a problem hiding this comment.
Looks good. Taking the secret out of the Worker source, and skipping the report when no Secret is set, is the safe default. Existing Workers keep working because /bots/ingest still takes the Bearer secret.
cihan-gyk
added a commit
to cihan-gyk/ansvisor
that referenced
this pull request
Oct 20, 2026
ansvisor#1252 and this branch each added a test to _bots-connect.test.tsx at the same place: both are kept, and this branch's failed-read test takes ansvisor#1252's connection shape (workerSecretName, a Worker without the secret). Co-Authored-By: Claude Opus 5.5 <[email protected]>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Follow-up from #1179's review (not blocking there): "Generated Worker: add
ctx.passThroughOnException(), keep the secret in a secret binding rather than in the source, and send origin plus pathname instead of the full URL."passThroughOnException()and origin + pathname are already on main. This PR does the third item.Server
bot-worker-script.js: the generated Worker no longer holds the connection secret. It readsenv.ANSVISOR_BOT_SECRET, a Worker Secret (Settings › Variables and Secrets)./bots/ingest.WORKER_SECRET_NAME.POST /api/bots/connectionsreturns it asworkerSecretNamefor a Worker, and null for the other senders.Web
NewBotConnection.workerSecretNamecarries the name.Existing Workers, with the secret in their code, keep working:
/bots/ingeststill takes the Bearer secret, however it's set.Related issue
Follow-up to #1179.
Type of change
feat— New featurefix— Bug fixchore— Maintenance / dependenciesdocs— Documentation onlyrefactor— Code change that neither fixes a bug nor adds a featuretest— Adding or updating testsHow to test
Unit tests
bot-worker-script.test.js:env.ANSVISOR_BOT_SECRET;Bearer <secret>;routes/bots.test.js: a Worker connection's script doesn't contain the secret, and the response names the Secret._bots-connect.test.tsx: the Worker steps and the secret's copy block.ai-bots.test.ts: the name is parsed.In the browser: with the branch's API on :8081 and web on :3003, AI bots › Connect › Cloudflare Worker › Create connection shows four steps, the Worker code without
abot_, and the secret under its name. I checked it in light and dark mode, at 1440 and 1024 px, then deleted the connection.Checklist
feature/,fix/,chore/,docs/) — see CONTRIBUTING.mdyarn lintpasses (run fromweb/)yarn typecheckpasses (run fromweb/)yarn format:checkpasses (run fromweb/)Also: web
yarn test(1792) andyarn build; servernpm run lint,npm test(1841).🤖 Generated with Claude Code