Skip to content

Add standalone Slack interaction engine with signature verification and immutable audit persistence#363

Merged
LVT-ENG merged 2 commits into
mainfrom
copilot/slack-signature-validation
Jun 5, 2026
Merged

Add standalone Slack interaction engine with signature verification and immutable audit persistence#363
LVT-ENG merged 2 commits into
mainfrom
copilot/slack-signature-validation

Conversation

Copilot AI commented Jun 5, 2026

Copy link
Copy Markdown
Contributor

This PR introduces a dedicated FastAPI Slack interaction endpoint to process interactive actions securely and persist transaction state in SQLite. It replaces the ad-hoc example flow with a runnable main_engine.py service wired for environment-based secrets and production-safe request handling.

  • Security hardening

    • Added Slack signature verification (X-Slack-Request-Timestamp, X-Slack-Signature) using HMAC SHA256.
    • Enforced timestamp replay window checks.
    • Added startup-time validation for required secret (SLACK_SIGNING_SECRET).
  • Interaction processing

    • Implemented /api/slack/interact payload parsing with defensive validation for expected action/user fields.
    • Built transactional status message generation from Slack action context.
    • Added fallback behavior for response_url via SLACK_WEBHOOK_URL env var when needed.
  • Slack response delivery

    • Moved outbound Slack callback posting to a thread pool to avoid blocking the request path.
    • Added HTTP error propagation for failed Slack callback updates.
  • Immutable audit persistence

    • Added auditoria.db initialization with refs(ref_id, status, timestamp) schema.
    • Persisted action state using INSERT OR REPLACE on ref_id with explicit commit semantics.
sig_basestring = f"v0:{timestamp}:{body.decode()}".encode("utf-8")
my_signature = "v0=" + hmac.new(
    SLACK_SIGNING_SECRET.encode("utf-8"),
    sig_basestring,
    hashlib.sha256,
).hexdigest()

if not hmac.compare_digest(my_signature, signature):
    raise HTTPException(status_code=403, detail="Firma inválida")

@LVT-ENG

LVT-ENG commented Jun 5, 2026

Copy link
Copy Markdown
Member

Superconmit_max.sh

@LVT-ENG LVT-ENG marked this pull request as ready for review June 5, 2026 18:12
@LVT-ENG LVT-ENG merged commit 4c94e46 into main Jun 5, 2026
3 of 8 checks passed

@LVT-ENG LVT-ENG left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes

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.

2 participants