extension-analyze
Compare original and translation side by side
🇺🇸
Original
English🇨🇳
Translation
ChineseExtension Analyze (Security & Compliance Auditor)
扩展分析(安全与合规审计工具)
Audit an existing Chrome extension. Do NOT just explain — execute the workflow.
对现有Chrome扩展进行审计。请勿仅做解释——执行以下工作流程。
Workflow (Execute This)
工作流程(执行以下步骤)
Step 1: Locate extension root and detect framework
步骤1:定位扩展根目录并检测框架
Ask user for path if not provided. Detect framework:
bash
ls wxt.config.ts plasmo.config.ts vite.config.ts manifest.json 2>/dev/null- Plasmo: manifest auto-generated; check and
package.jsoninsteadplasmo.config.ts - WXT: check manifest section
wxt.config.ts - Vanilla/CRXJS: check directly
manifest.json
如果未提供路径,请询问用户。检测框架:
bash
ls wxt.config.ts plasmo.config.ts vite.config.ts manifest.json 2>/dev/null- Plasmo:清单文件自动生成;请检查和
package.jsonplasmo.config.ts - WXT:检查中的清单配置部分
wxt.config.ts - 原生/CRXJS:直接检查
manifest.json
Step 2: Scan manifest.json (or equivalent config)
步骤2:扫描manifest.json(或等效配置文件)
bash
undefinedbash
undefinedCheck MV version, permissions, host_permissions, CSP, web_accessible_resources
检查MV版本、权限、主机权限、CSP、可访问网页资源
cat <ext>/manifest.json | jq '{manifest_version, permissions, host_permissions, content_security_policy, web_accessible_resources}'
undefinedcat <ext>/manifest.json | jq '{manifest_version, permissions, host_permissions, content_security_policy, web_accessible_resources}'
undefinedStep 3: Quick grep scans
步骤3:快速grep扫描
bash
undefinedbash
undefinedXSS vectors
XSS向量
grep -rn "innerHTML|outerHTML|document.write|insertAdjacentHTML" <ext>/src --include=".ts" --include=".js"
grep -rn "innerHTML|outerHTML|document.write|insertAdjacentHTML" <ext>/src --include=".ts" --include=".js"
Unsafe patterns
不安全模式
grep -rn "eval(|new Function(|setTimeout.*string|setInterval.*string" <ext>/src
grep -rn "eval(|new Function(|setTimeout.*string|setInterval.*string" <ext>/src
Hardcoded secrets
硬编码密钥
grep -rn "api_key|apiKey|secret|password|token" <ext>/src --include=".ts" --include=".js" | grep -v ".test." | grep -v "node_modules"
grep -rn "api_key|apiKey|secret|password|token" <ext>/src --include=".ts" --include=".js" | grep -v ".test." | grep -v "node_modules"
HTTP (non-HTTPS) calls
HTTP(非HTTPS)调用
grep -rn "http://" <ext>/src --include=".ts" --include=".js"
grep -rn "http://" <ext>/src --include=".ts" --include=".js"
Message handler sender validation
消息处理器发送方验证
grep -rn "onMessage|addListener" <ext>/src | grep -v "node_modules"
grep -rn "onMessage|addListener" <ext>/src | grep -v "node_modules"
Remote code loading
远程代码加载
grep -rn "importScripts|fetch.*.js|eval|chrome.scripting.executeScript" <ext>/src
undefinedgrep -rn "importScripts|fetch.*.js|eval|chrome.scripting.executeScript" <ext>/src
undefinedStep 4: Check CSP configuration
步骤4:检查CSP配置
- MV3 default CSP:
script-src 'self'; object-src 'self' - Flag any ,
unsafe-inline, orunsafe-evalsourceshttp: - Verify no remote script sources
- MV3默认CSP:
script-src 'self'; object-src 'self' - 标记任何包含、
unsafe-inline或unsafe-eval的来源http: - 验证无远程脚本来源
Step 5: Dependency audit
步骤5:依赖项审计
bash
cd <ext> && npm audit --json | jq '.vulnerabilities | to_entries[] | {pkg: .key, severity: .value.severity}'bash
cd <ext> && npm audit --json | jq '.vulnerabilities | to_entries[] | {pkg: .key, severity: .value.severity}'Step 6: Generate report
步骤6:生成报告
Output findings grouped by severity. See Output Format below.
按风险等级分组输出检测结果。请参考下方的输出格式。
Severity Levels
风险等级
| Level | Criteria |
|---|---|
| Critical | RCE, data exfiltration, remote code loading, eval with untrusted input |
| High | XSS, missing sender validation, API keys in source, HTTP API calls |
| Medium | Overly broad permissions, unsafe-inline CSP, sync storage secrets |
| Low | Missing error handling, no TypeScript, console.log in production |
| 等级 | 判定标准 |
|---|---|
| Critical(严重) | 远程代码执行(RCE)、数据泄露、远程代码加载、使用不可信输入的eval函数 |
| High(高) | XSS攻击、缺失发送方验证、源代码中包含API密钥、HTTP API调用 |
| Medium(中) | 权限范围过宽、CSP中包含unsafe-inline、同步存储中存储敏感数据 |
| Low(低) | 缺失错误处理、未使用TypeScript、生产环境中存在console.log |
Top 10 Issues Found in Most Extensions
多数扩展中存在的十大常见问题
- with page-sourced data (XSS) — High
innerHTML - without sender origin check — High
onMessage - host permission when not needed — Medium
<all_urls> - or
unsafe-inlinein CSP — Medium/Criticalunsafe-eval - API keys hardcoded in source — Critical
- or
eval()usage — Criticalnew Function() - storing sensitive data — Medium
chrome.storage.sync - HTTP endpoints instead of HTTPS — High
- Remote script loading (MV3 violation) — Critical
- Missing restrictions — Medium
web_accessible_resources
- 使用页面来源数据的(XSS)——高风险
innerHTML - 未检查发送方来源的——高风险
onMessage - 非必要情况下使用主机权限——中风险
<all_urls> - CSP中包含或
unsafe-inline——中/严重风险unsafe-eval - 源代码中硬编码API密钥——严重风险
- 使用或
eval()——严重风险new Function() - 存储敏感数据——中风险
chrome.storage.sync - 使用HTTP端点而非HTTPS——高风险
- 远程脚本加载(违反MV3规则)——严重风险
- 缺失限制——中风险
web_accessible_resources
Output Format
输出格式
undefinedundefinedExtension Audit Report: <name> v<version>
扩展审计报告:<名称> v<版本>
Date: <date> | MV: <2|3>
日期:<日期> | MV版本:<2|3>
Summary
摘要
Critical: X | High: X | Medium: X | Low: X
严重风险:X | 高风险:X | 中风险:X | 低风险:X
Findings
检测结果
[CRITICAL] API Key Exposed in Source
[严重风险] 源代码中暴露API密钥
File: src/background.ts:42
Pattern:
Fix: Move to environment variable or user-provided settings
Reference: references/common-vulnerabilities.md#4
const API_KEY = "sk-..."...
文件:src/background.ts:42
模式:
修复方案:迁移至环境变量或用户提供的设置
参考文档:references/common-vulnerabilities.md#4
const API_KEY = "sk-..."...
Passed Checks
通过的检查项
- CSP: No unsafe-inline/eval ✓
- HTTPS: All API calls use HTTPS ✓
---- CSP:无unsafe-inline/eval ✓
- HTTPS:所有API调用均使用HTTPS ✓
---References
参考资料
- — Full security audit checklist
references/security-checklist.md - — Performance, UX, accessibility, CWS
references/best-practices-checklist.md - — Vulnerability patterns with grep/fix
references/common-vulnerabilities.md - — Chrome Web Store policy compliance
references/cws-compliance-checklist.md - Chrome Permissions List
- Chrome Extensions Docs
- — 完整安全审计清单
references/security-checklist.md - — 性能、用户体验、可访问性、CWS合规性
references/best-practices-checklist.md - — 包含grep检测及修复方案的漏洞模式
references/common-vulnerabilities.md - — Chrome Web Store政策合规性清单
references/cws-compliance-checklist.md - Chrome Permissions List — Chrome扩展权限列表
- Chrome Extensions Docs — Chrome扩展开发文档
Related Skills
相关技能
- — Generate/validate manifest.json
extension-manifest - — Scaffold new extension
extension-create - — Store submission checklist
extension-publish
- — 生成/验证manifest.json
extension-manifest - — 快速搭建新扩展
extension-create - — 商店提交清单
extension-publish