Repository navigation
security: verify the Slack signing secret before executing approved actions - #24
Nitjsefnie wants to merge 2 commits into
Conversation
…ctions /slack/action executed approved commands via agent.execute_approved_action on the strength of an unauthenticated POST. Anyone who could reach the endpoint could forge an approval and run an arbitrary command — the approval step the operator relies on was not authenticated at all. Verify every request against Slack's documented signing scheme (https://api.slack.com/authentication/verifying-requests-from-slack): HMAC-SHA256 over "v0:{timestamp}:{raw body}" keyed with SLACK_SIGNING_SECRET, compared to X-Slack-Signature with hmac.compare_digest, and bounded by Slack's documented five-minute replay window on X-Slack-Request-Timestamp so a captured-but-valid signature cannot be replayed indefinitely. The HMAC is computed over the raw request bytes read before form parsing, since a re-serialized form would not reproduce the digest Slack signed. Verification fails closed: an unset or blank SLACK_SIGNING_SECRET rejects every request rather than falling back to the unauthenticated behaviour. This endpoint executes commands, so the skip-if-unset opt-out used by the GitHub webhook would leave the default configuration exploitable. Deployments must set SLACK_SIGNING_SECRET or /slack/action returns 401. Signatures are compared as bytes: hmac.compare_digest raises TypeError on non-ASCII str, and the signature header is attacker-controlled, so a str comparison turns junk input into a 500 instead of a 401. Tests cover Slack's own published signature fixture, valid/forged/wrong-key signatures, a signature lifted onto a different body, stale and future timestamps, missing headers, and the fail-closed path. Co-Authored-By: Claude Opus 4.8 <[email protected]>
|
| GitGuardian id | GitGuardian status | Secret | Commit | Filename | |
|---|---|---|---|---|---|
| - | - | Generic High Entropy Secret | 868eed2 | tests/test_slack_signature.py | View secret |
🛠 Guidelines to remediate hardcoded secrets
- Understand the implications of revoking this secret by investigating where it is used in your code.
- Replace and store your secret safely. Learn here the best practices.
- Revoke and rotate this secret.
- If possible, rewrite git history. Rewriting git history is not a trivial act. You might completely break other contributing developers' workflow and you risk accidentally deleting legitimate data.
To avoid such incidents in the future consider
- following these best practices for managing and storing secrets including API keys and other credentials
- install secret detection on pre-commit to catch secret before it leaves your machine and ease remediation.
🦉 GitGuardian detects secrets in your source code to help developers and security teams secure the modern development process. You are seeing this because you or someone else with access to this repository has authorized GitGuardian to scan your pull request.
|
On the GitGuardian hit — it's a false positive, but it's yours to decide, so here's exactly what it is. The flagged string is It's there for one test that earns its keep, $ python3 -c "…hmac.new(secret, b'v0:1531420618:'+body, sha256)…"
computed: v0=a2114d57b48eac39b9ad189dd8316235a7b4a8d21a10bd27519666489c69b503
expected: v0=a2114d57b48eac39b9ad189dd8316235a7b4a8d21a10bd27519666489c69b503That's the only test here that isn't circular. Every other case signs with our own GitGuardian notes it can't associate fork findings with your dashboard, but merging would create an incident there — real noise for you. Three ways out, your call:
Happy to push whichever you want. |
|
Thanks for the detailed explanation — I agree this is Slack's public test fixture, not a real secret. Not merging yet while we set up our develop branch and consolidate security work in PR #20. Before we revisit this PR, please either: Add a .gitguardian.yaml ignore for that test fixture, or |
The flagged string in tests/test_slack_signature.py is the example signing secret from Slack's signature-verification documentation, not a credential. Ignore it explicitly, with the reasoning documented in the yaml, per maintainer preference on PR open-devops-agent#24. Co-Authored-By: Claude Fable 5 <[email protected]>
|
Done — went with option 1: added No rush on the merge — happy to rebase or retarget onto |
|
Closing as duplicate — Slack signing secret verification was implemented in PR #20 (merged on |
The flagged string in tests/test_slack_signature.py is the example signing secret from Slack's signature-verification documentation, not a credential. Ignore it explicitly, with the reasoning documented in the yaml, per maintainer preference on PR open-devops-agent#24. Co-Authored-By: Claude Fable 5 <[email protected]>
The exposure
/slack/actionparsed a form payload and handed approved commands straight toagent.execute_approved_action— with no verification that the request came from Slack. Anyone able to reach the endpoint couldcurla forgedapprove_actionpayload with a base64 command of their choosing and have the agent execute it. That is remote command execution through an approval the operator never gave, and it defeats the whole point of the human-approval gate: the "approval" was accepted from an anonymous source.What this implements
Slack's documented signing scheme, verified against the official docs rather than reconstructed from memory:
v0:{timestamp}:{raw body}, joined with colons.SLACK_SIGNING_SECRET, hex digest, prefixedv0=, compared toX-Slack-Signature.hmac.compare_digest, never==— a plain comparison leaks the correct signature a byte at a time under timing analysis.await request.body()), read before form parsing. A digest over a re-serialized form would not match what Slack actually signed — this is the classic way signature verification passes its tests and fails on every real request.The new
verify_slack_signaturehelper sits next to the existingverify_github_signatureand follows its shape and its 401-on-mismatch handling.Replay window
X-Slack-Request-Timestampmust be within Slack's documented five minutes of local time. Without this, a signature is valid forever: anyone who captures one legitimate approval request (a proxy log, an error report, a mirrored request) can replay those exact bytes indefinitely and re-execute the command. A signature that never expires is not authentication, so the window is checked before the HMAC.The timestamp is parsed with
int(), deliberately notfloat().float("nan")parses fine and every comparison against NaN isFalse, soabs(now - nan) > 300isFalse— anantimestamp would sail straight through the window check.int()rejects it.Fail-open vs fail-closed — decision
Fails closed. An unset or blank
SLACK_SIGNING_SECRETrejects every request with 401.The GitHub webhook wraps its check in
if os.getenv("WEBHOOK_SECRET"):, skipping verification when the secret is unset. I deliberately did not copy that here. That opt-out means the default configuration is the exploitable one, and the two endpoints have very different blast radii: an unverified GitHub webhook enqueues an incident for the agent to look at, while an unverified Slack action executes a command. For an endpoint whose entire purpose is authorizing execution, "no secret configured" is a misconfiguration, not a licence to accept anonymous approvals — and a silent fall-open would be invisible in exactly the deployments that most need the check.Acceptance criteria
approve_action/reject_actionSLACK_SIGNING_SECRETto.env.exampleSLACK_SIGNING_SECRETtoservices/org_config.py— not applicable onmainOn
services/org_config.py: that file does not exist onmain. It lives on the unmergedfix/security-hardeningandfeat/add-mcpbranches, whereSLACK_SIGNING_SECRETis already present inORG_CREDENTIAL_KEYS— so this criterion is already satisfied wherever that module exists, and creating the whole multi-tenant credentials module here would both exceed this fix and collide with those branches. Flagging rather than guessing; happy to add it if you'd prefer it land onmainseparately.The verification reads the secret from
os.getenv, matching howWEBHOOK_SECRETand every other credential inapi/server.pyis read today, so it will pick up an org-resolved value through the existing env path.Tests
New
tests/test_slack_signature.py(15 tests), in the existing pytest/TestClientstyle:8f742231b10e..., timestamp1531420618), asserting our construction reproduces Slack's published digestv0=a2114d57...exactly.execute_approved_actionintact (this also proves the body survivesrequest.body()→request.form()).kubectl get pods→rm -rf /) → 401.nanandinftimestamps → rejected.hmac.compare_digestraisesTypeErroron non-ASCIIstr, and the header is attacker-controlled, so the comparison is done on bytes.Each guard was mutation-tested to confirm the tests actually bite: removing the replay window fails exactly the stale/future tests, and making the secret fail open fails exactly the fail-closed test.
Gates
72 of those pass on unmodified
main(verified before starting); the 15 new ones are this PR. No existing test was modified or relaxed.Scope is limited to
slack_actionplus the new helper, so this should not collide with the in-flight work on the alertmanager/manual handlers in the same file.Closes #11
Prepared with AI assistance (Claude Opus 4.8), human-reviewed before submission.