Repository navigation
Authorize the Slack rotate endpoint, and fail closed on watch ownership - #837
Merged
Merged
Conversation
Two independent authorization defects in lambda/dashboard-api.
POST /api/slack/token/rotate was routed above getUserFromRequest
alongside the two OAuth routes — but unlike those, with no comment
saying why — and the API Gateway route is $default with
AuthorizationType: NONE. It took a workspace's current bot token out of
the request body, rotated it with Slack, replaced the stored one, and
returned the NEW token as {"ok":true,"token":"xoxb-..."}. Possession of
a leaked or already-stale token was therefore the only credential needed
to mint a fresh valid one, while the legitimate owner lost theirs.
Confirmed against production with a deliberately invalid token: the
endpoint answered 500 "workspace not found for token", which shows the
handler ran with nothing in front of it. Nothing was written, because
the lookup fails before the update. spore-bot-workspaces holds seven
real workspaces.
Inbound requests are now verified with Slack's HMAC signature over the
raw body, within a five-minute replay window checked as an ABSOLUTE skew
so a replay cannot be refreshed by dating it forward. The signing secret
this needs already existed — slackSigningSecret(), stored in Secrets
Manager and on every workspace row — and had simply never been used to
verify anything. The response no longer carries the token, and the error
no longer says whether a token matched a workspace, which was an oracle
for whether a token is live.
Separately, handleGetWatch read user_id out of the raw DynamoDB item and
skipped the comparison entirely when the attribute was absent, or
present but not a string. It was the only fail-open ownership check in
the file set; sweeps.go and instances.go already compare directly.
WatchInfo now carries UserID, tagged json:"-" because it is an
authorization input rather than dashboard data and returning it would
leak the owning principal's IAM ARN — so an absent owner is a mismatch
instead of a bypass.
Two of the gates assert ORDER rather than presence: verifying after the
credential has been rotated is a check that cannot prevent anything. And
TestNoOwnershipCheckIsConditionalOnTheAttributeExisting discovers the
fail-open shape across the whole package instead of pinning the one line
that was wrong.
The test signing secret is worded rather than a hex blob on purpose:
Slack's own documentation example trips semgrep's generic-secret rule,
and suppressing that would train the next reader to suppress it too.
Refs GHSA-qc2h-6qqf-wcm4
Closes #821
scttfrdmn
force-pushed
the
fix/821-dashboard-authz
branch
from
October 11, 2026 19:08
22b686f to
3db5164
Compare
Codecov Report✅ All modified and coverable lines are covered by tests. 📢 Thoughts on this report? Let us know! |
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.
Closes #821. Advisory: GHSA-qc2h-6qqf-wcm4 (draft; publishes on merge).
Two independent authorization defects in
lambda/dashboard-api.1. The Slack rotate endpoint was unauthenticated, and handed back a live token
POST /api/slack/token/rotatewas routed abovegetUserFromRequest, alongside thetwo OAuth routes — but unlike those, with no comment saying why:
The handler took the workspace's current bot token out of the request body, scanned
for the matching workspace, rotated it with Slack, replaced the stored token, and returned
the new one:
So possession of a leaked — or already-stale — token was the only credential needed to
mint a fresh valid one, and the legitimate owner lost theirs in the process.
Verified against production, non-destructively
AuthorizationTypeon the$defaultroute isNONE, and the API is public. I probed itwith a token that cannot match anything:
That is the handler running with nothing in front of it. Nothing was written — the
lookup fails before any
UpdateItem, which I confirmed by readingrotateTokenByCurrentTokenfirst.spore-bot-workspacesholds 7 real workspaces, andboth
SLACK_CLIENT_IDandSLACK_SECRETS_ARNare populated, so the handler was liverather than inert.
Fix
Verify Slack's HMAC signature over the raw body before touching any credential:
v0:{timestamp}:{raw body}, HMAC-SHA256, compared withhmac.Equal— a byte-by-bytecomparison of an HMAC is a timing oracle for forging one.
now - ts > maxwould let a replay be refreshed indefinitely by dating it forward.would fail every genuine request, and the tempting fix for that is to stop verifying.
errSlackNotConfiguredand a 500, not a401. The two need opposite handling, and collapsing them is how "we cannot verify"
becomes "we do not verify".
The secret this needs already existed.
slackSigningSecret()has been there allalong, stored in Secrets Manager and on every workspace row — it had simply never been
used to verify anything.
Also: the response no longer contains the token (a live credential in an HTTP response
lands in access logs and every proxy in between), and the error no longer interpolates the
reason, which told a caller whether a token is live.
2. A watch with no owner was returned to any authenticated caller
Two fail-open conditions:
user_idabsent, or present but not a string. Eitherskipped the check entirely. It was the only fail-open ownership check in the file set —
sweeps.go:152/239/350andinstances.go:170/286all use the direct comparison. It waswritten this way because
WatchInfohad noUserIDfield, so the check had to reach intothe raw item map.
WatchInfonow carriesUserID, taggedjson:"-"because it is an authorization inputrather than dashboard data and returning it would leak the owning principal's IAM ARN. An
absent owner is now a mismatch against
"", i.e. a 403.Gates
Nineteen, each watched failing against a revert that compiles.
The Slack verification is driven with genuinely HMAC-signed requests plus ten hostile
variants: no headers at all (the unauthenticated POST that was possible), signature over a
different body, signature from a different secret, replays six minutes either side of now,
a truncated signature, the wrong scheme version, a malformed timestamp, and each header
missing individually.
Two gates assert order, not presence —
TestSlackRotateVerifiesBeforeRotating— becauseverifying after the credential has been rotated is a check that cannot prevent anything.
TestNoOwnershipCheckIsConditionalOnTheAttributeExistingdiscovers the fail-open shapeacross the whole package rather than pinning the one line that was wrong, so it cannot
reappear in another handler. It fails on empty discovery.
TestSlackRotateRouteVerifies…+ the ordering gateTestSlackRotateRouteVerifiesAndDoesNotEchoTheTokenTestSlackRotateVerifiesBeforeRotatingTestNoOwnershipCheckIsConditional…+TestGetWatchComparesTheOwnerDirectlyUserIDserialised to the clientTestWatchOwnerIsNotSerialisedToTheClientTestVerifySlackRequestRejectsEverythingElse/dated_six_minutes_into_the_futureTestVerifySlackRequestFailsClosedWithNoSecretThe second row needed two attempts: my first revert left
newTokendeclared inside theifscope and did not compile, so it proved nothing until rewritten.A note on the test fixture
The signing secret in the tests is worded (
not-a-real-slack-signing-secret-only-for-tests)rather than a hex blob. Slack's own documentation example trips semgrep's
detected-generic-secretrule, and suppressing that would train the next reader tosuppress it too. HMAC does not care what the bytes are.
Verification
make check(all nested modules),make check-docs, changelog gate,semgrep scan --config=auto --error .(0 findings, no suppressions added).Not deployed. Lambda code change; the vulnerable version is live until a redeploy, like
#797 and #820.