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.
Two-layer processing
Section titled “Two-layer processing”When you save custom CSS, the server runs two operations in sequence:
-
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.
-
Validation (explicit): Specific policy rules are checked. Violations return HTTP 422 with a structured JSON body listing each
ValidationIssue(code, severity, message, docs URL).
Blocked patterns (silently stripped)
Section titled “Blocked patterns (silently stripped)”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.
| pattern | reason |
|---|---|
expression\s*\( | CSS expression() is IE-only and an XSS vector. |
javascript\s*: | JavaScript URLs are XSS vectors. |
@import\b | External CSS imports leak data and bypass CSP. |
@charset\b | Cannot 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>"). |
Why these are blocked
Section titled “Why these are blocked”expression()andbehavior:— Internet Explorer CSS execution vectors. No modern browser needs them; they can execute JavaScript.javascript:— XSS vector usable in CSSurl()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 inurl().url(...data:(?!image/)...)— Non-imagedata:URIs (e.g.,data:text/html) can carry executable content. Imagedata: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.
Validation rules (returns HTTP 422)
Section titled “Validation rules (returns HTTP 422)”| code | severity | description |
|---|---|---|
css_too_long | error | Custom CSS exceeds 10,000 character limit. |
branding_modification_attempted | error | 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_attempted | error | 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. |
HTTP 422 response shape
Section titled “HTTP 422 response shape”{ "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.
Banner hiding
Section titled “Banner hiding”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:
| Elements | Properties that keep their defaults |
|---|---|
| Every element of the banner, its text included | scale, 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-overlay | display, 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-banner | z-index, filter, contain, pointer-events, backface-visibility |
.ag-banner-inner, .ag-btns, .ag-bar-cats, .ag-bar-cats-header | opacity, transform, filter, contain, pointer-events, backface-visibility |
.ag-btn | opacity, 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, anddisplay: contentson a button (browsers treat it asnoneon buttons);- an
opacityunder 0.5 on.ag-banner(it would still take clicks), andfilter: 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
transformon.ag-banneror a button with ascale()factor under 0.5, or atranslate()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-banner100px or more past the screen’s (negative margins stay free: they centre a banner). To anchor the banner to the right, writeright: 0rather thanleft: 100%with atranslate().
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.
{ "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 }"] }}Size limit
Section titled “Size limit”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.
Unicode normalization
Section titled “Unicode normalization”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).