Skip to content

security: verify the Slack signing secret before executing approved actions - #24

Closed
Nitjsefnie wants to merge 2 commits into
open-devops-agent:mainfrom
Nitjsefnie-OSC:fix/11-slack-signature-verification
Closed

Nitjsefnie wants to merge 2 commits into
open-devops-agent:mainfrom
Nitjsefnie-OSC:fix/11-slack-signature-verification

Conversation

@Nitjsefnie

Copy link
Copy Markdown
Contributor

The exposure

/slack/action parsed a form payload and handed approved commands straight to agent.execute_approved_action — with no verification that the request came from Slack. Anyone able to reach the endpoint could curl a forged approve_action payload 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:

  • Signature base string is v0:{timestamp}:{raw body}, joined with colons.
  • HMAC-SHA256 keyed with SLACK_SIGNING_SECRET, hex digest, prefixed v0=, compared to X-Slack-Signature.
  • Compared with hmac.compare_digest, never == — a plain comparison leaks the correct signature a byte at a time under timing analysis.
  • The HMAC covers the raw request bytes (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_signature helper sits next to the existing verify_github_signature and follows its shape and its 401-on-mismatch handling.

Replay window

X-Slack-Request-Timestamp must 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 not float(). float("nan") parses fine and every comparison against NaN is False, so abs(now - nan) > 300 is False — a nan timestamp would sail straight through the window check. int() rejects it.

Fail-open vs fail-closed — decision

Fails closed. An unset or blank SLACK_SIGNING_SECRET rejects 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.

⚠️ Upgrade impact: this is a breaking change for existing deployments. Any deployment currently using Slack approvals must set SLACK_SIGNING_SECRET (Slack app admin panel → Basic Information) or /slack/action will return 401 and approvals will stop working. This is intentional — the alternative is leaving those deployments silently executing forged commands.

Acceptance criteria

  • Validate the Slack request signature before processing approve_action / reject_action
  • Reject replayed requests (timestamp tolerance)
  • Add unit tests with known Slack signature fixtures
  • Add SLACK_SIGNING_SECRET to .env.example
  • Add SLACK_SIGNING_SECRET to services/org_config.py — not applicable on main

On services/org_config.py: that file does not exist on main. It lives on the unmerged fix/security-hardening and feat/add-mcp branches, where SLACK_SIGNING_SECRET is already present in ORG_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 on main separately.

The verification reads the secret from os.getenv, matching how WEBHOOK_SECRET and every other credential in api/server.py is 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/TestClient style:

  • Slack's own published fixture — the worked example from the docs (secret 8f742231b10e..., timestamp 1531420618), asserting our construction reproduces Slack's published digest v0=a2114d57... exactly.
  • Valid signature + fresh timestamp → 200, and the command reaches execute_approved_action intact (this also proves the body survives request.body() → request.form()).
  • Forged signature → 401. Well-formed signature under the wrong secret → 401.
  • Signature lifted from a benign request onto a different body (kubectl get pods → rm -rf /) → 401.
  • Valid signature with a stale timestamp → 401, and a future timestamp → 401. A request just inside the window is still accepted, so legitimate slow requests don't break.
  • Missing signature header / missing timestamp header / both missing → 401.
  • Non-numeric, nan and inf timestamps → rejected.
  • Missing or blank secret → 401 (fail-closed).
  • A non-ASCII signature header → a clean 401 rather than a 500 traceback. hmac.compare_digest raises TypeError on non-ASCII str, 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

python -m pytest tests/ -q
87 passed, 1 warning in 1.98s

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_action plus 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.

…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

gitguardian Bot commented Jul 16, 2026

Copy link
Copy Markdown

⚠️ GitGuardian has uncovered 1 secret following the scan of your pull request.

Please consider investigating the findings and remediating the incidents. Failure to do so may lead to compromising the associated services or software components.

Since your pull request originates from a forked repository, GitGuardian is not able to associate the secrets uncovered with secret incidents on your GitGuardian dashboard.
Skipping this check run and merging your pull request will create secret incidents on your GitGuardian dashboard.

🔎 Detected hardcoded secret in your pull request
GitGuardian id GitGuardian status Secret Commit Filename
- - Generic High Entropy Secret 868eed2 tests/test_slack_signature.py View secret
🛠 Guidelines to remediate hardcoded secrets
  1. Understand the implications of revoking this secret by investigating where it is used in your code.
  2. Replace and store your secret safely. Learn here the best practices.
  3. Revoke and rotate this secret.
  4. 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


🦉 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.

@Nitjsefnie

Copy link
Copy Markdown
Contributor Author

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 SIGNING_SECRET = "8f742231b10e8888abcd99yyyzzz85a5" in tests/test_slack_signature.py. That's the signing secret from Slack's own verification docs — note the literal yyyzzz placeholder in the middle. It authenticates nothing; it's the key half of Slack's published worked example.

It's there for one test that earns its keep, test_known_slack_signature_fixture: Slack publishes a full secret + timestamp + body → signature quadruple, and that test asserts our implementation reproduces their documented digest. Verified independently just now:

$ python3 -c "…hmac.new(secret, b'v0:1531420618:'+body, sha256)…"
computed: v0=a2114d57b48eac39b9ad189dd8316235a7b4a8d21a10bd27519666489c69b503
expected: v0=a2114d57b48eac39b9ad189dd8316235a7b4a8d21a10bd27519666489c69b503

That's the only test here that isn't circular. Every other case signs with our own _sign() helper and verifies with our own code — if I'd built the basestring wrong (say v0:{ts}:{parsed} instead of the raw body), those would all still pass happily. Slack's fixture is the one thing that would catch it.

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:

  1. Leave it and dismiss the incident once, since the value is public and inert.
  2. Add it to your GitGuardian ignore list (.gitguardian.yaml) — I didn't touch that config unasked.
  3. Drop the fixture test and generate a random secret per-run. Clean scan, but you lose the only external check on the basestring format. I'd rather not, but I'll do it if you prefer green over that coverage.

Happy to push whichever you want.

@OkiriGabriel

Copy link
Copy Markdown
Collaborator

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
Refactor to use a random secret per run (and drop the Slack fixture test).
Option 1 is fine with me if you document why in the yaml file

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]>
@Nitjsefnie

Copy link
Copy Markdown
Contributor Author

Done — went with option 1: added .gitguardian.yaml with an ignored_matches entry for the fixture (f2cba86). The yaml documents why inline: it's the example signing secret from Slack's signature-verification docs, kept because it's the one test vector that lets the suite verify our implementation against Slack's published expected digest instead of only against itself.

No rush on the merge — happy to rebase or retarget onto develop once your branch setup and #20 consolidation land.

@OkiriGabriel

Copy link
Copy Markdown
Collaborator

Closing as duplicate — Slack signing secret verification was implemented in PR #20 (merged on feat/add-mcp). Thanks @Nitjsefnie for the detailed test approach.

Nitjsefnie added a commit to Nitjsefnie-OSC/DevOps-AI-Agent that referenced this pull request Jul 16, 2026
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]>
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.

Verify Slack signing secret on /slack/action endpoint

3 participants