Skip to content
Cyber Attacks

Formjacking Explained: How Script Injection Steals Payment Data

Malicious code intercepts transaction details at the browser level before they reach the payment processor, bypassing standard network encryption.

Illustration: A stylized web browser window displays a blank online checkout form with empty input fields.
AI-generated illustration: DataSafe Times
Quick answer

Formjacking occurs when attackers inject malicious JavaScript into web checkout pages. This script captures sensitive data like credit card numbers and CVVs as you type. The stolen information is sent to a remote server before the legitimate payment request completes.

What is formjacking and how does it work?

Formjacking is the practice of injecting malicious JavaScript into a website’s checkout flow to capture payment data. The attacker does not steal the database; instead, they modify the page you see in your browser. When you enter your credit card details, the hidden script copies them and sends them to a third-party server. This happens instantly, often before you even click the submit button.

Where does the malicious code come from?

The malicious script usually enters through a compromised third-party plugin or widget. Many e-commerce sites rely on external services for analytics, reviews, or chat support. If the attacker compromises one of those providers, they can push malicious code to every site that uses that service. You might trust the main website, but you are also trusting every external script it loads.

Why does standard HTTPS encryption not stop this?

HTTPS encrypts data while it travels between your browser and the server. It does not protect data while it sits in your browser’s memory. The formjacking script runs inside your browser, where it has access to unencrypted input fields. It reads the data before the browser packages it into an encrypted packet. Encryption secures the pipe, not the source.

How can developers detect if a site is formjacking?

You cannot detect formjacking simply by looking at the final HTML on your screen. The malicious script often obfuscates its code, making it difficult to read. You must examine the JavaScript source files for suspicious network requests. Look for calls to unfamiliar domains or base64-encoded payloads. This requires manual inspection of the page’s network traffic during a test transaction.

Attack VectorDetection MethodMitigation Strategy
Compromised PluginHash verification of JS filesRemove unused third-party scripts
Direct InjectionContent Security Policy violationsStrict nonce-based script loading
Supply Chain AttackMonitor upstream provider integrityAudit vendor security practices

What is Content Security Policy and why is it the primary defense?

Content Security Policy (CSP) is a browser feature that allows you to declare which sources of content are allowed to load. It prevents scripts from executing if they do not come from a trusted origin. By setting strict CSP headers, you block the malicious JavaScript from running entirely. This stops the data theft at the point of execution.

See also: Warning Signs of Open Redirect Vulnerabilities You Can Spot · Private Browsing Mode: What It Actually Hides and What It Keeps

Can server-side validation prevent formjacking?

Server-side validation checks the data after it arrives at your backend. Formjacking steals the data before it reaches your server. Therefore, server-side checks cannot prevent the theft. They can only help you detect anomalies later, such as mismatched fields. Relying solely on backend validation gives a false sense of security against client-side injection.

How does formjacking relate to session cookie theft?

Both attacks target data in the browser, but they differ in scope. Session cookie theft hijacks an existing login to perform actions on your behalf. Formjacking captures new data as you type it into specific fields. An attacker might use both techniques simultaneously. Stealing the session allows them to view your past orders; formjacking allows them to steal your payment details for future transactions.

What is the hidden cost of fixing formjacking vulnerabilities?

The cost is not just in patching the code. It is in auditing every third-party dependency. Many developers ignore small analytics or chat widgets because they seem harmless. These widgets often have weaker security than the main application. You must treat every external script as a potential entry point. This requires continuous monitoring and strict vendor contracts.

Why do traditional WAFs often miss formjacking attacks?

Web Application Firewalls (WAFs) inspect incoming requests to the server. They look for patterns like SQL injection or command injection. Formjacking scripts often look like legitimate traffic because they mimic standard API calls. The payload is encoded and sent to a different domain, not to your server. Your WAF sees a clean request and allows it through.

How does this compare to MFA fatigue attacks?

MFA fatigue attacks overwhelm users with login prompts until they approve access by mistake. Formjacking does not rely on user error or fatigue. It relies on code execution. One is a social engineering attack targeting the human; the other is a technical exploit targeting the browser environment. Both bypass traditional perimeter defenses, but they require different defensive strategies.

What is the role of Subresource Integrity in this context?

Subresource Integrity (SRI) adds a cryptographic hash to external script tags. The browser checks the downloaded script against this hash. If the script has been altered, the browser refuses to run it. This prevents compromised third-party scripts from executing. It is a critical layer of defense when you cannot control the external provider directly.

How do botnet attacks facilitate formjacking at scale?

Attackers use botnets to distribute the malicious scripts across thousands of sites quickly. A single compromised plugin can infect many victims simultaneously. The botnet infrastructure provides the anonymity and bandwidth needed to receive the stolen data. This scale makes manual detection nearly impossible for individual site owners.

Why are tabletop exercises relevant to formjacking response?

Tabletop exercises simulate security incidents to test your team’s reaction. Practicing a formjacking scenario helps you identify gaps in your monitoring and communication. You might discover that you do not know how to quickly disable a specific third-party widget. Preparation reduces the window of exposure when a real attack occurs.

Can DKIM help prevent formjacking?

DKIM verifies that an email message originated from a specific domain. It protects against email spoofing, not website injection. Formjacking happens on web pages, not in emails. While DKIM is vital for email security, it does not stop malicious JavaScript from running in your browser. Do not confuse email authentication with web application security.

What is the difference between formjacking and callback phishing?

Callback phishing tricks users into calling a fake support number. Formjacking operates silently in the background of a legitimate-looking website. One relies on voice interaction and trust; the other relies on code execution and invisibility. Both aim to harvest credentials, but the vector is entirely different.

Infographic: Formjacking Explained: How Script Injection Steals Payment Data. Malicious scripts execute in the browser, often before network encryption begins. Server-side security alone cannot prevent client-side data interception. Content Security Policy headers restrict where scripts can load fro
Infographic: Formjacking Explained: How Script Injection Steals Payment Data. Free to share with a link to DataSafe Times.

How can you limit the damage if formjacking occurs?

Implement rate limiting on your API endpoints to slow down automated data exfiltration. This does not stop the theft, but it makes it harder for attackers to process large volumes of stolen data quickly. Combine this with strict CSP and SRI to prevent the initial execution. Monitoring for unusual outbound traffic patterns can also alert you to ongoing exfiltration.

Key takeaways

  • Malicious scripts execute in the browser, often before network encryption begins.
  • Server-side security alone cannot prevent client-side data interception.
  • Content Security Policy headers restrict where scripts can load from.
Bottom line

Browser-side encryption cannot stop code running in the browser from reading your input. Enforce strict Content Security Policy and Subresource Integrity headers to block unauthorized script execution.

Frequently asked questions

Does using a virtual credit card stop formjacking?

No, formjacking steals the card number as you type it. The virtual card details are still captured and sent to the attacker’s server immediately.

Can browser extensions detect formjacking?

Some security extensions can flag known malicious domains, but they often miss newly obfuscated scripts or compromised legitimate providers.

Is formjacking the same as skimming?

Skimming usually refers to physical devices on payment terminals. Formjacking is the digital equivalent, occurring entirely in the browser environment.

How long can a formjacking script stay active?

It remains active as long as the compromised script is served by the third-party provider. It can persist for weeks or months until detected.

How this guide was produced: written by the DataSafe Times editorial team with AI assistance, checked against the public references listed below, and reviewed when the facts change. See our editorial policy or report an error.

Further reading

  1. CISA: Cyber Threats and Advisories
  2. UK National Cyber Security Centre
  3. OWASP Foundation
formjackingweb securityjavascript injectionpayment protection

Related stories

Shared AI chat links in search results and their mechanics

Public conversational records index automatically when applications generate predictable Uniform Resource Locators for exported sessions.

Cybersecurity news without the noiseGet Alerts