用 Codex 或 Claude 帮你安装 复制这段 Prompt,粘贴到 Codex、Claude 或其他助手里,让它检查 Skill 页面并帮你完成安装。
直接命令不会经过审查 Prompt;运行前请先检查来源。
npx skills add https://github.com/pluginagentmarketplace/custom-plugin-javascript --skill security命令会保持在同一行。复制前请横向滚动并检查完整内容。
想先保存到本地?可下载 SkillsMP 当前能够提供的文件。
正在显示 SKILL.md
| name | security |
| description | JavaScript security best practices and vulnerability prevention. |
| sasmp_version | 1.3.0 |
| bonded_agent | 08-javascript-testing-quality |
| bond_type | PRIMARY_BOND |
| skill_type | reference |
| response_format | code_first |
| max_tokens | 1500 |
| parameter_validation | {"required":["topic"],"optional":["vulnerability_type"]} |
| retry_logic | {"on_ambiguity":"ask_clarification","fallback":"show_xss_prevention"} |
| observability | {"entry_log":"Security skill activated","exit_log":"Security reference provided"} |
// DANGEROUS - Never do this
element.innerHTML = userInput;
// SAFE - Use textContent
element.textContent = userInput;
// SAFE - Sanitize HTML
import DOMPurify from 'dompurify';
element.innerHTML = DOMPurify.sanitize(userInput);
// SAFE - Create elements
const div = document.createElement('div');
div.textContent = userInput;
parent.appendChild(div);
// Server-side validation is required
// Client-side is for UX only
function validateEmail(email) {
const pattern = /^[^\s@]+@[^\s@]+\.[^\s@]+$/;
return pattern.test(email);
}
function sanitizeInput(input) {
return input
.trim()
.replace(/[<>]/g, ''); // Basic, use library for real apps
}
// Use schema validation
import { z } from 'zod';
const UserSchema = z.object({
: z.().(),
: z.().().()
});
.(userData);
<!-- In HTML head or HTTP header -->
<meta http-equiv="Content-Security-Policy"
content="default-src 'self';
script-src 'self' https://trusted.com;
style-src 'self' 'unsafe-inline';">
// NEVER store sensitive data in localStorage
// Use httpOnly cookies for tokens
// If you must use localStorage:
// - Don't store tokens
// - Don't store PII
// - Encrypt if necessary
// Secure cookie settings
document.cookie = 'token=abc; Secure; HttpOnly; SameSite=Strict';
// Include CSRF token in requests
const csrfToken = document.querySelector('meta[name="csrf-token"]').content;
fetch('/api/action', {
method: 'POST',
headers: {
'X-CSRF-Token': csrfToken,
'Content-Type': 'application/json'
},
body: JSON.stringify(data)
});
# Audit dependencies
npm audit
# Fix vulnerabilities
npm audit fix
# Check specific package
npm audit --package-lock-only
# Use Snyk for deeper analysis
npx snyk test
| Vulnerability | Prevention |
|---|---|
| XSS | Use textContent, sanitize |
| CSRF | Use tokens, SameSite cookies |
| Injection | Parameterized queries |
| Prototype pollution | Freeze prototypes |
| Open redirect | Validate URLs |
// Vulnerable
function merge(target, source) {
for (const key in source) {
target[key] = source[key]; // Can pollute __proto__
}
}
// Safe
function safeMerge(target, source) {
for (const key of Object.keys(source)) {
if (key === '__proto__' || key === 'constructor') continue;
target[key] = source[key];
}
}
// Or use Object.assign / spread
const merged = { ...target, ...source };
// Log security events
window.addEventListener('securitypolicyviolation', (e) => {
console.error('CSP violation:', e.blockedURI);
});
// Check for XSS vectors
const testInput = '<script>alert(1)</script>';
// If this executes, you have XSS
// Store in memory, not localStorage
let accessToken = null;
async function login(credentials) {
const response = await fetch('/api/login', {
method: 'POST',
credentials: 'include', // For httpOnly refresh token
body: JSON.stringify(credentials)
});
const { accessToken: token } = await response.json();
accessToken = token; // Memory only
}
// Refresh before expiry
async function refreshToken() {
const response = await fetch('/api/refresh', {
credentials: 'include'
});
const { accessToken: token } = await response.json();
accessToken = token;
}
function isSafeRedirect(url) {
try {
const parsed = new URL(url, window.location.origin);
return parsed.origin === window.location.origin;
} catch {
return false;
}
}
基于 SOC 职业分类