javascript-typescript-vue-web-frontend-security

This document is designed as a security spec that supports:

Vue.js Web Security Spec (Vue 3.x, TypeScript/JavaScript, common tooling: Vite)

This document is designed as a security spec that supports:

  1. Secure-by-default code generation for new Vue code.
  2. Security review / vulnerability hunting in existing Vue code (passive “notice issues while working” and active “scan the repo and report findings”).

It is intentionally written as a set of normative requirements (“MUST/SHOULD/MAY”) plus audit rules (what bad patterns look like, how to detect them, and how to fix/mitigate them).


0) Safety, boundaries, and anti-abuse constraints (MUST FOLLOW)


1) Operating modes

1.1 Generation mode (default)

When asked to write new Vue code or modify existing code:

1.2 Passive review mode (always on while editing)

While working anywhere in a Vue repo (even if the user did not ask for a security scan):

1.3 Active audit mode (explicit scan request)

When the user asks to “scan”, “audit”, or “hunt for vulns”:

Recommended audit order:

  1. Build/deploy entrypoints and hosting config (Docker, CI, static hosting, SSR server).
  2. Secrets exposure (env usage, .env*, hard-coded keys). ([vitejs][2])
  3. XSS surface: templates, v-html / innerHTML, URL/style injection, DOM APIs. ([Vue.js][1])
  4. Auth/session handling in the browser (token storage, credentialed requests, CSRF integration). ([Vue.js][1])
  5. Routing/navigation (open redirects, “return_to/next”, unsafe external navigation). ([Vue.js][1])
  6. Third-party scripts and content (CDN assets, analytics, widgets, iframes). ([Vue.js][1])
  7. Security headers and browser hardening expectations (CSP, clickjacking). ([Vue.js][1])
  8. SSR-specific concerns (state serialization, template boundaries) when applicable. ([Vue.js][1])

2) Definitions and review guidance

2.1 Untrusted input (treat as attacker-controlled unless proven otherwise)

In a Vue app, untrusted input includes (non-exhaustive):

2.2 State-changing action (frontend perspective)

An action is state-changing if it can:

2.3 Required audit finding format

For each issue found, output:


3) Secure baseline: minimum production configuration (MUST in production)

This is the smallest “production baseline” that prevents common Vue/front-end misconfigurations.


4) Rules (generation + audit)

Each rule contains: required practice, insecure patterns, detection hints, and remediation.

VUE-DEPLOY-001: Do not run dev/preview servers in production

Severity: High

Required:

Insecure patterns:

Detection hints:

Fix:

Notes:


VUE-DEPLOY-002: Use Vue production builds and keep devtools off in production

Severity: Medium (High if production devtools/debug hooks are enabled)

Required:

Insecure patterns:

Detection hints:

Fix:


VUE-SECRETS-001: Never ship secrets in frontend code or env variables

Severity: High (Critical if real credentials are exposed)

Required:

Insecure patterns:

Detection hints:

Fix:

Notes:


VUE-SECRETS-002: Do not broaden Vite env exposure

Severity: High

Required:

Insecure patterns:

Detection hints:

Fix:

Notes:


VUE-XSS-001: Prefer Vue’s default escaping; avoid raw HTML injection

Severity: High

Required:

unless the HTML is trusted or robustly sanitized and the risk is explicitly accepted. ([Vue.js][1])

Insecure patterns:

Detection hints:

Fix:

Notes:


VUE-XSS-002: Never use non-trusted templates (client-side template/code injection)

Severity: Critical

Required:

Insecure patterns:

Detection hints:

Fix:


VUE-XSS-003: Do not mount Vue onto DOM that may contain user-provided server-rendered HTML

Severity: Medium

Required:

Insecure patterns:

Detection hints:

Fix:


VUE-XSS-004: Prevent URL injection in bindings and navigations

Severity: High

Required:

Insecure patterns:

Detection hints:

Fix:


VUE-XSS-005: Prevent style/CSS injection and UI redress

Severity: Low

Required:

Insecure patterns:

Detection hints:

Fix:


VUE-XSS-006: Never bind user-provided JavaScript into event handler attributes

Severity: Critical

Required:

Insecure patterns:

Detection hints:

Fix:


VUE-ROUTER-001: Do not treat client-side route guards as authorization

Severity: High

Required:

Insecure patterns:

Detection hints:

Fix:


VUE-ROUTER-002: Prevent open redirects and unsafe “return_to/next” handling

Severity: Low

Required:

Insecure patterns:

Detection hints:

Fix:

Notes:


VUE-AUTH-001: Token storage must assume XSS is possible

Severity: Low

Required:

Insecure patterns:

Detection hints:

Fix:


VUE-CSRF-001: Coordinate with the backend for CSRF when using cookies

Severity: High (for cookie-authenticated state-changing requests)

NOTE: If the application is not using cookie based authentication (for example if it passes an Authorization header), then CSRF is not a concern

Required:

Insecure patterns:

Detection hints:

Fix:

Notes:


VUE-HTTP-001: Do not put secrets in URLs; avoid leaking sensitive data in navigation/logs

Severity: Medium

Required:

Insecure patterns:

Detection hints:

Fix:


VUE-HEADERS-001: Require security headers at the deployment layer

Severity: Medium

Required:

Insecure patterns:

Detection hints:

Fix:


VUE-CSP-001: Use Trusted Types and DOM XSS hardening when feasible

Severity: Low

Required:

Insecure patterns:

Detection hints:

Fix:


VUE-THIRDPARTY-001: Avoid dynamic third-party script injection; prefer static, vetted loading

Severity: Low

Required:

Insecure patterns:

Detection hints:

Fix:


VUE-SRI-001: Use Subresource Integrity for CDN-hosted scripts/styles

Severity: Low

Required:

Insecure patterns:

Detection hints:

Fix:


VUE-SUPPLY-001: Dependency and patch hygiene is mandatory

Severity: Low

Required:

Insecure patterns:

Detection hints:

Fix:


VUE-SSR-001: SSR adds additional trust boundaries; treat state injection as XSS-sensitive

Severity: Medium

Required:

Insecure patterns:

Detection hints:

Fix:


5) Practical scanning heuristics (how to “hunt”)

When actively scanning, use these high-signal patterns:

Always try to confirm:


6) Sources (accessed 2026-01-27)

Primary Vue documentation:

Vite documentation (common Vue tooling):

OWASP and web platform hardening references:

Browser/platform references:

[1]: https://vuejs.org/guide/best-practices/security "https://vuejs.org/guide/best-practices/security" [2]: https://vite.dev/guide/env-and-mode "https://vite.dev/guide/env-and-mode" [3]: https://vuejs.org/guide/best-practices/production-deployment "https://vuejs.org/guide/best-practices/production-deployment" [4]: https://cheatsheetseries.owasp.org/cheatsheets/HTTP_Headers_Cheat_Sheet.html "https://cheatsheetseries.owasp.org/cheatsheets/HTTP_Headers_Cheat_Sheet.html" [5]: https://vite.dev/guide/cli "https://vite.dev/guide/cli" [6]: https://vite.dev/guide/build "https://vite.dev/guide/build" [7]: https://vuejs.org/guide/best-practices/production-deployment?utm_source=chatgpt.com "Production Deployment" [8]: https://cheatsheetseries.owasp.org/cheatsheets/Authorization_Cheat_Sheet.html "https://cheatsheetseries.owasp.org/cheatsheets/Authorization_Cheat_Sheet.html" [9]: https://cheatsheetseries.owasp.org/cheatsheets/Cross-Site_Request_Forgery_Prevention_Cheat_Sheet.html "https://cheatsheetseries.owasp.org/cheatsheets/Cross-Site_Request_Forgery_Prevention_Cheat_Sheet.html" [10]: https://web.dev/articles/trusted-types "https://web.dev/articles/trusted-types" [11]: https://developer.mozilla.org/en-US/docs/Web/Security/Defenses/Subresource_Integrity?utm_source=chatgpt.com "Subresource Integrity - Security - MDN Web Docs" [12]: https://developer.mozilla.org/en-US/docs/Web/HTML/Reference/Attributes/rel/noopener "https://developer.mozilla.org/en-US/docs/Web/HTML/Reference/Attributes/rel/noopener" [13]: https://vuejs.org/guide/essentials/template-syntax "Template Syntax | Vue.js" [14]: https://vite.dev/config/server-options "https://vite.dev/config/server-options"