security
Compare original and translation side by side
🇺🇸
Original
English🇨🇳
Translation
ChineseSecurity Audit
安全审计
Perform a thorough security review of $ARGUMENTS (or the whole app if no argument is given). Work through every step below in order and report findings with file paths and line numbers.
对**$ARGUMENTS**(若未提供参数则对整个应用)执行全面的安全审查。按顺序完成以下每一步,并附上文件路径和行号报告发现的问题。
Step 1 — Map the attack surface
步骤1 — 梳理攻击面
Read these files before checking anything:
- /
src/main.tsx— entry point, routing, auth gatingsrc/App.tsx - — dev server proxy, CORS, headers
vite.config.ts - — list of third-party dependencies
package.json - Any file matching ,
**/auth*,**/login*,**/token***/credential*
Identify:
- All pages/routes and whether each is behind an auth guard
- All places where external data enters the app (CDF SDK calls, , user form input)
fetch - All places where data is written back (CDF upsert, POST/PUT/DELETE)
fetch
在检查任何内容前,先阅读以下文件:
- /
src/main.tsx— 入口文件、路由、身份认证拦截src/App.tsx - — 开发服务器代理、CORS、请求头
vite.config.ts - — 第三方依赖列表
package.json - 所有匹配、
**/auth*、**/login*、**/token*的文件**/credential*
识别:
- 所有页面/路由,以及每个路由是否受身份认证拦截保护
- 外部数据进入应用的所有入口(CDF SDK调用、、用户表单输入)
fetch - 数据回写的所有位置(CDF upsert、POST/PUT/DELETE请求)
fetch
Step 2 — Credential & secret hygiene
步骤2 — 凭证与密钥管理
Search for hard-coded credentials and sensitive values:
bash
undefined搜索硬编码的凭证和敏感值:
bash
undefinedLook for anything that smells like a secret in source files
在源码文件中查找疑似密钥的内容
grep -rn --include=".ts" --include=".tsx" --include=".js"
-E "(password|secret|apikey|api_key|token|bearer|private_key)\s=\s*['"]" src/
-E "(password|secret|apikey|api_key|token|bearer|private_key)\s=\s*['"]" src/
Flag any match. Secrets must come from environment variables (`import.meta.env.VITE_*`) or from the Dune auth flow — never hard-coded.
Also verify:
- `.env.example` does not contain real secrets (only placeholder values like `your-token-here`)
- `.gitignore` lists `.env` and `.env.local`
- No `console.log`, `console.error`, or similar calls that print a CDF token, user object, or API key
---grep -rn --include=".ts" --include=".tsx" --include=".js"
-E "(password|secret|apikey|api_key|token|bearer|private_key)\s=\s*['"]" src/
-E "(password|secret|apikey|api_key|token|bearer|private_key)\s=\s*['"]" src/
标记所有匹配项。密钥必须来自环境变量(`import.meta.env.VITE_*`)或Dune身份认证流程——绝对不能硬编码。
同时验证:
- `.env.example` 不包含真实密钥(仅包含`your-token-here`这类占位符值)
- `.gitignore` 已列出`.env`和`.env.local`
- 没有`console.log`、`console.error`或类似调用会打印CDF令牌、用户对象或API密钥
---Step 3 — Dangerous DOM APIs
步骤3 — 危险DOM API
Search for patterns that allow arbitrary script execution or HTML injection:
bash
grep -rn --include="*.tsx" --include="*.ts" \
-E "dangerouslySetInnerHTML|innerHTML\s*=|eval\(|new Function\(|setTimeout\(['\"]|setInterval\(['\"]" src/For each hit:
- : confirm the value is sanitized with DOMPurify or equivalent before use. If not, flag as HIGH.
dangerouslySetInnerHTML - /
eval: flag as HIGH unconditionally — there is no safe use in a browser app.new Function - /
setTimeoutwith a string argument: flag as MEDIUM (equivalent tosetInterval).eval
搜索允许任意脚本执行或HTML注入的模式:
bash
grep -rn --include="*.tsx" --include="*.ts" \
-E "dangerouslySetInnerHTML|innerHTML\s*=|eval\(|new Function\(|setTimeout\(['\"]|setInterval\(['\"]" src/针对每个匹配项:
- :确认值在使用前已通过DOMPurify或同类工具进行清理。若未清理,标记为高风险。
dangerouslySetInnerHTML - /
eval:无条件标记为高风险——在浏览器应用中没有安全的使用场景。new Function - /
setTimeout使用字符串参数:标记为中风险(等价于setInterval)。eval
Step 4 — Authentication & authorization
步骤4 — 身份认证与授权
Read the auth setup (likely , , or output):
src/contexts/src/hooks/setup-dune-auth- Every route that shows CDF data must be behind the Dune auth guard (returns a non-null
useCogniteClientbefore rendering).sdk - The CDF client must be initialized with short-lived OIDC tokens, not a static API key.
- User role/capability checks must happen server-side (CDF ACLs) — do not rely solely on hiding UI elements.
Check the / Atlas agent integration:
useAtlasChat- The must not be constructed from user-supplied input.
agentExternalId - Tool functions must not trust
executeblindly — validate or guard before using values in CDF queries.args
阅读身份认证设置(通常在、或输出文件中):
src/contexts/src/hooks/setup-dune-auth- 所有展示CDF数据的路由必须受Dune身份认证拦截保护(在渲染前返回非空的
useCogniteClient)。sdk - CDF客户端必须使用短期OIDC令牌初始化,而非静态API密钥。
- 用户角色/权限检查必须在服务器端执行(CDF访问控制列表)——不得仅依赖隐藏UI元素。
检查 / Atlas代理集成:
useAtlasChat- 不得由用户提供的输入构造。
agentExternalId - 工具函数不得盲目信任
execute——在CDF查询中使用值前需验证或拦截。args
Step 5 — Input validation
步骤5 — 输入验证
Every value that comes from a form, URL param, or query string before it reaches a CDF call or is rendered to the DOM must be validated:
bash
undefined所有来自表单、URL参数或查询字符串的值,在传入CDF调用或渲染到DOM前必须经过验证:
bash
undefinedFind useSearchParams, URLSearchParams, and form onChange handlers
查找useSearchParams、URLSearchParams和表单onChange处理器
grep -rn --include=".tsx" --include=".ts"
-E "useSearchParams|URLSearchParams|searchParams.get|e.target.value" src/
-E "useSearchParams|URLSearchParams|searchParams.get|e.target.value" src/
For each hit, verify:
- The value is validated with Zod or a type guard before use.
- String values rendered in JSX are not concatenated into raw HTML.
---grep -rn --include=".tsx" --include=".ts"
-E "useSearchParams|URLSearchParams|searchParams.get|e.target.value" src/
-E "useSearchParams|URLSearchParams|searchParams.get|e.target.value" src/
针对每个匹配项,验证:
- 值在使用前已通过Zod或类型守卫进行验证。
- 在JSX中渲染的字符串值未拼接成原始HTML。
---Step 6 — Vite / server configuration
步骤6 — Vite / 服务器配置
Read and any / files:
vite.config.tsserver.tsexpress.ts- Confirm includes at minimum:
server.headers- — restricts script sources
Content-Security-Policy - or
X-Frame-Options: DENYframe-ancestors 'none' X-Content-Type-Options: nosniff
- Confirm the dev proxy () does not expose internal endpoints in production builds.
server.proxy - Confirm does not embed raw secrets into the bundle (use
defineinstead).import.meta.env
阅读及所有 / 文件:
vite.config.tsserver.tsexpress.ts- 确认至少包含:
server.headers- — 限制脚本源
Content-Security-Policy - 或
X-Frame-Options: DENYframe-ancestors 'none' X-Content-Type-Options: nosniff
- 确认开发服务器代理()在生产构建中未暴露内部端点。
server.proxy - 确认未将原始密钥嵌入到打包文件中(改用
define)。import.meta.env
Step 7 — Dependency audit
步骤7 — 依赖审计
bash
pnpm audit --audit-level=highList every high/critical vulnerability with its package name, severity, and the recommended fix. If no vulnerabilities are found at high/critical level, state that explicitly.
bash
pnpm audit --audit-level=high列出所有高/严重级别的漏洞,包含包名、严重程度和推荐修复方案。若未发现高/严重级别的漏洞,需明确说明。
Step 8 — Report findings
步骤8 — 报告发现的问题
Produce a structured report grouped by severity:
| Severity | File | Line | Issue | Recommendation |
|---|---|---|---|---|
| HIGH | | 42 | | Remove; use a data-driven approach |
| MEDIUM | ... | ... | ... | ... |
| LOW | ... | ... | ... | ... |
| INFO | ... | — | Dependency X has a known low-severity CVE | Run |
If no issues are found in a step, state "No issues found" for that step. Do not skip steps silently.
生成按严重程度分组的结构化报告:
| 严重程度 | 文件 | 行号 | 问题 | 建议 |
|---|---|---|---|---|
| 高风险 | | 42 | 调用 | 删除该调用;采用数据驱动的实现方式 |
| 中风险 | ... | ... | ... | ... |
| 低风险 | ... | ... | ... | ... |
| 信息 | ... | — | 依赖包X存在已知低严重级别的CVE | 执行 |
若某一步未发现问题,需明确说明“未发现问题”。不得静默跳过任何步骤。
Done
完成
Summarize the total number of findings by severity and list any items that require immediate action before the next deployment.
按严重程度总结发现问题的总数,并列出下次部署前需立即处理的事项。