Core Security Principles
The package requires three types of credentials:- Access Token (required) - Authenticates SDK calls to MercadoPago
- Public Key (optional) - Used for frontend checkout integrations
- Webhook Secret (recommended) - Validates webhook signature authenticity
Webhook Security
Webhook security is critical to prevent fraudulent payment notifications.HMAC Signature Validation
The package validates webhook signatures using HMAC-SHA256 whenMERCADOPAGO_WEBHOOK_SECRET is configured.
Configure webhook secret
Set your webhook secret in Obtain this secret from your MercadoPago dashboard when configuring webhook notifications.
.env:How signature validation works
The The validation requires:
WebhookService validates signatures at src/Services/WebhookService.php:38-60:x-signatureheader with formatv1=hash,ts=timestampx-request-idheaderdata.idparameter (query string or payload)
Webhook Security Best Practices
- Always validate signatures - Configure
MERCADOPAGO_WEBHOOK_SECRETin production - Use HTTPS only - Never expose webhook endpoints over HTTP
- Verify resource existence - Query MercadoPago API to confirm payment status
- Implement idempotency - Handle duplicate webhook deliveries gracefully
- Log failed validations - Monitor for potential security threats
HTTPS Requirements
Why HTTPS Is Required
- Credential protection - Access tokens transmitted in requests must be encrypted
- Webhook security - MercadoPago validates SSL certificates before sending webhooks
- PCI compliance - Payment card industry standards require encrypted transmission
- User trust - Modern browsers warn users about insecure payment forms
HTTPS Configuration Checklist
- Valid SSL certificate installed (not self-signed)
- Certificate covers your domain (including subdomains if needed)
- HTTP to HTTPS redirect configured
- HSTS headers enabled
- Mixed content warnings resolved
- Webhook URL in MercadoPago dashboard uses
https://
Force HTTPS in Laravel
Add toApp\Providers\AppServiceProvider:
Credential Management
Environment Variables
Store all credentials in.env and never commit them:
.env is listed in .gitignore:
Credential Resolution
The package resolves credentials atsrc/Support/EnvCredentialResolver.php:18-34:
The access token is required. The package throws
MercadoPagoConfigurationException if it’s missing.Credential Rotation
When rotating credentials:Secrets Management Services
For production environments, consider using dedicated secrets management:- AWS Secrets Manager
- HashiCorp Vault
- Azure Key Vault
- Google Secret Manager
Demo Routes Protection
How Demo Routes Are Protected
The middleware atsrc/Http/Middleware/EnsureDemoRoutesEnabled.php:18-28 enforces protection:
MERCADOPAGO_ENABLE_DEMO_ROUTES=falseAPP_ENVis notlocalortesting
Production Configuration
Always disable demo routes in production:Custom Controller Security
The package recommends implementing your own controllers with proper security:Authentication
Protect your payment endpoints with Laravel’s authentication:Authorization
Implement authorization policies for payment operations:Input Validation
Always validate user input before creating payments:Rate Limiting
Protect payment endpoints from abuse:Security Recommendations
Production Checklist
Credentials
- Access token stored in environment variables
- Public key stored in environment variables
- Webhook secret configured and validated
- No credentials in version control
- Credentials rotated regularly
Network security
- HTTPS enabled and enforced
- Valid SSL certificate installed
- HTTP to HTTPS redirect configured
- Webhook URL uses HTTPS
- HSTS headers enabled
Application security
- Demo routes disabled (
MERCADOPAGO_ENABLE_DEMO_ROUTES=false) - Custom controllers implement authentication
- Authorization policies configured
- Input validation on all endpoints
- Rate limiting enabled
Webhook security
- Webhook secret configured
- Signature validation active
- Failed validations logged
- Idempotency implemented
- Resource verification before processing
Security Don’ts
❌ Never do this:- Commit credentials to Git
- Share access tokens or webhook secrets
- Expose demo routes in production
- Use HTTP for webhook endpoints
- Skip webhook signature validation
- Trust webhook data without verification
- Store credentials in frontend code
- Use self-signed SSL certificates in production
- Implement payment logic without authentication
- Allow unlimited payment attempts
Security Do’s
✅ Always do this:- Store credentials in environment variables
- Enable HTTPS with valid certificates
- Configure webhook secrets
- Validate webhook signatures
- Disable demo routes in production
- Implement custom controllers with authentication
- Validate all user input
- Apply rate limiting
- Log security events
- Monitor for unusual activity
- Rotate credentials periodically
- Verify payments with MercadoPago API
Incident Response
If you suspect a security incident:Immediate actions
- Revoke compromised credentials immediately in MercadoPago dashboard
- Review recent payment transactions for anomalies
- Check application logs for suspicious activity
- Disable affected endpoints if necessary
Investigation
- Identify the scope of the breach
- Determine which credentials were exposed
- Review access logs and error logs
- Document the timeline of events
Remediation
- Generate new credentials
- Update environment variables
- Deploy configuration changes
- Verify new credentials work correctly
- Monitor for continued suspicious activity
Additional Resources
Production Deployment
Deploy your application to production
Webhook Handling
Process webhook notifications securely
MercadoPago Security
Official MercadoPago security documentation