Harden Stripe webhook handling and remove exposed Vercel identifiers#360
Harden Stripe webhook handling and remove exposed Vercel identifiers#360Copilot wants to merge 4 commits into
Conversation
|
Supercommit_max.sh |
|
Supercommit_max.sh |
|
Supercommit max.sh |
There was a problem hiding this comment.
Pull request overview
This PR hardens the Flask /api/webhook Stripe endpoint for production use (stricter input/signature validation and safer logging) and removes hardcoded Vercel identifiers from operational tooling by standardizing on environment-driven configuration.
Changes:
- Tightens Stripe webhook handling in
api/index.py(reject empty payloads / missing signature headers, explicit misconfiguration behavior, structured event-type handling, and logging). - Replaces hardcoded Vercel org/project/deployment IDs in scripts/docs with
VERCEL_*environment variables. - Adds developer-facing configuration examples (
.env.example,api/requirements.example.txt) and Stripe webhook unit tests.
Reviewed changes
Copilot reviewed 8 out of 8 changed files in this pull request and generated 1 comment.
Show a summary per file
| File | Description |
|---|---|
| todo.md | Replaces embedded Vercel project ID references with VERCEL_PROJECT_ID placeholders. |
| tests/test_stripe_webhook.py | Adds webhook tests for missing signature header, invalid payload, and supported event types. |
| scripts/fetch_logs.py | Switches log-fetch script to environment-driven Vercel identifiers (token/org/project/deployment). |
| scripts/deploy_vercel.py | Removes hardcoded Vercel IDs and standardizes deployment script on VERCEL_ORG_ID / VERCEL_PROJECT_ID. |
| api/requirements.example.txt | Provides minimal example dependencies for a Flask/Stripe setup. |
| api/index.py | Implements stricter webhook validation, improved logging, and environment-controlled Flask debug mode. |
| .idx/dev.nix | Updates IDX env placeholders to non-sensitive example values for Stripe/Vercel vars. |
| .env.example | Adds a repo-level example env file covering Stripe/Vercel and other runtime variables. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| import json | ||
| import time | ||
| import unittest | ||
| from unittest.mock import patch | ||
|
|
||
| import stripe | ||
|
|
||
| from api.index import app | ||
|
|
||
|
|
||
| def _stripe_signature(secret: str, payload: str, timestamp: int) -> str: | ||
| signed_payload = f"{timestamp}.{payload}" | ||
| signature = stripe.WebhookSignature._compute_signature(signed_payload, secret) | ||
| return f"t={timestamp},v1={signature}" |
|
Pégale esto a Copilot:Estoy en Slack y aparece un mensaje que dice: “Este mensaje contiene elementos interactivos.” |
This change prepares the Flask/Vercel webhook path for production by removing hardcoded secret-related values and tightening Stripe signature validation and event handling. It also replaces exposed Vercel project/org identifiers in operational scripts and docs with environment-driven configuration.
Webhook hardening
Stripe-Signatureheaders with explicit400responses.STRIPE_ENDPOINT_SECRETfrom environment only and warns clearly when the service is misconfigured.payment_intent.succeededpayment_intent.payment_failedcheckout.session.completedcharge.refundedConfiguration cleanup
VERCEL_TOKENVERCEL_PROJECT_IDVERCEL_ORG_IDVERCEL_DEPLOYMENT_IDwhere applicableDeployment/runtime examples
.env.examplewith placeholder values only, including the Stripe/Vercel variables requested.api/requirements.example.txtwith the minimal Flask/Stripe example dependency set.Docs and operational references
Coverage