fix(worker): bind Slack API auth to a server-side session - #36
Merged
StephenTangCook merged 1 commit intoAug 27, 2026
Conversation
The SPA-facing worker endpoints trusted the `bkb_team_id` and `bkb_user_id`
cookies as proof of identity. Both cookies were plaintext with no signature
and no server-side record, so a client could set them and reach any
workspace's bot token and any consented member's user token.
Mint a random session id at both OAuth callbacks, store `{team_id, user_id}`
in the new SLACK_SESSIONS KV under it, and set only that opaque id as the
`bkb_session` cookie. Every protected endpoint now resolves identity through
the session, never from client-supplied values.
Closes ENG-5917, ENG-5918.
Generated-By: PostHog Desktop
Task-Id: 14ad785e-882d-4ab1-afca-6b829e1f2421
StephenTangCook
marked this pull request as ready for review
August 27, 2026 16:06
StephenTangCook
approved these changes
Aug 27, 2026
StephenTangCook
deleted the
posthog-self-driving/fixworker-bind-slack-api-auth-to-server-1447fc
branch
August 27, 2026 16:08
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
bkb_team_idandbkb_user_idcookies as identity.cookies.tswrites them as plaintext, unsigned, with no server-side record, so a client can set them and load the bot token from KV. The same pattern loaded a member's user token in thesendAsUserbranch.{ team_id, user_id }server-side in the newSLACK_SESSIONSKV under that ID, and set only the opaque ID as thebkb_sessioncookie. Every protected endpoint resolves identity through the session, never from client-supplied values.Reachable through
/api/slack/channels,/api/slack/emojis,/api/slack/messages/send,/api/slack/modals/send, and the/api/slack/me/can-send-as-userenumeration oracle.requireBotInstallbkb_team_idcookiesendAsUser/ modal sendbkb_user_idcookiecan-send-as-userType of change
Area
src/)/slack/install)/slack/user-install)/api/slack/*)/slack/events)scripts/).github/workflows,wrangler.jsonc)Test plan
pnpm run buildpassespnpm run dev:tunnelexercised end-to-end where relevantManual checks:
pnpm run buildbundles the worker and client.pnpm run typecheckreports only the pre-existingsrc/client/App.tsxprop-type error (present on cleanmain, unrelated to this change); no errors in the worker.Screenshots / recordings
N/A — server-side auth change, no UI.
Related issues
Closes ENG-5917, ENG-5918 (linked in the footer).
Checklist
README.md/.dev.vars.example/wrangler.jsoncif config or setup changedImportant
Breaking setup change for forks. This adds a fifth KV namespace,
SLACK_SESSIONS. Forks must runpnpm run setup:kvagain and paste the new ID intowrangler.jsonc(theREPLACE_WITH_SESSIONS_KV_IDplaceholder). After deploy, the oldbkb_team_id/bkb_user_idcookies stop working; users re-run/slack/install(and/slack/user-installfor "send as me") to get a session. Stored installations in KV stay valid.Agent context
wrangler tail/pnpm run logs.Created with PostHog Desktop from this inbox report, addressing ENG-5917, ENG-5918.
Need help on this PR? Tag
@codesmith-botwith what you need. Autofix is disabled.