Gradient glow shape

Can iFrames Place Cookies on Your Site Without User Consent?

By Josh Manion, CEO, Vault JS | December 3, 2022

Person looking at picture frames

Key Takeaways

  • iFrames embed external content on your site that operates independently from your consent management tools. Any domain loaded through an iframe can introduce its own cookies, and because the code within the frame runs outside your site’s control, your cookie consent settings cannot restrict what the external domain places on a visitor’s device.
  • A visitor who opts out of non-essential cookies on your site can still receive them through an iframe. If the third-party domain embedded in the frame cannot detect or does not honor the visitor’s opt-out, it can load tracking and analytics cookies without permission, potentially putting your site out of compliance with data protection laws and creating liability for your organization.
  • The sandbox attribute and periodic audits reduce but do not eliminate iframe risk. Most developers do not consistently implement sandbox restrictions, and some cookies can bypass even a partially restricted frame. Only continuous, site-wide monitoring can detect when unpermitted cookies have been placed through iframes and gone unnoticed for weeks or months.

If your site streams video or audio content, displays social feeds, serves up dynamic maps, news, ads or data, then it likely uses iframes. Most enterprise websites do. And while these bits of code can enhance the overall user experience, they can also open your company to significant risks.

What is an iFrame?

An iframe, short for inline frame, is a piece of HTML code that displays content from an external source on your webpage. The content displayed within an iframe is hosted elsewhere but is served up right alongside your own site’s material. For example, one common use of iframes is to embed YouTube videos on an independent page. That code may look like something like this:

<iframe src=“https://www.youtube.com/embed/abc123”></iframe>

The iframe above is essentially a window on your site to YouTube. Visitors will be able to view and interact with the video on that platform without leaving your page. The frames can be customized — you can specify height and width attributes, or add a title to provide alternative text that will be compatible with screen readers — but the simplest iframe can function with only a source link.

Why Do Enterprise Websites Use iFrames?

iFrames both simplify the responsibilities of a website manager and enhance the user experience. both simplify the responsibilities of a website manager and enhance the user experience. Since the code and content within the frame are hosted elsewhere, the work and cost of maintaining them do not fall to the primary website. In the YouTube example, your company will not have to write original code to create your own video player, worry about hosting the video on your own servers, or keep associated software up to date. YouTube’s team handles all of that. Your team only needs to place the iframe.

From a user experience standpoint, iframes allow your site to include interactive and diverse content delivered in specialized ways. Plus, iframes keep customers on your site. Instead of sending customers to watch a video on YouTube.com — an uncontrolled environment where they may become distracted — you can display the video on your own page by deploying an iframe. This ensures that your visitors remain focused on viewing only the content you want them to see, in the context you want them to experience

What Security Risks Do iFrames Create?

While keeping the primary host site and the external content separate has definite benefits, it also creates risks as the host site has limited control over what happens inside an iframe. The iframe essentially loads another web page inside of your host page, introducing new code that your website team did not write or approve. This foreign code can harm your site in several ways:

Malicious Code
In extreme cases, the embedded content can contain intentionally harmful code designed to steal customer data, upload malware, or otherwise sabotage the host site and the user.

Phishing Operations
If the external site’s security is compromised, attackers can imitate a legitimate site and redirect customers to a less safe domain. Customers who believe they are interacting with a trusted source can be enticed into entering personal information into unsafe forms or clicking dangerous third-party links.

Impaired Site Performance
Loading embedded content takes time and computing energy. While not a direct security threat, sites with many iframes can experience slower load times that frustrate and deter users.

You and your site management team can reduce these risks by only embedding content from known and trusted sources with thorough security protocols. Furthermore, iframes should be used selectively and, if appropriate, loading should be delayed when off-screen.

How Do iFrames Bypass Your Cookie Consent Management?

Your enterprise website most likely allows users to opt out of non-essential cookies and then limits what cookies it places itself. With this cookie compliance management in place, you might assume that you have fulfilled your responsibilities to your customers.

However, any domain embedded in a web page by an iframe can introduce its own set of cookies in addition to those placed by the host site. The cookies which iframes introduce are not usually inherently dangerous, but even harmless cookies placed by independent domains can bypass consent management tools and gain access to more data than the visitor has permitted. Since the code within an iframe operates independently, your site cannot restrict what kinds of cookies the external domain can place.

If the third-party domain is unable to detect that your visitor has opted out of some cookies, or if it chooses not to abide by the restrictions of that opt-out, it can load its own non-essential cookies without permission. A basic iframe will not be able to block them.

When a third party loads these non-essential cookies through your iframe, your site may fall out of compliance with data protection laws and your enterprise may be held liable for mishandling visitors’ information.

How Can You Detect and Prevent Unpermitted Cookies from iFrames?

To minimize security risks, your site developers can add the sandbox attribute to their iframe code to limit the iframe’s control over the page, broadly preventing the frame from initiating popups, downloads, URL changes, or other concerning events. This can also help in restricting cookies. Most developers, however, do not consistently implement such restrictions and some cookies can slip through even a partially restricted iframe. Once placed, these cookies can go undetected for weeks or months.

The only way to know for sure that no unpermitted cookies have been placed is to run a site-wide cookie consent audit. This will help identify instances where unrestricted iframes have led to negligent consent management.

A Digital Marketing Assurance Platform (DMAP) can be a critical tool in addressing the challenges that iframes pose. As the liabilities around visitor privacy continue to grow, the attacks and unpermitted cookies that iframes leave your site vulnerable to become more pressing risks. By actively monitoring consent management configurations, vendor security and the dissemination of customer data, enterprises can immediately identify security issues and protect against these liabilities. To learn more, visit VaultJS.com.

Josh Manion

Josh Manion
CEO and Co-Founder, Vault JS

Before founding Vault JS, he created and led Ensighten, pioneering the tag management category and earning patents for innovations in how third-party JavaScript is managed on enterprise websites. That close-up view of the security and privacy risks embedded in the Martech ecosystem led directly to the creation of Vault JS.

See if your organization's privacy compliance is putting you at risk.