Skip to main content
Blog
Blog

Affiliate hijacking and traffic hijacking: how fraud scripts reroute users

Affiliate hijacking is traffic hijacking for commission fraud: browser-side scripts reroute clicks through attacker-controlled affiliate links. Here is how it works and how to stop it.

Jul 10, 2025 5 min read
banner of this article on black and blue background

Have you ever clicked a link and ended up somewhere unexpected? Or maybe you noticed a website acting strangely, sending you to other sites you didn’t ask for? This could be a sign of traffic hijacking.

Let’s break down what this means, how it works, and how you can protect yourself.

2026 update: We refreshed this guide to separate affiliate hijacking from broader traffic hijacking and to show why browser-side redirects can happen even when the server and payment page are clean.

What is affiliate hijacking?

Affiliate hijacking is a form of traffic hijacking where injected JavaScript changes a user's click, outbound link, or session path so it passes through an attacker's affiliate URL before reaching the real destination. The user may still land on the expected site, but attribution and commission credit move to the attacker. Because the redirect is triggered inside the browser, server logs, WAFs, and checkout-only controls often see a normal page request while the revenue theft happens between click and destination.

What is traffic hijacking?

Traffic hijacking is when someone secretly changes where a website’s links go, sending visitors to other sites. Often, for malicious reasons. This is bad for users (who get tricked or exposed to danger) and for website owners (who lose trust and revenue).

We’ve conditioned users to think it’s normal that, when they click “Pay”, the screen flashes and a brand new page loads from a completely different domain.

But this is a massive blind spot and attackers know it.

So if you’re protecting the payment form itself, by validating scripts on that page using cside for example, it makes perfect sense for a bad actor to hijack the click that brings users there instead.

We delve more into this tactic in this January PCI DSS update for SAQ A companies.

This specific tactic is known as clickjacking (simply a strategy of the traffic jacking), and it’s commonly used to impersonate trusted flows.

Types of hijacking at a glance

TermWhat it isWho it harms
Traffic hijackingCode secretly changes where a site's links or navigation send visitorsUsers and site owners
ClickjackingTricks a user into clicking something other than what they see, often via invisible overlaysUsers
Affiliate hijacking (link hijacking)Reroutes a click or session through an attacker's affiliate link to steal a commissionAffiliate programs and site owners
Malicious redirectSends a visitor to a scam or malware page mid-flowUsers and site owners

How does affiliate fraud work?

Affiliate hijacking is the most common form: malicious code forces a user's click or session through an attacker's affiliate link before the real destination loads, so the attacker collects a commission the visitor never meant to generate. More broadly, affiliate fraud is when someone abuses affiliate programs (which pay for clicks or sales) by forcing users through their special links, even if the user never wanted to go there. This is unfair to both the real website and the companies running the affiliate programs.

A common tactic is link hijacking, where a script redirects a user through the attacker’s affiliate link before reaching the final destination. In more sophisticated cases, attackers insert affiliate links dynamically only for certain high-value users, or based on browser signals, making detection harder.

How do these attacks happen? (with simple code snippets)

Attackers use hidden JavaScript on websites.

Here’s how it works, step by step:

1. Detecting your browser

The script first checks what browser you’re using:

// Checks if you are using Chrome, Firefox, Safari, etc.  
function getBrowser() {  
  // ...detects browser type...  
}

2. Replacing download links

It finds all the download links and changes what happens when you click them:

// Finds all download links and changes their behavior  
let links = document.querySelectorAll('a.dlink');  
for (let link of links) {  
  link.setAttribute('href', 'javascript:void(0);');  
  link.addEventListener('click', function () {  
    // Instead of downloading, you get redirected  
    window.open('https://malicious-redirect[.]com', "_blank");  
  });  
}

3. Tracking and limiting redirects

To avoid being too obvious, the script uses cookies to limit how often you get redirected:

function hasCookie() {  
  return document.cookie.includes('wpdlInterval=1');  
}

What does this mean for you?

  • For users: You might end up on scammy or dangerous sites, or your computer could get infected.
  • For website owners: Your visitors lose trust, your reputation suffers, you are in risk of violation of compliance, and you lose out on real revenue.

How can you spot and prevent this?

For users:

  • Be careful with download links, especially on unfamiliar sites.
  • Use a browser extension or ad blocker that warns about suspicious redirects.
  • Keep your browser and antivirus up to date.

For website owners:

  • Regularly scan your site for unknown scripts.
  • Use security plugins and keep your software updated.
  • Set up alerts for unusual traffic patterns.

Final thoughts

Traffic hijacking and affiliate fraud are real threats. By understanding how these attacks work, you can better protect yourself and your website. Stay alert, and always be cautious with unfamiliar links.

For website owners, the defense is browser-layer visibility. Affiliate-hijacking and redirect code only reveals itself at runtime in the browser, so client-side security monitoring that inventories every script and alerts on unauthorized changes to outbound links is what catches it. cside also flags the AI agents and bots that increasingly automate this abuse.

Sign up to get started or book a demo.

Himanshu Anand
Software Engineer

I'm a software engineer and security analyst.

FAQ

Frequently Asked Questions

Affiliate hijacking is a form of affiliate fraud where malicious code on a site forces a user's click or session through an attacker's affiliate link before sending them to the real destination, so the attacker earns a commission the user never intended to generate. It usually runs as injected JavaScript that rewrites download or outbound links, sometimes only for certain users or browser signals to avoid detection.

Yes. Affiliate hijacking can come from a compromised third-party script, a rogue tag manager entry, or a malicious browser extension running on the user's device. In those cases, the server can look clean while JavaScript in the browser rewrites links, opens affiliate redirects, or changes attribution cookies.

Clickjacking tricks a user into clicking something different from what they see, often using invisible overlays. Affiliate hijacking specifically reroutes the click or navigation through an attacker's affiliate link to steal commissions. Clickjacking is a technique; affiliate hijacking is one fraudulent outcome that injected redirect scripts can produce.

An injected script finds outbound or download links and rewrites them, or adds a click listener that first opens the attacker's affiliate URL. It often uses cookies to throttle how often it fires and browser checks to target only certain visitors, which makes the behavior hard to reproduce and nearly invisible to server-side tools.

Because the malicious code runs in the browser, server-side controls miss it. Detect it with client-side monitoring that inventories every script, flags unauthorized changes to outbound or download links, and alerts when code redirects users to unapproved domains. cside monitors scripts at runtime in the browser to catch injected redirect and affiliate-hijacking code before it harms users or revenue.

Monitor and Secure Your Third-Party Scripts

Gain full visibility and control over every script delivered to your users to enhance site security and performance.

Start free, or try Business with a 14-day trial.

cside dashboard interface showing script monitoring and security analytics
Related Articles
Book a demo