XSS sinks
innerHTML, eval, document.write, dangerouslySetInnerHTML, v-html, {@html}, Angular sanitizer bypasses and javascript: URLs.
FrontGuard scans React, Vue, Svelte, Angular and plain JS/TS for XSS sinks, leaked secrets, insecure auth and vulnerable dependencies. One command, no account, your code never leaves your machine.
export function Comment({ comment, user }: Props) {
useEffect(() => {
localStorage.setItem('authToken', user.token);
}, [user]);
const preview = document.getElementById('preview')!;
preview.innerHTML = comment.draft;
return (
<article>
<div dangerouslySetInnerHTML={{ __html: comment.body }} />
<a href={`/u/${user.id}?token=${user.token}`}>Profile</a>
</article>
);
}
npx @juliocarneiro/frontguard
✖ 4 issues (4 high) · 1 file scanned
Real output of FrontGuard on these samples.
Five categories, tuned for code that runs in the browser.
innerHTML, eval, document.write, dangerouslySetInnerHTML, v-html, {@html}, Angular sanitizer bypasses and javascript: URLs.
130+ provider token formats, private keys, JWTs and database URLs. Masked in every report, and browser-safe keys are ignored.
Tokens in localStorage, credentials in query strings and hardcoded passwords.
Public source maps, http:// and ws:// resources, third-party scripts without SRI and postMessage to "*".
Exact versions from npm, pnpm, yarn and bun lockfiles, checked against OSV.dev with CVEs and fixed versions.
Try it in ten seconds, then keep it in your workflow.
Nothing to install: npx downloads the package and scans the current directory, exiting with 1 when it finds something serious. Use the full scoped name, shown below.
Installs FrontGuard, creates the config, adds a "security" script and a GitHub Actions workflow. Asks before each step.
Locally, in pre-commit hooks or in CI. Results go to the console, JSON, an HTML dashboard or SARIF.
The npm package is @juliocarneiro/frontguard. There is no unscoped "frontguard" package, so "npx frontguard" only works after FrontGuard is installed in the project; "frontguard" is the name of the command it installs (used by npm run security).
Script blocks in .vue, .svelte, .astro and .html files are analyzed in place, so every finding points at the right line and column.
Stripe publishable keys, Sentry DSNs and Supabase anon keys are made for the browser. FrontGuard does not cry wolf about them.
Secrets are masked in the terminal, JSON, HTML and SARIF output, including the context lines around other findings.
Transitive packages included, dev-only packages detected by walking the dependency graph, and the fix version for each advisory.
Every rule shares a single Babel parse and traversal, ESLint style, so large projects scan in seconds.
Per-rule levels, a "warn" mode that never fails the build, and inline // frontguard-ignore-next-line comments.
Each rule has a stable id, a severity, a CWE mapping and a concrete fix.
no-inner-htmlhighDynamic innerHTML/outerHTML assignmentAssigning a dynamic value to innerHTML or outerHTML parses it as HTML, which executes injected markup and scripts.no-evalcriticalDynamic code executioneval(), new Function() and string arguments to setTimeout/setInterval compile strings as code, turning any injected value into code execution.no-document-writehighdocument.write() calldocument.write() and document.writeln() inject raw HTML into the page and are a classic XSS sink.no-dangerously-set-inner-htmlhighReact dangerouslySetInnerHTMLdangerouslySetInnerHTML bypasses React escaping. Any untrusted data that reaches __html is executed as markup.no-v-htmlhighVue v-html directivev-html renders raw HTML and executes any markup injected into the bound value.no-bypass-security-trustcriticalAngular sanitizer bypassDomSanitizer.bypassSecurityTrust* disables the built-in Angular XSS protection for that value.no-html-sink-callhighDynamic HTML passed to a parsing APIinsertAdjacentHTML, Range.createContextualFragment and setHTMLUnsafe parse their argument as HTML, executing injected markup.no-javascript-urlmediumjavascript: URLjavascript: URLs run code when followed. They are a common XSS vector in href, src and form actions.no-svelte-htmlhighSvelte {@html} tag{@html ...} inserts raw HTML without escaping and executes injected markup.no-open-redirecthighNavigation to a URL taken from the page addressA value read from location.search/hash, URLSearchParams, document.referrer or window.name is used as a navigation target. Attackers craft links that redirect victims to phishing pages, or run code with a javascript: URL (DOM-based XSS).no-dangerous-attributehighCode-executing attribute set from a dynamic valueEvent-handler attributes (onclick, onerror...) are compiled as JavaScript and iframe srcdoc is parsed as a full HTML document, so a dynamic value there executes injected code. URL attributes fed from the page address accept javascript: URLs.no-prototype-pollutionhighPrototype pollution in object mergeA merge/extend/set helper copies attacker-controllable keys onto an object without rejecting "__proto__", "constructor" and "prototype". A payload such as {"__proto__": {...}} then adds properties to every object on the page, which turns into DOM XSS through sanitizers and templating (DOMPurify CVE-2026-41238) or code execution on the server (React2Shell, CVE-2025-55182).no-aws-credentialscriticalAWS credentials exposedAWS access keys or secret keys were found in source code. They grant direct access to AWS services and can lead to full account compromise.no-api-tokenshighAPI key or token exposedA provider API key or token was found hardcoded in source code. Anything bundled into frontend code is readable by every visitor.no-private-keyscriticalPrivate key exposedA private cryptographic key (RSA, EC, DSA, PGP or OpenSSH) was found.no-hardcoded-jwthighHardcoded JWTA JSON Web Token was found in source code. JWTs carry identity claims and are often still valid when leaked.no-connection-stringscriticalDatabase connection string exposedA database URL containing credentials was found in source code.no-high-entropy-stringsmediumHigh-entropy stringA long random-looking string was found. It may be a credential; review it and suppress the finding if it is not.no-secret-in-public-envhighServer secret exposed through a public env variableVariables prefixed with NEXT_PUBLIC_, VITE_, REACT_APP_, NUXT_PUBLIC_, PUBLIC_, EXPO_PUBLIC_... are inlined into the JavaScript sent to the browser. A name like VITE_SUPABASE_SERVICE_ROLE_KEY or NEXT_PUBLIC_STRIPE_SECRET means a server secret is readable by every visitor.no-token-in-web-storagehighAuth token stored in Web StoragelocalStorage and sessionStorage are readable by any script on the page, so a single XSS bug leaks every token stored there.no-token-in-urlhighCredential passed in a URLTokens in query strings end up in browser history, server and proxy logs, and Referer headers.no-hardcoded-credentialscriticalHardcoded credentialA password or secret is assigned as a string literal. Everything in frontend code ships to the browser and can be read by anyone.no-insecure-randommediumMath.random() used for a security valueMath.random() is not cryptographically secure: its output can be predicted from a few samples. Tokens, nonces, OAuth state, PKCE verifiers, salts or passwords generated with it can be guessed.no-insecure-cookiemediumAuth cookie written from JavaScriptA session or token cookie is set through document.cookie. Cookies written by JavaScript can never be httpOnly, so any XSS can read them, and without Secure and SameSite they also travel over plain HTTP and cross-site requests.no-public-sourcemapsmediumPublic source maps in build configPublishing source maps exposes your original source code, comments and internal paths to anyone.no-mixed-contentmediumInsecure http:// or ws:// resourceLoading scripts, data or sockets over plain HTTP/WS lets anyone on the network read or tamper with them, and browsers block it on HTTPS pages.require-srilowThird-party resource without Subresource IntegrityA script or stylesheet is loaded from another origin without an integrity hash. If that host is compromised, its code runs on your page.no-wildcard-postmessagemediumpostMessage with "*" target originpostMessage(data, "*") delivers the message to whatever origin the target window currently has, leaking data to attacker-controlled frames.require-message-origin-checkmediummessage event handler without an origin checkA window "message" listener reads the event without checking event.origin. Any site that can open or frame your page can post messages to it, so the data must be treated as attacker-controlled (DOM XSS, token theft, CSRF-style actions).no-exposed-dev-servermediumDev server protections disabledThe dev server accepts any Host header, any CORS origin or serves files outside the project. Any website you visit can then read your source and files such as .env through your local dev server (DNS rebinding and cross-origin reads, as in the Vite file-read CVEs CVE-2025-30208, CVE-2025-31125 and CVE-2025-24010).no-vulnerable-dependencieshighVulnerable dependencyAn installed package version has a published security advisory (source: OSV.dev).No rule matches this filter.
The SARIF output uses relative paths, stable fingerprints and GitHub security-severity, so alerts are deduplicated across runs and ranked correctly. npm create @juliocarneiro/frontguard writes this workflow for you.
name: FrontGuard
on: [push, pull_request]
permissions:
contents: read
security-events: write
jobs:
scan:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v5
- uses: actions/setup-node@v5
with: { node-version: 22 }
- run: npx --yes @juliocarneiro/frontguard@latest -r console,sarif
- uses: github/codeql-action/upload-sarif@v4
if: ${{ !cancelled() }}
with:
sarif_file: frontguard-report/frontguard-report.sarifimport { defineRule, scan, toSarif } from '@juliocarneiro/frontguard';
const noAlert = defineRule({
meta: {
id: 'ACME-001', name: 'no-alert', title: 'alert() call',
severity: 'low', category: 'misconfig',
description: 'alert() blocks the UI.',
remediation: 'Use the design-system dialog.',
},
create: (context) => ({
CallExpression({ node }) {
if (node.callee.name === 'alert') {
context.report({ line: node.loc.start.line, column: 1 });
}
},
}),
});
const result = await scan({ config: { customRules: [noAlert] } });
await writeFile('report.sarif', toSarif(result));Use FrontGuard as a library, and add rules for your team’s conventions with the same visitor API the built-in rules use.
Free and open source, under the MIT license.
npm create @juliocarneiro/frontguard