ui-security-sandbox
БесплатноБез исполняемых скриптовНе проверенThis skill should be used when hardening an agent UI — authoring the narrowest _meta.ui.csp allowlists, the iframe sandbox and proxy-origin model, treating…
от TheLobbi★ 22 звезды на GitHubОб этом скилле
Security model for agent-rendered UI
Your View renders data that travelled: external service → MCP server → model → host → iframe. Every hop is a place content could have been shaped by someone who is not your user. Design accordingly.
The sandbox contract
- The View runs in a sandboxed iframe with no access to the host's DOM,
cookies,
localStorage, or origin. postMessageis the only channel, which makes every capability enumerable and auditable. That is a feature — do not try to widen it.- CSP is deny-by-default. Anything not declared in
_meta.ui.cspis blocked. - Nested frames are blocked unless
frameDomainsopts in (and several hosts do not supportframeDomainsat all).
For mcp-ui's client renderer, the sandbox.url proxy origin is what enforces
isolation. Never point it at your own application origin to make something
work — that hands untrusted markup your session.
Authoring CSP
Declare the narrowest possible allowlists in the resource contents _meta:
_meta: {
ui: {
csp: {
connectDomains: ["https://api.example.com"], // fetch / WebSocket
resourceDomains: ["https://static.example.com"], // scripts, styles, images, fonts
frameDomains: [], // nested iframes — leave empty
baseUriDomains: [],
},
domain: "https://example.com", // the origin the View is served as
},
}
Rules:
- One entry per real dependency. No wildcards, no
https://*. - No CDN domains you can avoid. Inline assets with
vite-plugin-singlefileor esbuild andresourceDomainsshrinks to nothing. connectDomainsis not a convenience list. Each entry is an origin the View may exfiltrate rendered data to. Justify every one.frameDomainsstays empty unless a specific embed is a product requirement. Copilot ignores it entirely, so an embed-dependent design fails there anyway.- CSP goes in the contents
_meta, not the config argument. Misplacing it produces a View that loads and then silently cannot reach the network.
Review processes (OpenAI's, and any internal one worth having) diff the declared policy against observed behavior. An over-broad allowlist is a review finding before it is an incident.
structuredContent is untrusted input
The single most important rule.
// ❌ Executes anything the upstream service put in the field.
el.innerHTML = toolResult.structuredContent.description;
// ✅ Text is text.
el.textContent = toolResult.structuredContent.description;
React's default {value} interpolation is safe. dangerouslySetInnerHTML is
not, and neither is any string that reaches innerHTML, outerHTML,
insertAdjacentHTML, document.write, eval, new Function, or a javascript:
URL.
Validate the shape before rendering. A schema check at the View boundary — zod, valibot, or a hand-rolled guard — turns a whole class of malformed-payload bugs into a clean error state:
const Forecast = z.object({ city: z.string().max(120), days: z.array(Day).max(14) });
const parsed = Forecast.safeParse(toolResult.structuredContent);
if (!parsed.success) return renderError();
Bound array lengths and string lengths. An unbounded list is a denial-of-service against your own render loop.
URLs from data
Any URL that arrived in the payload is attacker-influenced.
function safeHref(raw: string): string | null {
try {
const u = new URL(raw);
return u.protocol === "https:" || u.protocol === "http:" ? u.toString() : null;
} catch { return null; }
}
- Reject everything but
http:/https:— this killsjavascript:,data:, andvbscript:in one check. - Navigate via
app.openLink({ url })/ui/open-link, neverwindow.open,location.assign, ortop.location. Host-mediated navigation is the whole point: the host can show the destination and refuse. - Same rule for image
src— adata:image is usually fine, an arbitrary remote origin needs to be inresourceDomains.
Prompt injection through the View
Two directions, both real:
Data → model. Whatever you pass to ui/update-model-context or
ui/message enters the conversation as trusted-looking context. If it contains
attacker-controlled text, you have handed an injection straight to the model.
Send structured facts about what the user is looking at — IDs, counts,
selections — not raw upstream prose.
// ❌ raw upstream text into model context
app.updateModelContext({ note: item.descriptionFromThirdParty });
// ✅ facts the model needs, bounded and typed
app.updateModelContext({ selectedIds: ids, view: "list", total: items.length });
Model → View. Tool arguments are model-authored. Validate them server-side before acting; never treat "the model sent it" as authorization.
Authorization lives on the server
- The View is a rendering surface, not a trust boundary. Every state-changing action goes through a tool call the
Установить ui-security-sandbox в Claude Code и Claude Desktop
Зарегайся, чтобы установить скилл
Создай бесплатный аккаунт, чтобы открыть команду установки и сохранить скилл в библиотеку.
- Открой команду установки в одну строку
- Сохраняй скиллы в синхронизируемую библиотеку
- Уведомления, когда скиллы обновляются
Разрешённые инструменты
Инструменты, которые скиллу разрешено вызывать.
Без ограничений — скилл может использовать любой инструмент.
FAQ
Что делает скилл ui-security-sandbox?
This skill should be used when hardening an agent UI — authoring the narrowest _meta.ui.csp allowlists, the iframe sandbox and proxy-origin model, treating structuredContent as untrusted input, prompt-injection through rendered data, host-mediated navigation, secrets handling, and the pre-ship security checklist.
Как установить скилл ui-security-sandbox?
Скопируй папку скилла в ~/.claude/skills (вкладка Claude Code выше делает это одной командой), либо поставь как плагин.
Скилл ui-security-sandbox запускает скрипты?
Нет, скилл состоит только из инструкций (SKILL.md), без исполняемых скриптов.
Похожие скиллы
skill-creator
Create new skills, modify and improve existing skills, and measure skill performance. Use when users want to create a skill from scratch, edit, or optimize an…
от Anthropicdiscernment-nudge
After you give a substantive answer or draft that the user may act on — advice or recommendations, drafted artifacts such as goals, plans, pitches, proposals…
от Anthropicdata-consolidate
Joins the plant's scheduled exports and connector data into one working dataset — ERP items (NetSuite or Infor M3), sales orders, production work orders…
от Anthropicinspection-to-capa
Runs the quality chain end to end: writes the nonconformance against the requirement it violates, searches history at the moment of writing to say whether…
от Anthropic