Transcend Docs

Block unknown requests

Move a site from report-only mode to Block, so airgap.js stops requests and cookies from hosts you have not approved.

After this guide, airgap.js blocks requests and cookies from every host that you have not approved. You can also turn the change off again.

This guide follows Inventory a site in report-only mode. For how the pieces fit together, see the overview. To keep these settings in a file that your team reviews, see Manage consent config as code.

Try it: a runnable example lives in the Airgap security demo in the transcend-io/examples repository.

How airgap.js decides on a requestA page script makes a request. airgap.js checks it against rules from your data flows, the user's consent and your overrides. It then allows the request, rewrites it, holds it until the user opts in, or blocks it because the host is unknown. airgap.js also generates a Content Security Policy (CSP) from the same rules, so the browser blocks hosts outside your data flows even for loads inside CSS and SVG that airgap.js does not see.airgap.js
Generates
Loads inside CSS and SVG
Page scriptMakes a request
Rules
Your data flows
User consent
Your overrides
AllowHas consent, so it is sent
RewriteAn override edits the URL
HoldSent if the user opts in
BlockUnknown host, not sent
Generated Content Security Policy (CSP)The browser blocks hosts outside your data flows, even for loads airgap.js does not see

Block can break a page

A host that is still in Triage counts as unknown. Block stops it, even when it is a tool that your site needs. Approve every host that you need before you deploy to production, and test on a test bundle first.

Before you start

Choose the policies

Two settings decide what happens to something that matches no data flow or cookie rule. Both live in the Advanced Settings tab.

Dashboard optiontranscend.yml valueWhat airgap.js does with unknown requests or cookies
Allow throughALLOWAlways allows them
Allow with full consentREQUIRE_FULL_CONSENTAllows them only when the user consented to every applicable purpose
BlockBLOCKAlways blocks them
  • Unknown Request Policy covers network requests.
  • Unknown Cookie Policy covers cookies.

Picking Block for the request policy also turns on the generated CSP in lax mode. Picking either other option turns the generated CSP off. The generated CSP and Allow through cannot run together: with a CSP on, airgap.js never allows an unknown request.

Move from report-only to Block

  1. Open Consent Management → Data Flows and Consent Management → Cookies. Approve what the site needs, or mark the rest as junk.

  2. In the site's airgap.js tag, remove data-report-only="on". Leave data-monitoring="export" in place if you want to keep checking with airgap.export().

  3. Check the Reporting Only switch in the General tab of Consent Management → Developer Settings. Turn it off. When it is on, the consent manager allows all web requests on your domain.

  4. In Consent Management → Developer Settings → Advanced Settings, set Unknown Request Policy to Block. Set Unknown Cookie Policy to Block.

    The Advanced Settings tab of Developer Settings with Unknown Request Policy and Unknown Cookie Policy set to Block

  5. Select Review Changes & Publish..., pick the Test bundle type, and deploy. Load a staging copy of the site with the test bundle and click through the key flows. See Testing with Test Bundle.

    The Review Changes and Publish modal, where you pick the bundle type to deploy

  6. Deploy to the Production bundle the same way.

To make steps 3 and 4 a reviewed change instead, set both policies in transcend.yml:

consent-manager:
  unknownRequestPolicy: BLOCK
  unknownCookiePolicy: BLOCK

Then preview, push, and deploy to the test bundle. These commands need an API key. See Manage consent config as code for the key, its scopes, and the US API URL.

transcend inventory push --file=./transcend.yml --dryRun
transcend inventory push --file=./transcend.yml
transcend consent update-consent-manager --bundleTypes=TEST --deploy

Set both policies together. In CLI 13.4.0, a push applies the cookie policy only when the file also sets the request policy.

What the generated CSP is

When the request policy is Block, airgap.js adds one Content Security Policy (CSP) to the page. It is a <meta> tag in the <head> with a single default-src directive. It looks like this:

<meta
  http-equiv="Content-Security-Policy"
  content="default-src airgap://test 'self' data: blob: cdn.example-vendor.com *.cdn.example-vendor.com 'unsafe-inline' 'unsafe-eval';"
/>

The hosts in your tag differ. The list holds:

  • 'self', data:, and blob:.
  • The hosts of your approved data flows. Lax mode adds each host's subdomains too.
  • 'unsafe-inline' and 'unsafe-eval', so existing site code keeps working.
  • airgap://test, a marker that airgap.js adds so it can tell its own violations from other CSPs.

Because the rule is default-src, it covers every request type that falls back to it, such as images, styles, and scripts. airgap.js sees most requests at runtime. The CSP is the backstop for requests it does not see directly, such as CSS and SVG subresources.

The generated CSP has limits:

  • It has no rule for navigations or form targets. See Turn on navigation control.
  • It allows inline scripts and eval. It does not replace a nonce-based or hash-based script-src in your header.
  • Browsers ignore some directives in a <meta> CSP, such as frame-ancestors and report-uri. Send those in a header.

For the full list of limits, see the overview.

Choose lax or strict

ModeTag attributeWhat the CSP allowsWhen consent changes
Lax (default)data-csp="allow-known-hosts allow-subdomains"Every host in your data flows, and its subdomainsTakes effect with no page refresh
Strictdata-csp="strict"Only the hosts that the user consented toairgap.js refreshes the page

Start with lax. It blocks hosts that you have never reviewed, and airgap.js still applies consent at runtime.

Use strict when you need the browser to enforce consent as well, for example for CSS and SVG subresources. The dashboard sets lax when you pick Block, so add strict on the tag:

<script
  data-cfasync="false"
  src="https://transcend-cdn.com/cm/<your-bundle-id>/airgap.js"
  data-csp="strict"
></script>

Keep an existing header CSP working

A browser enforces every CSP on a page. A request must pass your header CSP and the generated CSP. Add these hosts to your header:

HostWhy
https://transcend-cdn.comLoads airgap.js and its modules
https://telemetry.transcend.ioTelemetry for EU-hosted organizations
https://telemetry.us.transcend.ioTelemetry for US-hosted organizations
https://cdn.transcend.ioOlder CDN host. Add it if your snippet uses it

For example, a header can name them in script-src and connect-src:

Content-Security-Policy: script-src 'self' https://transcend-cdn.com; connect-src 'self' https://telemetry.transcend.io

Check the Installation tab to see which CDN host your snippet uses. See Integrating with an existing CSP.

Without these hosts, telemetry stops

If your header blocks the telemetry host, new hosts never reach Triage, and you lose the view of what Block stopped.

Turn on navigation control

Navigation control is off by default. Without it, a script on an approved host can still send data away by changing location to another site. The generated CSP has no rule for that.

  1. Add data-regulate-navigation="report-only" to the tag. airgap.js lists navigations in telemetry and changes nothing.
  2. Check Triage for the places users go.
  3. Change the value to on. airgap.js now treats a navigation like a request. It cancels a navigation to an unknown host.
<script
  data-cfasync="false"
  src="https://transcend-cdn.com/cm/<your-bundle-id>/airgap.js"
  data-regulate-navigation="on"
></script>

Most coverage needs the Navigation API. Without it, navigation control covers only form submissions and window.open(). See Navigation control.

See what airgap.js stopped

airgap.js reports hosts to telemetry, so a new host appears in Triage. See Find the hosts in Triage.

The browser reports CSP violations too. airgap.js listens for the browser's securitypolicyviolation event and sends the blocked host to telemetry. It marks the host as a violation only when the generated CSP caused it. A violation from your own header CSP is reported without that mark.

The CSP catches what the runtime does not see, such as a stylesheet that loads an image from an unknown host. In the browser, the Network tab shows no request to a blocked host.

To learn more about what telemetry reports, see Telemetry configuration.

Test that a request is blocked

A blocked fetch never settles

When airgap.js blocks a fetch, the call returns a promise that stays pending. It does not reject. airgap.js resolves it only if the request is allowed later. Code that waits on it waits forever.

In a test, add a timeout. Treat a timeout as "blocked":

const outcome = await Promise.race([
  fetch('https://unapproved.example.com/data').then(() => 'allowed'),
  new Promise((resolve) => setTimeout(() => resolve('blocked'), 3000)),
]);
console.log(outcome); // "blocked"

Roll back

Choose the way that fits how fast you need to act.

Roll back the deployed bundle. Open Consent Management → Developer Settings → Deploy History. Select Rollback under the deployment to restore. Changes that are staged in the Admin Dashboard stay in place. See Rollback airgap bundle versions.

Deploy History, listing each deployment with a Rollback button

Set the policies back to Allow.

  1. In transcend.yml, set both policies to ALLOW. Or set both to Allow through in Advanced Settings.

    consent-manager:
      unknownRequestPolicy: ALLOW
      unknownCookiePolicy: ALLOW
  2. Push the file. Skip this step if you used the dashboard.

    transcend inventory push --file=./transcend.yml
  3. Deploy to the test bundle and then to the production bundle.

    transcend consent update-consent-manager --bundleTypes=TEST --deploy
    transcend consent update-consent-manager --bundleTypes=PRODUCTION --deploy

    In the dashboard, select Review Changes & Publish... and then Deploy Changes.

Setting the request policy to Allow through also turns the generated CSP off.

A push does not deploy

A push stages your change. Visitors see it only after a deploy. Until then, Block stays on.

Report only on one site. Add data-report-only="on" to that site's tag and ship the page. This turns off blocking for that site only.

Next steps

On this page