Cybersecurity · Work Journal
Why blocking third-party cookies doesn't stop every tracker. How a tracker's script can write a first-party cookie and send its value home, what a 2021 study of 10,000 websites found, and where Content Security Policy helps. With the video, real Chrome tests and a worked example.
Most browsers now block or isolate third-party cookies, or let you turn blocking on. That is a real protection. But it covers one route a tracker can use, not all of them.
In 2021, four researchers looked at 10,000 popular websites. On 97.72% of them they found first-party cookies created by third-party JavaScript. On 57.66% of those sites, at least one such cookie held a unique user identifier that was sent to multiple third parties.
The video above walks through the whole mechanism with animations and real browser tests. This article is the written version: the key code, one worked example, and links to the right minute in the video for each part.
The short version:
- Third-party cookie blocking stops the browser from sending a tracker’s own cookie across websites.
- It does not stop a tracker’s script that runs inside a page from writing a cookie for that website and sending its value in a request.
- Several companies’ scripts on one page can read the same JavaScript-readable cookies.
- Content Security Policy can keep unapproved scripts out. It can’t judge what an approved script does.
Cookies in one minute
HTTP doesn’t remember earlier requests on its own. A cookie fixes that. When you log in to a shop, the server answers with a header like this:
Set-Cookie: session_id=ABC123; Path=/; Secure; HttpOnly
On every later request to the same site, the browser sends it back:
GET /cart HTTP/1.1
Host: furniture-shop.example
Cookie: session_id=ABC123
Secure means the cookie only travels over HTTPS. HttpOnly hides it from JavaScript. Only the server can set HttpOnly. A cookie written with document.cookie can always be read by other JavaScript on the same page, which matters later.
Whether a cookie is first-party or third-party depends only on one thing: the cookie’s domain compared with the website in your address bar.
The route browsers block
Say furniture-shop.example loads a tracking pixel from an advertising company, tracker.example:
<img src="https://tracker.example/pixel">
The tracker answers with Set-Cookie: user_id=XYZ789; SameSite=None; Secure. That cookie belongs to tracker.example, even though you are on the furniture shop. When you later visit bicycle-shop.example, which uses the same pixel, the browser sends user_id=XYZ789 again. The tracker now knows that one browser visited both shops. The shops never had to talk to each other.
How does the tracker know which site the request came from? Either the site adds it (/pixel?site=bicycle-shop), or the Referer header tells it. Under today’s default referrer policy, a cross-site request carries only the origin, such as https://furniture-shop.example/, not the full page path.
This is the route browsers restrict:
| Browser | Default behaviour (checked November 2026) |
|---|---|
| Safari | Blocks third-party cookies (Intelligent Tracking Prevention) |
| Firefox | Blocks known cross-site tracking cookies. Isolates other third-party cookies per website (Total Cookie Protection) |
| Brave | Blocks third-party cookies |
| Chrome | Allows them in normal browsing, unless you turn blocking on. Blocks them in Incognito |
The route they don’t: a tracker writes a first-party cookie
Video: 8:58
Here is the worked example. This time the furniture shop doesn’t use a pixel. It loads a script from the same advertising company:
<script src="https://tracker.example/analytics.js"></script>
The file comes from tracker.example, but it runs inside the furniture shop’s page. A script included like this generally gets the same permissions as the shop’s own code. So it can do this:
document.cookie = "visitor_id=ABC123; path=/";
fetch("https://tracker.example/collect?id=ABC123");
The first line creates a cookie. The browser stores it under furniture-shop.example, because that is the page the script runs in. It is a first-party cookie, and third-party cookie blocking doesn’t apply to it.
The second line sends the value to the tracker in the URL. The browser isn’t attaching a cookie to that request. The script reads the value and sends it itself.
The tests behind the video ran this in Chrome 153, on local test copies of the two fictional shops, with third-party cookies blocked in settings:
- The pixel route was blocked. The tracker’s
Set-Cookiewas rejected, and no cookie reachedtracker.exampleon the second shop. - The script route went through. The browser stored
visitor_id=ABC123underfurniture-shop.example. The tracker’s server log showedGET /collect?id=ABC123with no cookie attached.
Other protections may still stop this, such as tracker blocking in Firefox or Brave, or a content blocker. Third-party cookie blocking alone doesn’t.
One cookie, two companies
Video: 11:06
Now the shop loads scripts from two companies, tracker.example and adnetwork.example. The first one writes tr_uid=ABC123. The second one just reads document.cookie, finds tr_uid=ABC123, and sends it to its own server. The browser doesn’t keep first-party cookies apart by which vendor’s script wrote them. Both scripts run as furniture-shop.example. In the Chrome test, adnetwork.example received /collect?id=ABC123.
There is a limit. On the bicycle shop, the same tracker script writes a different value, XYZ789, into the bicycle shop’s cookies. Neither shop can read the other’s cookies. To know it’s the same person, the tracker needs a link: for example, a matching email-derived identifier when the visitor logs in to both shops, or a shared third-party cookie where those are still allowed.
So first-party cookie tracking collects identifiers within a website. Following someone across websites needs an extra linking step.
What the researchers measured
Video: 13:23
The study is Cookie Swap Party: Abusing First-Party Cookies for Web Tracking by Quan Chen, Panagiotis Ilia, Michalis Polychronakis and Alexandros Kapravelos (The Web Conference 2021). They call these cookies external cookies.
They built a data-flow tracking system on Chromium using dynamic taint analysis. When a script from another domain writes a cookie, the system marks it. It follows the value through later JavaScript, including scripts from other companies. If the value reaches a network request, the system records the flow. This catches flows that you can’t see by inspecting cookies, because the browser’s developer tools show a cookie’s domain, not who wrote it or who received it.
On the Alexa top 10,000, they found that 9,772 sites (97.72%) had external cookies. On 57.66% of those sites, at least one external cookie held a unique identifier sent to multiple third parties.
Two caveats. These numbers describe the web in 2021, not today. And an external cookie isn’t automatically bad: analytics and other legitimate services use the same mechanism. The privacy problem is a unique identifier used to follow people and shared beyond the company that created it.
Can Content Security Policy help?
Video: 17:10
Partly. Take this policy on the furniture shop:
Content-Security-Policy: script-src 'self' https://tracker.example; connect-src 'self' https://tracker.example
- It allows the tracker. Its script runs, and
fetchtotracker.exampleis allowed, so the first-party cookie route still works. CSP can’t tell analytics from tracking. - It blocks the ad network. Chrome refused
adnetwork.example/script2.jswith a console error naming thescript-srcrule. Afetchtoadnetwork.examplewould be blocked byconnect-src. connect-srcisn’t the only exit. A script can send data withnew Image().src = "https://adnetwork.example/collect?id=ABC123". That request falls underimg-src. In the test it went through until the policy addedimg-src 'self'.
I cover building a policy step by step in Content Security Policy for an Online Shop.
What to do if you run a website
- List the third-party scripts on each page and why each one is there. Remove the ones nobody uses.
- Check which cookies each script writes. Clear cookies, load the page with one vendor at a time, and watch the Application panel in DevTools.
- Check where data goes. In the Network panel, search requests for your cookie values to see which hosts receive them.
- Use CSP to keep out scripts you never approved, with
script-src,connect-srcandimg-srcall set. - Tell visitors the truth in your cookie banner. “First-party” doesn’t mean only you use the data.
Sources
- Chen, Ilia, Polychronakis & Kapravelos: Cookie Swap Party: Abusing First-Party Cookies for Web Tracking, The Web Conference 2021
- WebKit: Full Third-Party Cookie Blocking and More
- Mozilla: Enhanced Tracking Protection in Firefox for desktop
- Brave: How do I manage cookies in Brave?
- Google: Delete, allow and manage cookies in Chrome and Next steps for Privacy Sandbox and tracking protections in Chrome
- Chrome for Developers: A new default Referrer-Policy for Chrome