Skip to content

fix(integrations): read the verification credentials from the instance, and close the legacy Slack route to inactive rows (TASK-141) - #1907

Merged
lilyshen0722 merged 2 commits into
mainfrom
kai/141-secret-hardening
Sep 26, 2026
Merged

lilyshen0722 merged 2 commits into
mainfrom
kai/141-secret-hardening

Conversation

@lilyshen0722

@lilyshen0722 lilyshen0722 commented Sep 25, 2026 •

Copy link
Copy Markdown
Contributor

TASK-141. Three values the ingress trusts came from the row a caller can write, and two of them were verified twice with two different answers. This makes every reader take the instance's value, stops a body from putting one back, and closes the legacy route to an inactive row.

Second head, 19c69088 — the Telegram twin of the Slack disagreement, found by @vera in 74294 (see Re: the hold at the end).

The row could pick the key that verifies its own events

value read at (this head) before now
Slack signing key routes/webhooks/slack.ts:215 integration.config?.signingSecret || SLACK_SIGNING_SECRET SLACK_SIGNING_SECRET
Slack signing key, second check integrations/providers/slackProvider.ts:81 config.signingSecret alone SLACK_SIGNING_SECRET
Slack app-level key routes/registry/helpers.ts:265 config.appToken || SLACK_APP_TOKEN SLACK_APP_TOKEN
Slack signing key routes/registry/helpers.ts:266 config.signingSecret || SLACK_SIGNING_SECRET SLACK_SIGNING_SECRET
Telegram webhook key routes/registry/helpers.ts:285 config.secretToken || TELEGRAM_SECRET_TOKEN TELEGRAM_SECRET_TOKEN
Telegram webhook key, second check integrations/providers/telegramProvider.ts:111-116 if (config.secretToken) + verify the header against it removed — the route's env-only, fail-closed check (routes/webhooks/telegram.ts:66-87, :415) is the only one

The double verification is a defect this change also fixes, and it is why the provider site is not cosmetic. POST /webhooks/slack/:integrationId verifies at :219 with the env fallback, then calls the provider at :244, whose events handler re-verifies with config.signingSecret alone — so an event signed with the instance secret passes the route and is 401'd by the handler. Dormant, not live: :244 is the legacy per-row path, the OAuth bind writes chatId + botTokenRef, and production's single Slack row carries none of the four fields. With both sites env-only the two checks cannot disagree.

The Telegram half was the same defect one connector over, and it was a hold on aa7446cd rather than a bug I found (Vera 74294): telegramProvider.ts re-verified the x-telegram-bot-api-secret-token header against config.secretToken, and it is reached only from routes/webhooks/telegram.ts:513 — after that route verified the same header against TELEGRAM_SECRET_TOKEN and failed closed. So a row-level copy was a second gate that 401'd an update the instance secret had just accepted. Deleted rather than made env-only: the route's check is already env-only and fail-closed, so a duplicate here could only ever reject. My first pass named four reader sites and asserted "every verification reader is env-only" while this one stood; the grep I ran was for the four sites I already knew, which is how a claim outruns its evidence.

Why the provisioners need no edit here. applyOpenClawIntegrationChannels in both provisioners reads entry.appToken / entry.signingSecret, and that entry comes from buildOpenClawIntegrationChannels — the same helper, and its only producer (routes/registry/provision.ts:289, routes/registry/reprovision.ts:127; grepped, no other caller). Making :265-266 env-only removes the row's copy from the projection at its only source, so the provisioners read env-derived values by construction. Editing them too would be a second place to keep in step for no behaviour change.

What a body can no longer set

signingSecret, appToken and secretToken join SERVER_OWNED_CONFIG_KEYS. The strip is the boundary that lasts: the legacy route takes no auth, so a planted key is ingress that outlives the access that set it, and env-only readers close only the reads that exist today.

Census first, and it makes this a no-live-break change (connector-ops 74259, by $exists, no values): of the 4 Slack+Telegram rows in production, each of the three keys is present on 0, not even as an empty string; SLACK_SIGNING_SECRET is set, TELEGRAM_SECRET_TOKEN is set, SLACK_APP_TOKEN is unset (nothing uses an app token today). So no legacy per-row app exists to break, and a reader that is env-only has no live subject it can regress.

The legacy route now answers an inactive row like an unknown id

if (!integration || integration.type !== 'slack') also did no isActive check, while /events resolves only isActive rows (:87). An inactive row's planted key was therefore durable unauthenticated ingress. It now returns the same 404, with nothing buffered.

--unset-empty (opt-in) removes the retired key from an empty holder

Two production Discord rows hold config.botToken: ''. No writer can refresh or clear it — TASK-139 refuses (Discord) or strips (all types) a body's value, and this script's write predicate is { botToken: NON_EMPTY_STRING } in the other collection — so an $exists census reads "2 rows carry config.botToken" for a field with no writer. That reading produced a wrong claim on 2026-09-25; the counts are already reported apart, and this removes the residue instead of documenting it forever.

Removing the key is reader-neutral, verified not assumed. No code tests the key's presence: no 'botToken' in config, no hasOwnProperty, no Object.keys(config) in backend/**/*.ts. Every reader is falsy-safe — isSupplied (utils/discordBinding.ts:45), the Discord resolver (integrations/providers/discordProvider.ts:60, env-first per utils/discordBotToken.ts:7), slackProvider.ts:63 (config.botToken || env). The default run is still a report only; the filter is scoped { type: 'discord', 'config.botToken': '' }.

Run order: code → Deploy Dev → a human runs the script with --apply --unset-empty, exactly as the TASK-124 migration is staged. It is not part of this PR's deploy.

Comments and docs carried in the same pass

  • integrations/manifests.ts:96-97 — the comment was wrong in two ways (Vera 74276): "no route writes it" is false while a body can, and "both readers fall back" was never true of the provider. Both were corrected to what this head does.
  • utils/serverOwnedConfigKeys.ts:14-16 — the two invariant bullets described the deleted design (serverOwnedConfig: was named as a manifest field, and its only occurrence in the repo was that comment). Replaced with Vera's wording: the published projection names no key in this list, and every key a route strips is in this list and is the only copy.
  • utils/serverOwnedConfigKeys.ts:35-36 — the botToken bullet said its "only writer is a caller's body"; at this head there is no row-level writer left (this row's strip completes it). Reworded, keeping the reason the entry stays: the two Discord refusals must keep running first.
  • docs/runbooks/connector-credentials-setup.md:193-196 — said the legacy integration "reads a per-integration signing secret from its own row and falls back to the same env". Now: verifies with SLACK_SIGNING_SECRET only, and an inactive row 404s.
  • docs/slack/README.md:5, :12, :18, :31 — :18 told the reader to paste the signing secret into the integration row, which this PR makes impossible; :31 promised the callback returns a signing secret; :5 named slackProvider.js (it is .ts). Setup now points at the instance environment.
  • Comment-only and doc-only edits have no witness — a comment cannot redden a test. The behaviour they describe is witnessed elsewhere in this PR (the strip list by M7, the published-projection invariant by manifestCallerContract.test.js, the reader behaviour by the env-only tests).

Witnesses and mutation ledger

New: slack.webhook.legacyOwnership.test.js (the route), telegramProvider.rowSecret.test.js (the Telegram handler: it buffers whatever copy the row carries, and does not refuse a request for a missing header — that decision is the route's), plus cases added to slackProvider.bindingShape.test.js (the handler's own verification), registry.helpers.channelTokenSources.test.js (the projection), integrations.manifestStatus.test.js (the strip), clearDiscordBotToken.test.ts (the flag). slack.webhook.signature.test.js's legacy fixture needed isActive: true — it described a state the route now refuses, which is itself the witness that the guard is real.

11 mutation arms, one deliberate survivor, every reddened test named (/tmp/kai-141-ledger.py):

arm reddens
M1 :215 row-first again verifies with the instance secret, so a secret planted on the row is refused
M2 guard drops isActive answers an inactive row like an unknown id and buffers nothing
M3 provider reads the row copy verifies an event with the instance secret… + fails closed when the instance secret is unset…
M4/M5/M6 helpers prefer the row (appToken / signingSecret / secretToken) the three env-only cases each
M7 the three keys leave the strip list strips every verification credential a body tries to set…
M8 --unset-empty never writes removes the key from an empty holder under --unset-empty…
M9 the unset filter loses its type scope same test (the other type's empty copy must survive)
M10 the Telegram handler gates on the row copy again buffers an update the route accepted, whatever copy the row carries + does not refuse a request for a missing header
M11 an env-only duplicate gate in the Telegram handler SURVIVED — tripwire, and it should

M11 is the honest limit of the Telegram witness: it pins the row read, not "no second gate exists". An env-only duplicate cannot fire on anything the route admitted (the route compares that same header to that same value and fails closed), so it is inert by construction rather than unobserved. Disclosed so the survivor is not read as coverage.

Evidence

  • tsc -p backend/tsconfig.build.json --noEmit → 0 errors.
  • eslint over the 6 changed .ts files → 0 errors / 10 warnings, all on pre-existing lines (slackProvider.ts:40, :76; telegramProvider.ts:96, :107; helpers.ts:530, :607, :613, :641, :650); none on an added line.
  • Targeted sweep (integrations, scripts, contracts, the Slack/webhook/registry/integration route suites) → 36 suites / 306 tests, all pass.
  • Full backend tier: 452 of 458 suites passed (6 skipped), 4206 passed / 24 skipped of 4230 tests, 0 failures, 225.618 s.

Re: the hold at aa7446cd (Vera 74294)

Vera censused every row-level read of the three keys at that head instead of checking the four sites this PR named, and the grep returned exactly one hit — a verification gate. Her spelling of why it is a hold rather than an exposure is exact and I am not going to re-argue it: the block is additive, the strip means no body can plant it again, and production carries 0 rows with any of the three keys by $exists (independently re-measured, control config.chatId = 1). What failed was the claim — a comment saying "every reader takes them from the environment" while a reader did not is worse than the reader, because the next person stops looking.

Taken as the first option she offered (delete + witness), because this PR already carries its Slack twin: the duplicate gate is gone, and the witness reddens if the row read returns (M10). Nothing else in the hold moved — her aimed mutations and mine agree on which test each revert reddens, and --unset-empty's filter is unchanged.

Two corrections to my own text rode along: the sites table is five readers plus one removed gate (not four), and the strip-list comment now says where the row copy could still decide a request instead of claiming a uniformity that had an exception.

Gate: @vera.

…e, and close the legacy Slack route to inactive rows (TASK-141)

The legacy per-row Slack route takes no auth, and three of the values it trusts
came from the row a caller can write.

* `routes/webhooks/slack.ts` verified with `config.signingSecret || env`, and the
  provider it hands off to (`integrations/providers/slackProvider.ts`)
  re-verified with `config.signingSecret` ALONE - so the two checks disagreed:
  an env-signed event passed the route and was 401'd by the handler.
* `routes/registry/helpers.ts` preferred the row's `appToken` and
  `signingSecret` over the environment, and `secretToken` for Telegram. It is
  the only producer of `integrationChannels` (routes/registry/provision.ts,
  reprovision.ts), so this one site is what both provisioners project.
* `clear-discord-bot-token.ts` could report the empty `config.botToken` holders
  but never remove them, leaving a key with no writer on two production rows and
  an `$exists` census that reads 2.

Now: every reader takes the instance's value, the three keys join
`SERVER_OWNED_CONFIG_KEYS` (so a body cannot put them back), an inactive row on
the legacy route answers 404 like an unknown id, and `--unset-empty` removes the
retired key from an empty holder.
… gate (TASK-141, Vera 74294)

`telegramProvider.ts` re-verified `x-telegram-bot-api-secret-token` against
`config.secretToken`. It is reached only from `routes/webhooks/telegram.ts:513`,
which has already verified that header against `TELEGRAM_SECRET_TOKEN` and fails
closed — so a row-level copy was a second gate that 401'd an update the instance
secret had just accepted, one connector over from the Slack pair this PR fixes.

Deleted rather than made env-only: the route's check is already env-only and
fail-closed, so a duplicate here could only ever reject. Witness in the shape of
the Slack one: the handler buffers whatever copy the row carries. Re-adding the
row read reddens it; an env-only duplicate survives, and that is a property
rather than a gap — such a check cannot fire on anything the route admitted.
@lilyshen0722
lilyshen0722 added this pull request to the merge queue Sep 25, 2026
Merged via the queue into main with commit f43fa40 Sep 26, 2026
19 checks passed
samxu01 pushed a commit that referenced this pull request Sep 26, 2026
…red (TASK-141 follow-up)

`docs/telegram/README.md` listed `secretToken` as row config and called the
secret optional in three places, and `docs/integrations/README.md` indexed it the
same way. `routes/webhooks/telegram.ts:65-83` rejects every update while
`TELEGRAM_SECRET_TOKEN` is unset (the only exception is the local-dev
`TELEGRAM_WEBHOOK_ALLOW_UNVERIFIED=true` opt-out), and from #1907 the key is in
`SERVER_OWNED_CONFIG_KEYS`, so a row copy is stripped by the API and read by
nothing. Both halves are now stated where a reader looks.

Opened after #1907 merges: the row-config half describes the post-#1907 state,
and a docs PR merged ahead of it would document a state no reader sees.
lilyshen0722 added a commit to thantiklermcirony/commonly that referenced this pull request Oct 9, 2026
…red (TASK-141 follow-up) (Team-Commonly#1908)

`docs/telegram/README.md` listed `secretToken` as row config and called the
secret optional in three places, and `docs/integrations/README.md` indexed it the
same way. `routes/webhooks/telegram.ts:65-83` rejects every update while
`TELEGRAM_SECRET_TOKEN` is unset (the only exception is the local-dev
`TELEGRAM_WEBHOOK_ALLOW_UNVERIFIED=true` opt-out), and from Team-Commonly#1907 the key is in
`SERVER_OWNED_CONFIG_KEYS`, so a row copy is stripped by the API and read by
nothing. Both halves are now stated where a reader looks.

Opened after Team-Commonly#1907 merges: the row-config half describes the post-Team-Commonly#1907 state,
and a docs PR merged ahead of it would document a state no reader sees.
lilyshen0722 added a commit to thantiklermcirony/commonly that referenced this pull request Oct 9, 2026
… daemon, MCP and the CLI (Team-Commonly#1926)

* docs(readme): point at what a team does first: channels, grants, the daemon, MCP and the CLI

Sam, 2026-09-25: "README lack new good pointers". The link row under the
badges read Live Demo · Documentation · Self-host · Agent Marketplace, and
the Documentation table led with the scope doc and ADR-001. Both now lead
with the tasks a team starts with, each linking the page that walks it:
the quickstart, connecting Slack or Telegram, granting GitHub, running your
own agent with the daemon, the MCP server and the CLI (with their npm
packages), then self-hosting. ADRs collapse to one "Design records" row.

Links go to docs-site pages in the repo, since the docs site has no public
URL. docs/slack/README.md is not linked: it still describes the legacy
ingest-only provider with per-row secrets, which Team-Commonly#1907 removed.

Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
Claude-Session: https://claude.ai/code/session_01RUTWqLu6zhFPraoPHZcjQP

* docs(readme): link the hosted docs site, and describe the connectors page as what it covers (otto's hold on Team-Commonly#1926)

docs.commonly.me is live, so the pointers go there rather than to .mdx
source, whose site-absolute links 404 on GitHub. The connectors page teaches
how an outside service joins a pod and how grants work; it names no platform,
so the row no longer promises Slack or Telegram, and Connectors and Grants
merge into one row as the page itself does.

Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
Claude-Session: https://claude.ai/code/session_01RUTWqLu6zhFPraoPHZcjQP

---------

Co-authored-by: Claude Opus 5.5 (1M context) <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant