Skip to content

Authorize the Slack rotate endpoint, and fail closed on watch ownership - #837

Merged
scttfrdmn merged 1 commit into
mainfrom
fix/821-dashboard-authz
Oct 11, 2026
Merged

scttfrdmn merged 1 commit into
mainfrom
fix/821-dashboard-authz

Conversation

@scttfrdmn

Copy link
Copy Markdown
Contributor

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/rotate was routed above getUserFromRequest, alongside the
two OAuth routes — but unlike those, with no comment saying why:

// OAuth routes bypass authentication — they're called by Slack's redirect,
// not by an authenticated spore.host user.
if path == "/api/slack/oauth" && method == "GET" { ... }
...
if path == "/api/slack/token/rotate" && method == "POST" {
    return handleSlackTokenRotate(ctx, cfg, request)   // no comment, no auth
}

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:

Body: fmt.Sprintf(`{"ok":true,"token":%q}`, newToken),

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

AuthorizationType on the $default route is NONE, and the API is public. I probed it
with a token that cannot match anything:

$ curl -s -X POST 'https://…/api/slack/token/rotate' \
    -d '{"token":"xoxb-NOT-A-REAL-TOKEN-spore-audit-probe","type":"tokens_revoked"}'
HTTP 500
{"success":false,"error":"Token rotation failed: workspace not found for token"}

That is the handler running with nothing in front of it. Nothing was written — the
lookup fails before any UpdateItem, which I confirmed by reading
rotateTokenByCurrentToken first. spore-bot-workspaces holds 7 real workspaces, and
both SLACK_CLIENT_ID and SLACK_SECRETS_ARN are populated, so the handler was live
rather than inert.

Fix

Verify Slack's HMAC signature over the raw body before touching any credential:

  • v0:{timestamp}:{raw body}, HMAC-SHA256, compared with hmac.Equal — a byte-by-byte
    comparison of an HMAC is a timing oracle for forging one.
  • Five-minute replay window, checked as an absolute skew. Only testing
    now - ts > max would let a replay be refreshed indefinitely by dating it forward.
  • The raw body is base64-decoded when API Gateway encoded it. Signing the encoded form
    would fail every genuine request, and the tempting fix for that is to stop verifying.
  • A missing signing secret returns a distinct errSlackNotConfigured and a 500, not a
    401. 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 all
along, 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

if v, ok := result.Item["user_id"]; ok {
    if s, ok := v.(*dynamodbtypes.AttributeValueMemberS); ok && s.Value != userARN {
        return errorResponse(403, "Access denied"), nil
    }
}

Two fail-open conditions: user_id absent, or present but not a string. Either
skipped the check entirely. It was the only fail-open ownership check in the file set —
sweeps.go:152/239/350 and instances.go:170/286 all use the direct comparison. It was
written this way because WatchInfo had no UserID field, so the check had to reach into
the raw item map.

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. 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 — because
verifying after the credential has been rotated is a check that cannot prevent anything.

TestNoOwnershipCheckIsConditionalOnTheAttributeExisting discovers the fail-open shape
across the whole package rather than pinning the one line that was wrong, so it cannot
reappear in another handler. It fails on empty discovery.

revert caught by
rotate route stops verifying TestSlackRotateRouteVerifies… + the ordering gate
rotate echoes the new token again TestSlackRotateRouteVerifiesAndDoesNotEchoTheToken
verify moved after rotate TestSlackRotateVerifiesBeforeRotating
watches back to the presence-gated check TestNoOwnershipCheckIsConditional… + TestGetWatchComparesTheOwnerDirectly
UserID serialised to the client TestWatchOwnerIsNotSerialisedToTheClient
replay skew made one-sided TestVerifySlackRequestRejectsEverythingElse/dated_six_minutes_into_the_future
missing secret no longer fails closed TestVerifySlackRequestFailsClosedWithNoSecret

The second row needed two attempts: my first revert left newToken declared inside the
if scope 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-secret rule, and suppressing that would train the next reader to
suppress 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.

@scttfrdmn scttfrdmn added this to the Security audit 2026-10 milestone Oct 11, 2026
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
scttfrdmn force-pushed the fix/821-dashboard-authz branch from 22b686f to 3db5164 Compare October 11, 2026 19:08
@codecov

codecov Bot commented Oct 11, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.

📢 Thoughts on this report? Let us know!

@scttfrdmn
scttfrdmn merged commit 9b08faf into main Oct 11, 2026
7 checks passed
@scttfrdmn
scttfrdmn deleted the fix/821-dashboard-authz branch October 11, 2026 19:18
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.

Make the dashboard watch ownership check fail closed, and authenticate the Slack rotate path

1 participant