Safeguard
Security Guides•

Is a data layer a sandbox for marketing tags?

A data layer limits what you hand to tags, which helps privacy, but it will not stop a tag running code on the page. What it does and what isolates.

Safeguard Security Team
3 min read

No. A data layer is a structured object your page fills with the values tags may use, which helps you control what data is shared. OWASP states plainly that a data layer is not a sandbox, because remotely managed event handlers remain part of the page's trust boundary.

Definitions

Data layer: a JavaScript object on your page, defined by you, holding values such as page type or product category that tags read.

Sandbox: a boundary that stops code inside from reaching what is outside, such as the page content and cookies.

Trust boundary: the line around code you rely on. Anything inside it can affect your page.

What a data layer is good for

OWASP recommends a host defined data layer that limits what data is collected. The value is in minimisation. Instead of letting every tag scrape the page, you publish a short list of approved fields. Tags read from that list. If a field is not in the data layer, a well behaved tag has no reason to have it.

That helps with privacy reviews, with analytics quality, and with answering the question what do our vendors get.

What it cannot do

A tag running on your page is still JavaScript in your page. Remote event handlers managed from a vendor console can fire code on clicks and form events. A script that wants more than the data layer offers can read the document, cookies not marked HttpOnly, and form fields. The data layer politely offers the right data and cannot prevent the wrong data being taken.

Related: Google Tag Manager's built in click and form variables, such as Click Text and Form Text, read from the page. See what built-in tag variables can capture.

What does isolate scripts

ControlWhat it does
Cross domain iframeOWASP says vendor code will not have direct access to the page DOM and cookies
Iframe sandbox attributeRestricts what the framed content may do
Subresource IntegrityRuns only the code that was reviewed, with a hash
Content Security PolicyLimits where scripts load from and send data to
Server side collectionMoves eligible tags out of the browser

OWASP names these, and notes that for high risk applications CSP is worth adding on top of iframe sandboxing. For the iframe attribute detail, see which iframe sandbox tokens to allow.

A practical design

  1. Write down the fields tags need, and name each field's purpose.
  2. Push only those fields into the data layer.
  3. Keep identifiers, emails and free text out of it.
  4. Put high risk vendors in a cross domain iframe where the vendor supports it.
  5. Review the data layer spec whenever a new tag is added.

Try it yourself

Click through it at your own pace, or open it full screen. Look at how change is surfaced after the fact, since a data layer spec only helps if drift is noticed.

Quick check

Does a data layer hide cookies from tags?

No. It controls what you publish to tags, and does not block a script from reading the page.

Is it still worth having?

Yes. It reduces what you share on purpose and gives reviewers one list to check.

Sources

Last reviewed: 19 October 2026.

Never miss an update

Weekly insights on software supply chain security, delivered to your inbox.

Self-healing security runs on Safeguard.

Your first fix PR is minutes away.

No sales call required, even your agent can complete the purchase over MCP.