Heroku PCI Compliance
Your Heroku-hosted payment application can achieve PCI compliance, but you need to understand the shared responsibility model and implement specific architectural patterns. As a Platform-as-a-Service (PaaS), Heroku manages the underlying infrastructure security while you’re responsible for application-level controls and cardholder data protection. This guide walks you through building compliant payment systems on Heroku, from architectural decisions to deployment configurations that satisfy PCI requirements.
Technical Overview
Heroku operates as a managed container platform built on Amazon Web Services infrastructure. Your application runs in dynos (lightweight Linux containers) within Heroku’s multi-tenant environment, with the platform handling OS patching, network security, and physical controls. This abstraction simplifies many infrastructure compliance requirements but shifts critical security responsibilities to your application architecture.
Architecture Considerations
Your Heroku PCI compliance strategy centers on scope reduction through tokenization or validated P2PE solutions. Since you cannot achieve network segmentation in Heroku’s shared environment, every component that touches cardholder data brings your entire application into scope. The platform’s ephemeral filesystem and lack of persistent storage actually work in your favor — they prevent accidental CHD retention in log files or temporary directories.
The defense-in-depth model on Heroku requires:
- Application-level encryption for data in transit (enforced TLS)
- Tokenization at the edge to prevent CHD from entering your environment
- Secure coding practices validated through static and dynamic analysis
- Runtime application self-protection (RASP) or web application firewalls
- Comprehensive logging forwarded to external SIEM platforms
Industry best practices extend beyond PCI to include OWASP Top 10 protections, CIS Controls implementation at the application layer, and adherence to Heroku’s security baseline recommendations. Your architecture should assume zero trust — even within Heroku’s private spaces.
PCI DSS Requirements Addressed
Running payment applications on Heroku affects how you meet several core PCI requirements:
Requirement 1 (Firewall Configuration)
Heroku’s shared responsibility model means you cannot directly configure network firewalls. The platform provides network isolation between applications, but you must implement application-level controls through:
- Web application firewalls (WAF) like Cloudflare or Fastly
- Application-layer access controls
- IP allowlisting through Heroku Private Spaces when handling CHD
Requirement 2 (Default Passwords and Security Parameters)
You must manage:
- Environment variable security for API keys and credentials
- Database connection strings using Heroku’s config vars
- Elimination of default credentials in your application code
- Secure random generation for all application-generated passwords
Requirement 6 (Secure Development)
Heroku deployments require:
- Secure coding standards enforced through CI/CD pipelines
- Automated vulnerability scanning of application dependencies
- Code reviews documented in your version control system
- Change control through Heroku Pipeline promotions
Requirement 8 (Access Control)
Implement multi-factor authentication for:
- Heroku Dashboard access
- CLI authentication using Heroku MFA
- Application-level user authentication
- Database access through secure tunnels
Requirement 10 (Logging and Monitoring)
Configure comprehensive logging:
- Heroku log drains to forward all application logs
- External SIEM integration for log retention and analysis
- Application-level audit trails for CHD access
- Failed authentication attempt monitoring
SAQ Eligibility by Architecture
| Architecture | SAQ Type | Key Requirements |
|---|---|---|
| Frontend redirect to payment gateway | SAQ A | No CHD touches Heroku |
| iFrame or JavaScript from PSP | SAQ A-EP | Proper Content Security Policy |
| API tokenization with vault | SAQ D | Full application security |
| Direct CHD processing | SAQ D | Not recommended on Heroku |
Implementation Guide
Step 1: Environment Configuration
Start by creating a Heroku Private Space if handling any CHD or building SAQ A-EP eligible applications:
“`bash
heroku spaces:create pci-production –team your-team
heroku apps:create your-payment-app –space pci-production
“`
Configure forced TLS for all endpoints:
“`bash
heroku config:set FORCE_SSL=true
“`
Step 2: Application Security Hardening
Implement Content Security Policy headers for SAQ A-EP compliance:
“`javascript
app.use((req, res, next) => {
res.setHeader(‘Content-Security-Policy’,
“frame-ancestors ‘none’; ” +
“form-action ‘self’ https://your-psp.com; ” +
“default-src ‘self'”
);
res.setHeader(‘X-Frame-Options’, ‘DENY’);
res.setHeader(‘X-Content-Type-Options’, ‘nosniff’);
next();
});
“`
Step 3: Tokenization Integration
Integrate tokenization at the edge to keep CHD out of Heroku:
“`javascript
// Client-side tokenization example
const stripe = Stripe(‘your-publishable-key’);
const {token, error} = await stripe.createToken(card);
// Send only the token to your Heroku backend
“`
Step 4: Logging Configuration
Set up comprehensive log draining to external SIEM:
“`bash
heroku drains:add syslog+tls://your-siem.com:514 –app your-app
“`
Configure application-level audit logging:
“`javascript
const auditLog = {
timestamp: new Date().toISOString(),
user: req.user.id,
action: ‘PAYMENT_PROCESSED’,
resource: ‘ORDER_123’,
ip: req.ip,
userAgent: req.headers[‘user-agent’]
};
logger.info(‘AUDIT’, auditLog);
“`
Step 5: Database Encryption
Enable encryption at rest for Heroku Postgres:
“`bash
heroku addons:create heroku-postgresql:professional –app your-app
heroku pg:upgrade ENCRYPTION –app your-app
“`
Implement application-level encryption for sensitive fields:
“`javascript
const crypto = require(‘crypto’);
const algorithm = ‘aes-256-gcm’;
const key = Buffer.from(process.env.ENCRYPTION_KEY, ‘base64’);
function encrypt(text) {
const iv = crypto.randomBytes(16);
const cipher = crypto.createCipheriv(algorithm, key, iv);
// … encryption logic
}
“`
Step 6: Access Control Implementation
Configure Heroku SSO with MFA:
“`bash
heroku access:add security-team@company.com –permissions deploy,operate,manage
heroku spaces:access:add user@company.com –space pci-production –permissions member
“`
Implement application-level RBAC:
“`javascript
const enforceRole = (requiredRole) => {
return (req, res, next) => {
if (req.user.roles.includes(requiredRole)) {
next();
} else {
res.status(403).json({error: ‘Insufficient permissions’});
}
};
};
“`
Testing and Validation
Verifying PCI Requirements
Your testing methodology should mirror QSA assessment procedures:
1. Configuration reviews: Export and review all Heroku configs
“`bash
heroku config –json > config-backup.json
“`
2. Vulnerability scanning: Integrate automated scanning
“`bash
# In your CI/CD pipeline
npm audit –production
snyk test
“`
3. Penetration testing: Include Heroku endpoints in scope
– Test against your custom domain, not herokuapp.com
– Include authorization bypass attempts
– Verify secure headers implementation
Evidence Collection
Maintain these artifacts for your compliance file:
- Heroku configuration exports
- Application security scan results
- Log samples showing proper audit trails
- Network diagrams including CDN and WAF placement
- Pentest reports covering Heroku infrastructure
Automated Monitoring
Set up continuous compliance monitoring:
“`javascript
// Monitor for configuration drift
const requiredConfigs = [‘FORCE_SSL’, ‘NODE_ENV’, ‘LOG_LEVEL’];
const currentConfigs = Object.keys(process.env);
const missing = requiredConfigs.filter(c => !currentConfigs.includes(c));
if (missing.length > 0) {
alertSecurityTeam(`Missing required configs: ${missing}`);
}
“`
Operational Maintenance
Log Review Procedures
Establish daily log review procedures:
- Failed authentication attempts
- Administrative access to Heroku dashboard
- Configuration changes
- Deployment events
- Error rates indicating potential attacks
Change Management
Implement PCI-compliant change control:
1. Use Heroku Pipelines for promotion workflow
2. Require review apps for security testing
3. Document approvals in pull requests
4. Tag releases with compliance annotations
“`bash
Example deployment flow
heroku pipelines:promote –app staging-app –to production-app
git tag -a “v1.2.3-pci” -m “PCI-validated release”
“`
Annual Tasks
Schedule these annual review activities:
- Review and update Heroku team access
- Rotate all API keys and credentials
- Update security contact information
- Review and test incident response procedures
- Validate backup and recovery processes
Troubleshooting
Common Implementation Issues
Issue: Application fails PCI scans due to missing security headers
Solution: Implement headers at application level, not relying on Heroku defaults
“`javascript
app.use(helmet({
contentSecurityPolicy: {
directives: {
defaultSrc: [“‘self'”],
frameSrc: [“‘none'”]
}
}
}));
“`
Issue: Log retention doesn’t meet PCI requirements
Solution: Use external log management with proper retention
“`bash
heroku drains:add https://user:pass@logs.papertrailapp.com:12345/drain
“`
Issue: Database connections expose credentials
Solution: Use Heroku’s automatic credential rotation
“`javascript
const dbUrl = process.env.DATABASE_URL;
// Heroku rotates these automatically
“`
Performance Considerations
Balance security controls with application performance:
- Cache security decisions to avoid repeated auth checks
- Use CDN for static assets to reduce attack surface
- Implement rate limiting at edge, not application
- Monitor dyno metrics during security scans
Legacy System Integration
When connecting Heroku applications to on-premises systems:
- Use Heroku Private Spaces VPN connections
- Implement mutual TLS authentication
- Sanitize data before transmission
- Log all cross-boundary communications
FAQ
Can I achieve SAQ A on Heroku if I use JavaScript-based payment forms?
Yes, but only with proper implementation of payment provider SDKs that tokenize on the client side. Your JavaScript must load directly from the payment provider’s CDN, not from your Heroku application. Implement strict Content Security Policy headers to prevent form tampering.
Do I need a WAF for PCI compliance on Heroku?
While Heroku provides DDoS protection, Requirement 6.6 mandates either code reviews or a WAF for public-facing web applications. Most organizations find WAF implementation through Cloudflare or Fastly more practical than documenting manual code reviews.
How do I handle PCI-compliant backups on Heroku?
Heroku Postgres continuous protection satisfies backup requirements, but you must ensure no CHD exists in your database. Use tokenization to prevent CHD storage, making backup encryption requirements irrelevant for payment data.
What about key management for application-level encryption?
Use Heroku config vars for key storage combined with key rotation procedures. For enhanced security, integrate with external key management services like AWS KMS or HashiCorp Vault through Heroku Private Spaces.
Can I run a payment gateway directly on Heroku?
Technically possible but not recommended due to the shared infrastructure model. Payment gateways require network segmentation and hardware security modules (HSMs) that aren’t available in Heroku’s PaaS environment.
Conclusion
Achieving PCI compliance on Heroku requires embracing platform limitations as security features. Your success depends on tokenization at the edge, comprehensive application security controls, and meticulous logging practices. While you can’t implement traditional network segmentation, Heroku’s immutable infrastructure and forced SSL provide strong security foundations when combined with proper application architecture.
PCICompliance.com gives you everything you need to achieve and maintain pci compliance — our free SAQ Wizard identifies exactly which questionnaire you need based on your Heroku architecture, our ASV scanning service handles your quarterly vulnerability scans including your Heroku-hosted endpoints, and our compliance dashboard tracks your progress year-round. Whether you’re building a new payment system or migrating existing applications to Heroku, start with our free SAQ Wizard to understand your PCI Network Segmentation:, or talk to our compliance team about Heroku-specific implementation strategies.