CKTIS / CSS
CSS security: safe embedding and links
Safe CSS embedding requires control over rules and resource addresses, not just valid syntax. Keep trusted styles separate from user data, and do not treat a link’s appearance or its :visited state as a security guarantee.
Version: CSS modules; structured CSSWG indexes reconciled with pinned MDN BCD; Chromium 152 scope gate, per-example verification still required
Syntax
selector { property: value; }
url("resource")
a:link { color: #0645ad; }
a:visited { color: #663399; }Safe embedding and links (safe embedding and links) involve two separate concerns: which styles you admit into a document and which resources those styles may reference. A recommended trust boundary is an application-controlled static stylesheet with a restricted set of allowed variants rather than arbitrary user-provided rules.
Successful CSS parsing is not security validation. Declarations, strings, and URLs have different syntax; do not treat one escaping function as universal protection. When embedding in HTML, account for the HTML context as well. For user preferences, prefer mapping to predefined classes or values instead of concatenating stylesheet text.
url() identifies a resource rather than ordinary decorative text. Its value can lead to a fetch, depending on the property. In an external stylesheet, relative URLs resolve against the stylesheet URL, not the document URL. Control allowed destinations; a syntactically valid URL does not imply a trusted resource.
:link and :visited distinguish a link’s visitation state, but browsers must protect history privacy and may restrict that distinction. Do not use :visited to discover history or make authorization decisions. Styling a link does not establish that its destination is safe; control navigation destinations separately.
The example uses only fixed declarations and the local fragment #details, without external resources. Its expected text is stable, but visited-link color is not a test assertion. The cited CSSWG documents are changeable editor drafts, not evidence of Chromium 152 support; the example still requires local verification.
Examples
<!doctype html>
<html lang="en">
<meta charset="utf-8">
<title>CSS security example</title>
<style>
.notice { color: #222; background-color: #fff; }
a:link { color: #0645ad; }
a:visited { color: #663399; }
</style>
<p class="notice">Public information only. <a href="#details">Details</a></p>
<p id="details">No external resources are needed.</p>
</html>Result
Public information only. Details No external resources are needed.
The displayed code and declared result were verified in an isolated environment using the method recorded in the verification evidence for this exact version.