Skip to content

CSS Sanitizer Rules

The CSS sanitizer has two layers: a silent strip that removes dangerous patterns without error, and a validation layer that returns HTTP 422 for policy violations that must be fixed before saving.

When you save custom CSS, the server runs two operations in sequence:

  1. Sanitization (silent): Dangerous CSS patterns are removed via regex before storage. No error is returned — the offending substring is stripped. The stored CSS is the sanitized version.

  2. Validation (explicit): Specific policy rules are checked. Violations return HTTP 422 with a structured JSON body listing each ValidationIssue (code, severity, message, docs URL).

These patterns are removed from your CSS before storage. If you see your saved CSS is shorter than what you entered, one of these patterns matched.

patternreason
expression\s*\(CSS expression() is IE-only and an XSS vector.
javascript\s*:JavaScript URLs are XSS vectors.
@import\bExternal CSS imports leak data and bypass CSP.
@charset\bCannot change document charset from custom CSS.
behavior\s*:IE legacy behavior property is an XSS vector.
-moz-binding\s*:Firefox legacy XBL binding is an XSS vector.
url\(.*javascript:.*\)javascript: URLs in url() are XSS vectors.
url\(.*data:(?!image/).*\)Non-image data: URIs can carry executable content.
<\s*/?\s*(?:script|style)\b[^>]*>HTML script/style tags (opening or closing, with or without stray whitespace) can break out of the surrounding markup context. Applied REPEATEDLY until the result stops changing, because removing a nested tag can splice its neighbours into a new one ("<scr<script>ipt>").
  • expression() and behavior: — Internet Explorer CSS execution vectors. No modern browser needs them; they can execute JavaScript.
  • javascript: — XSS vector usable in CSS url() values on some older browsers.
  • @import — Loads external stylesheets, bypassing CSP and leaking IP addresses to third-party origins (GDPR concern).
  • @charset — Cannot and should not change the document charset from within custom CSS.
  • -moz-binding — Firefox XBL binding execution, removed from modern Firefox but blocked defensively.
  • url(...javascript:...) — Redundant specific guard for JavaScript URLs in url().
  • url(...data:(?!image/)...) — Non-image data: URIs (e.g., data:text/html) can carry executable content. Image data: URIs (data:image/...) are allowed.
  • <script> and <style> tags — CSS that breaks out of its surrounding markup context via HTML injection. Opening and closing tags are both stripped, including forms with stray whitespace (</ script>), and stripping repeats until the result stops changing so a nested payload cannot reassemble into a live tag.
codeseveritydescription
css_too_longerror Custom CSS exceeds 10,000 character limit.
branding_modification_attemptederror Custom CSS targets protected branding selectors (.ag-branding, .ag-cookie-mark, .ag-bite, .ag-cr1-3). See https://api.kookiok.com/docs/banner-css/branding-policy.
banner_hiding_attemptederror Custom CSS plainly hides the banner, its button row or the Reject all, Accept all or Customize button: display: none (contents on a button), an opacity under 0.5 on .ag-banner or a filter opacity() under 0.5 on a button, a scale() under 0.5 or a translate() of a screen (1000px, 100%), an offset or margin of a screen, an offset pulling the banner's edge 100px past the screen. Only the plainest values are judged. The issue lists each declaration. See https://api.kookiok.com/docs/banner-css/css-sanitizer#banner-hiding.
422 response body
{
"error": "custom_css_validation_failed",
"violations": [
{
"code": "branding_modification_attempted",
"severity": "error",
"message": "Custom CSS targets protected branding selectors (.ag-branding, .ag-cookie-mark, .ag-bite, .ag-cr1-3).",
"docsUrl": "https://api.kookiok.com/docs/banner-css/branding-policy/"
}
]
}

The violations array lists every issue found. Fix each one and retry the save.

Visitors must always see the consent banner and its Reject all, Accept all and Customize buttons: a banner nobody sees collects no valid consent, and hiding Reject all is a dark pattern. Two mechanisms keep custom CSS from hiding them in the most common ways. Neither is a barrier against CSS written to get around them; such CSS breaks the consent rules all the same, and stays your responsibility.

1. What custom CSS cannot change. The banner’s own stylesheet opens with a guard: a cascade layer of !important declarations that comes before everything else. An !important declaration in an earlier layer wins over every later declaration, whatever its specificity, !important flag or layer, so these properties keep their default whatever your CSS says, also inside your @keyframes:

ElementsProperties that keep their defaults
Every element of the banner, its text includedscale, translate, rotate, zoom, offset-path, visibility, content-visibility, clip-path, clip, mask, and content (on ::before and ::after it stays yours)
:host, the root <div> and .ag-overlaydisplay, opacity, transform, filter, backdrop-filter, perspective, will-change, contain, transform-style, animation, transition; the host and the root <div> also keep position and z-index, the overlay its z-index
.ag-bannerz-index, filter, contain, pointer-events, backface-visibility
.ag-banner-inner, .ag-btns, .ag-bar-cats, .ag-bar-cats-headeropacity, transform, filter, contain, pointer-events, backface-visibility
.ag-btnopacity, contain, pointer-events, backface-visibility

A rule setting these properties is saved, and has no effect. For example, * { scale: 0 !important; } leaves the banner exactly as it was. Everything else stays yours to style: colours, fonts, borders, shadows, spacing, layout (display: flex, grid or contents on the containers), position and size of the banner, an entrance animation of your own, hover effects on the buttons. The guard holds on screens only, so a page can still leave the banner out of what it prints.

2. What is refused when you save. Where those properties have legitimate uses, a plain value that would hide something is refused with HTTP 422 and the code banner_hiding_attempted. The check applies to .ag-banner, the containers above and the Reject all, Accept all and Customize buttons:

  • display: none, and display: contents on a button (browsers treat it as none on buttons);
  • an opacity under 0.5 on .ag-banner (it would still take clicks), and filter: opacity() under 0.5 on a button. This holds with an entrance animation of your own too: visitors who ask for reduced motion get no animations, so the banner’s resting state must be visible;
  • a transform on .ag-banner or a button with a scale() factor under 0.5, or a translate() of a screen or more (1000px, 100%, 100vw or 100vh);
  • an offset (top, left, inset, …) or margin of a screen or more, or an offset that pulls an edge of .ag-banner 100px or more past the screen’s (negative margins stay free: they centre a banner). To anchor the banner to the right, write right: 0 rather than left: 100% with a translate().

Only plain values are judged: a number with its unit. A value computed by calc(), var() or another function is saved. Selectors are read the way a browser reads them: div, *, :is(), :where(), :not(), :host(), attribute selectors, escaped names, comments, nested rules and rules inside @media, @supports or @layer all count. A rule counts when it may select one of these elements at some time, for example only on hover or only while the details are expanded. Rules that apply only to print (@media print) are not checked.

422 response body (excerpt)
{
"code": "banner_hiding_attempted",
"severity": "error",
"message": "Custom CSS would hide the consent banner or its Reject all, Accept all or Customize button: #ag-reject-all { display: none }. ...",
"docsUrl": "https://api.kookiok.com/docs/banner-css/css-sanitizer#banner-hiding",
"context": { "rules": ["#ag-reject-all { display: none }"] }
}

Custom CSS is capped at 10,000 characters. This applies to the raw input (before sanitization). If you need more space, consider:

  • Moving shared styles into your host page’s CSS (they won’t affect the banner directly, but fonts loaded on the host page are available via --font-family).
  • Using token overrides instead of verbose class-by-class rules.

Before pattern matching, the sanitizer runs NFKC normalization (full-width → half-width character mapping). This prevents bypasses using Unicode lookalikes such as expression() (full-width e).