Security Guide
VD3 UI is presentation-layer code, but a few habits keep an app safe. The library is conservative about where it will fetch or render external content — copy the samples below as they are; a stricter CSP than this will blank the theme.
Content Security Policy
useThemePreference / applyPreference writes --vd-radius-scale with element.style.setProperty. A style-src 'self' policy without 'unsafe-inline' blocks that write.
<!-- VD3 UI ships no inline scripts, but theme apply writes an inline custom property.
Allow that write (or theming / radius scale will not apply). -->
<meta http-equiv="Content-Security-Policy"
content="default-src 'self'; img-src 'self' data:; style-src 'self' 'unsafe-inline'; script-src 'self'">Remote data is allow-listed
Vue path: call useSuggest(root) once (see Autocomplete). There is no VdAutocomplete component.
<!-- Marker attribute data-vd-suggest is required.
URL + allowlist alone will not attach the widget. -->
<input
type="text"
class="vd-input"
placeholder="Search…"
data-vd-suggest
data-vd-suggest-url="/api/search"
data-vd-suggest-allowlist="https://api.example.com">Auth UI vs app responsibility
The kit paints login screens and sets autocomplete / reveal / aria-invalid. It does not mint JWTs, set cookies, generate CSRF tokens, talk to Google/GitHub SDKs, or enforce lockout. Pass error / message from the parent; hide CSRF in the #extra slot. Live screens live on Login.
- Kit: visible labels, WHATWG autocomplete tokens, a real
type="button"password reveal,VdAlertfor parent copy. - App: session, CSRF, rate limits, OAuth, captcha vendors, password policy.
Suggest, wired
Static JSON on data-vd-suggest — type “ap” or “ba”:
Treat v-html as a sharp tool
// v-html renders raw HTML — only ever pass trusted, first-party content.
// For anything user-supplied, render text with {{ }} or sanitise first.
// loadSection() (see Lazy loading) injects fetched HTML through sanitizeHtml
// with inline style denied by default. Deferred HTML from Lazy loading goes through the same sanitizer — do not re-inject the response with v-html.
Rich-Text & HTML sanitizer (sanitizeHtml)
sanitizeHtml strips unsafe markup before insertion, keeping a small allowlist of inline formatting tags and restricting <a href> to http:, https:, and mailto:. installSanitizedHtml wires that policy for live DOM nodes via replaceChildren() without assigning untrusted strings to Element.innerHTML.
import {
sanitizeHtml,
installSanitizedHtml,
installTrustedHtml,
} from '@vanduo-oss/vd3';
// 1. Return sanitized markup string (strips scripts, event handlers, inline style, and SVGs by default)
const safeMarkup = sanitizeHtml(dirty, { allowSvg: false, allowStyle: false });
// 2. Live DOM injection via replaceChildren() — never assigns untrusted markup to innerHTML
installSanitizedHtml(el, html, { allowSvg: false, allowStyle: false });
// 3. Explicit opt-out for repository-owned static placeholders (e.g. skeleton/spinner markup)
installTrustedHtml(el, '<div class="vd-skeleton vd-skeleton-text"></div>');Why keep allowStyle: false by default:allowStyle: true applies only a lightweight blocklist heuristic (dropping styles containing url(, expression(, position: fixed|sticky, or CSS backslash escapes) rather than a full CSS parser. Enabling inline styles or calling installTrustedHtml on untrusted strings opens the door to CSS injection and UI redressing (e.g. overlaying fake login prompts or exfiltrating attribute values). Reserve both strictly for trusted, first-party static markup.
| Composable / Component | HTML Sink / Prop | Default Policy |
|---|---|---|
useTooltips | data-tooltip-html | Sanitized via sanitizeHtml (allowStyle: false, allowSvg: false). |
usePopover | data-vd-bubble | Sanitized via sanitizeHtml; opt into inline SVG icons only via data-vd-bubble-allow-svg. |
useToast | title, message | Sanitized via sanitizeHtml (allowStyle: false). |
useLazyLoad | loadSection | Fetched HTML partial is sanitized before DOM insertion (allowStyle: false). |
VdCodeSnippet | highlightCode | Escapes raw source before wrapping token spans. |
Supply-chain & dependency hardening
@vanduo-oss/vd3 ships with a zero-runtime-dependency posture: vue >= 3.3 is its sole peer dependency, and all UI Phosphor icon weights are self-hosted in the package. Text fonts are not bundled — host them yourself, as this site does for the theme-customizer faces — with zero external CDN requests at runtime.
# Install strictly from the committed lockfile
pnpm install --frozen-lockfile
# Gate CI on moderate+ advisories (with narrow, time-boxed dev-only exceptions documented in SECURITY-AUDIT.md)
pnpm audit --audit-level=moderate
pnpm audit --audit-level=moderate --ignore GHSA-vfj7-8cjw-p6xm When an unpatched advisory affects a build-only tool, record it in SECURITY-AUDIT.md with an explicit advisory ID (--ignore GHSA-...), documented devDependencies-only scope, and a mandatory review / expiry date — never blanket-suppress audit gates.
Continuous scanning (Snyk SAST/SCA) & hardened CI
Run Snyk Code (SAST) and Snyk Open Source (SCA) both in CI and directly inside the IDE (via the Snyk extension or MCP server) so DOM sinks, regular-expression hazards, and vulnerable transitive packages are caught before commit. Pair scans with hardened GitHub Actions workflows: set top-level permissions: contents: read and pin every third-party action to a full 40-character commit SHA instead of a mutable tag.
# .github/workflows/ci.yml — least-privilege token + SHA-pinned third-party actions
permissions:
contents: read
jobs:
build-test:
runs-on: ubuntu-latest
timeout-minutes: 15
steps:
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
- uses: pnpm/action-setup@ea17c68df8912ef543352723c149a84f56e3d413 # v6.1.0
with:
version: 10.28.2
- uses: actions/setup-node@949feb2413d6458794dcd2491c4babbbce0c15c1 # v7.1.0
with:
node-version: 24
cache: pnpm
- run: pnpm install --frozen-lockfile
- run: pnpm audit --audit-level=moderate --ignore GHSA-vfj7-8cjw-p6xmDeveloper workstation & AI-assisted coding guardrails
- Endpoint & IDE agent hooks: Run host protection with IDE and AI-agent guardrails (such as Norton / Gen guardrails for Cursor) that inspect file reads and edits, block indirect prompt injection hidden in HTML comments or untrusted test fixtures, and block automatic agent reads of sensitive credential files (
.npmrc,.env, SSH keys). - Token-free local configs: Keep registry publish tokens out of project
.npmrcfiles. Prefer OIDC trusted publishing in CI or short-lived, environment-scoped tokens that never rest on disk in plaintext.
SSR cross-request state isolation
In SSR environments (Nuxt, Vite SSR, Node or Worker isolates), useToast notification queues and useThemePreference state live at module scope and are shared across concurrent requests handled by the same isolate.
- Never enqueue user-specific notifications or mutate module-scoped theme state with per-request user data during server rendering.
- Keep
VanduoVueplugin registration in a.client.tsplugin and pass auth or validation errors as component props (:error/:messageonVdLoginorVdAlert).
Checklist
| Practice | Why |
|---|---|
| Content Security Policy | No inline scripts are required. Theme apply sets --vd-radius-scale as an inline style on <html>, so style-src needs 'unsafe-inline' (or an equivalent exception) or radius theming blanks out. |
| Trusted v-html only | Raw-HTML rendering is reserved for first-party static content. |
| Same-origin remote data | Suggest fetches are restricted to same-origin or an explicit allowlist. The input still needs data-vd-suggest (or data-vd-autocomplete). |
| Sanitized HTML injection | loadSection sanitizes fetched markup before inject. Do not bypass it with v-html of that response. |
| Dependency hygiene | pnpm's strict lockfile + isolated node_modules limit supply-chain risk. |
| No secrets in the bundle | Anything imported into the client is public — keep keys server-side. |
| Auth UI is headless | VdLogin / VdSignUp / VdForgotPassword emit submit and social; they never fetch. Sessions, CSRF tokens, OAuth SDKs, captchas, and lockout timers stay in the app. Credential fields use WHATWG autocomplete tokens — never autocomplete=off. |
| Snyk SAST & SCA scanning | Run Snyk Code (SAST) and Snyk Open Source (SCA) in CI and inside the IDE (Snyk extension / MCP server) to catch DOM sinks, regex issues, and vulnerable dependencies before commit. |
| Pinned CI actions & frozen lockfile | Enforce permissions: contents: read, pin third-party GitHub Actions to full 40-char commit SHAs, and run pnpm install --frozen-lockfile with narrow, time-boxed SECURITY-AUDIT.md exceptions. |
| Workstation & IDE agent guardrails | Pair endpoint protection with IDE/agent hooks (e.g. Norton / Gen guardrails for Cursor) to block indirect prompt injection and automatic reads of .npmrc, .env, or SSH keys; use OIDC trusted publishing instead of static registry tokens. |
| SSR state isolation | useToast queues and useThemePreference live at module scope. Never enqueue user-specific notifications or mutate theme state with per-request data during SSR; register VanduoVue in a .client.ts plugin and pass auth errors via props. |