frontend-security
Skill22 starsChanged 5 months agoMITView on GitHub
Browser-side hardening: XSS and safe text binding, per-sink URL policy, DOM clobbering, nonce-based CSP, Trusted Types, subresource integrity, iframe capability minimization, postMessage validation, and where client state may live. Use when generating HTML, JSX, Vue, or Svelte templates, setting response headers in a web app, embedding third-party scripts or frames, or storing anything client-side.
2 other projects use a version of this.
Adopted by
Most recently taken up by
- ZeroTokenClaw/agents-skillstheir own version, first seen Sep 21, 2026
- Rootx202/appsec-skillstheir own version, first seen Jul 13, 2026
Other versions2 projects use a version of this.
Word for word · 0
None found.
Edited · 0
None found.
Wrote their own version · 2
- Rootx202/appsec-skills★ 3same name
- ZeroTokenClaw/agents-skills★ 1same name
How matches are found. Word for word: the exact same text. Edited: shares passages with this file (“99% same” means 99% of its five-word phrases also appear here; 10% or more counts). Their own version: similar meaning, or, weakest, the same name. We can’t tell which project had it first. Projects are counted among the 200 most-starred candidates, and mentions are links to the repository we found, up to 50 per site, so both counts are a floor.
In this repository36 other files it gives its agents.
- AGENTS.mdAGENTS.md
- dist/AGENTS.mdAGENTS.md
- dist/CLAUDE.mdCLAUDE.md
- dist/copilot-instructions.mdCopilot instructions
- docs/llms-full.txtllms.txt
- docs/llms.txtllms.txt
- api-securitySkill
- auth-securitySkill
- cicd-securitySkill
- container-securitySkill
- cors-securitySkill
- crypto-misuseSkill
- database-securitySkill
- deserialization-securitySkill
- dynamic-verificationSkill
- electron-securitySkill
- error-handling-securitySkill
- file-upload-securitySkill
- graphql-securitySkill
- iac-securitySkill
- iam-best-practicesSkill
- llm-app-securitySkill
- logging-securitySkill
- ml-securitySkill
- mobile-securitySkill
- protocol-securitySkill
- saas-securitySkill
- secret-detectionSkill
- secure-code-reviewSkill
- security-regression-testsSkill
- serverless-securitySkill
- ssrf-preventionSkill
- supply-chain-securitySkill
- template-injectionSkill
- threat-modelingSkill
- websocket-securitySkill
The file
We split this skill into the rules it gives an agent
6 rules. About 0 are common, 0 are distinctive, and 6 are very specific to this project.
≈0
Common · estimate
Many files like this have a rule of this kind.
≈0
Distinctive · estimate
This author's own choices. Worth a look.
6
Very specific
Tied to their project's names, files or tools. Probably skip.
- Common
- Distinctive
- Very specific
- Very specific: line 46
Read security-sensitive configuration and control-flow values from lexical variables or an object you own — never from a named window / …
- Very specific: line 89
Keep authentication secrets out of JavaScript-readable storage — no access tokens, refresh tokens, JWTs, or sensitive personal or business …
- Very specific: line 99
Use dangerouslySetInnerHTML, v-html, {@html …}, innerHTML =, or document.write with untrusted input.
- Very specific: line 101
Use eval, new Function, setTimeout(string), or setInterval(string).
- Very specific: line 102
Read or write document.cookie from JavaScript for an auth cookie — it should be HttpOnly, which means JavaScript cannot see it and code …
- Very specific: line 105
Treat tightening the HTML sanitizer as the fix when the exploit rides on content the sanitizer allows by design — a valid link, an <img …
≈ “Common” is an estimate: at least 1 in 5 of the 213,895 skill files we read have a rule of the same kind, not the same words. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.
Files
Frontend Security
Rules (for AI agents)
ALWAYS
- Render untrusted data through the framework's ordinary text interpolation, which escapes for the output context. Do not reach for a raw-HTML API merely to display user data. Where rich HTML genuinely must be rendered, put it through a maintained sanitizer (DOMPurify) with an explicit allowlist first.
- Validate URL-bearing attributes per sink, not against one global scheme list. A
navigation target (
href,action,formaction, an<iframe src>) and an image source do not share a trust model:javascript:is never acceptable anywhere, while a narrowly constraineddata:image/…orblob:may be exactly what an image sink requires. Decide the permitted schemes for each sink and check against that list. - Read security-sensitive configuration and control-flow values from lexical variables
or an object you own — never from a named
window/documentproperty (window.config,document.redirectTo, an implicit global). The browser exposes elements byidandnameas named properties, so injected markup can shadow the value your code expected. An explicitgetElementById()lookup is not the problem; trusting an ambient global is. Type-check what you read before using it in a privileged way. - Build the
Content-Security-Policyaround a nonce or hash as the trust root:script-src 'nonce-{value}' 'strict-dynamic'; object-src 'none'; base-uri 'none'. Keeping'self'beside the nonce means every same-origin script is still trusted — that is a host-allowlist policy wearing a nonce, which may be the right trade-off but is not a strict CSP, so do not call it one. Generate the nonce from a CSPRNG afresh for every HTML response, and apply it only to scripts the server itself authorizes. - Where you deploy Trusted Types, enforce
require-trusted-types-for 'script'and restrict which policies may exist with thetrusted-typesdirective. The first makes DOM sinks demand a typed value; without the second, any code can mint a pass-through policy (createHTML: s => s) and the guarantee is gone. Keep policies few, named, and centrally reviewed. - Load third-party scripts and stylesheets from version-pinned, immutable URLs
with
integrity="sha384-…"andcrossorigin="anonymous". A hash pinned against a mutable URL breaks the page the first time the provider ships a legitimate update, which is how integrity checks come to be quietly deleted. If a provider cannot offer stable bytes with CORS, self-host rather than drop SRI. - Sandbox every
<iframe>, starting from no capability tokens and adding only what the embedded content needs. Do not combineallow-scriptswithallow-same-origin: together they let the framed document reach the parent and remove its ownsandboxattribute, so the sandbox stops meaning anything. If the content genuinely needs both, isolate it on a separate origin instead. - On
postMessage, name an explicittargetOriginwhen sending — never*— and on receipt verifyevent.originagainst an allowlist, validate the message's shape before reading any field, and where the channel expects one particular frame, checkevent.sourceas well. Origin, schema and sender are three separate checks. - Set
X-Content-Type-Options: nosniff,Referrer-Policy: strict-origin-when-cross-originor stricter,Permissions-Policydropping unused features, andCross-Origin-Opener-Policy: same-originto sever the opener relationship at the document level. Remove framework version banners here too (X-Powered-By, a detailedServer). Note thatno-referrer-when-downgradeis weaker than the current browser default — configuring it is a step backwards. - Send HSTS on production HTTPS. Add
includeSubDomainsonly after confirming every subdomain serves HTTPS, andpreloadonly as a deliberate, hard-to-reverse commitment for the registrable domain: the token makes a domain eligible for the preload list, it does not enrol it, and reversing it is slow. - Keep authentication secrets out of JavaScript-readable storage — no access tokens,
refresh tokens, JWTs, or sensitive personal or business data in
localStorageorsessionStorage, where a single XSS reads all of it — and clear authenticated client-side state on logout. Server-issued session cookies are the alternative:Secure,HttpOnly, an application-appropriateSameSite, and the__Host-prefix for host-only cookies atPath=/.auth-securityowns issuing them; this rule exists so a frontend review recognises an auth value that has escaped into JavaScript's reach.
NEVER
- Use
dangerouslySetInnerHTML,v-html,{@html …},innerHTML =, ordocument.writewith untrusted input. - Use
eval,new Function,setTimeout(string), orsetInterval(string). - Read or write
document.cookiefrom JavaScript for an auth cookie — it should beHttpOnly, which means JavaScript cannot see it and code that does is reaching for a cookie that was never hardened. - Treat tightening the HTML sanitizer as the fix when the exploit rides on content
the sanitizer allows by design — a valid link, an
<img src>, a permitted attribute. The sanitizer is working. The vulnerable behaviour is downstream, where some sink turns that allowed value into a navigation, a command, or a native capability. Fix the sink and reduce its authority.
KNOWN FALSE POSITIVES
- Internal admin tools rendering Markdown or rich text from trusted authors may use a raw-HTML API after a sanitizer pass; document the sanitizer call inline.
- A deliberately sandboxed browser-extension page may use a more permissive CSP
for code that needs eval-like behaviour, provided it stays isolated from the
extension APIs. That is not a licence to add
'unsafe-eval'to MV3extension_pages— Chrome rejects that policy outright, and WebAssembly has its own'wasm-unsafe-eval'token. - A WebSocket to a non-same-origin endpoint where the server validates
Origin. - A native or WASM decoder that is merely registered or configured is not yet an attack surface. Before flagging one, establish a reachable runtime path from untrusted input to that decoder — including an implementation fetched lazily at runtime, which does not have to be in the shipped bundle to be reachable.
Context (for humans)
Escaping is still the base layer and CSP is still what turns one missed escape into a report instead of a stolen session. What has changed is where the browser now draws its boundaries: opener isolation, cross-origin isolation, and Trusted Types are document-level controls that a per-element attribute cannot replace.
Two failure shapes account for most of what goes wrong in review. The first is a
control that is present but hollow — a nonce alongside 'self', a sandbox with
allow-scripts allow-same-origin, Trusted Types enforced without restricting who may
create a policy. Each looks like the hardened version and grants what it appears to
withhold. The second is a defence recommended against an old default: browsers have
moved, and a Referrer-Policy copied from a 2019 guide now configures something
weaker than doing nothing at all.
The corollary for anything written here: prefer the browser's current default to a remembered value, and when a rule names a header value or a token, check it against the platform rather than against an example.
References
references/verifying-findings.md— confirm or refute a finding, then lock itreferences/browser-controls.md— per-framework text binding, strict versus allowlist CSP, the response-header matrix, when COOP / COEP / CORP each apply, and extension-CSP specificsrules/csp_defaults.jsonrules/xss_sinks.json- OWASP XSS Prevention Cheat Sheet.
- OWASP CSP Cheat Sheet.
- OWASP DOM Clobbering Prevention.
- Trusted Types specification (W3C).
- CWE-79 · CWE-346.
Does it work?
Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.
No reviews yet
People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.
- It worked
- Partly
- It didn't
Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.
Your trail
Files you open will collect here, so you can find them again.
Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.
Now do this for your own.
Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.

