Loading...
Loading...
Compare original and translation side by side
src/main.tsxsrc/App.tsxvite.config.tspackage.json**/auth***/login***/token***/credential*fetchfetchsrc/main.tsxsrc/App.tsxvite.config.tspackage.json**/auth***/login***/token***/credential*fetchfetchundefinedundefinedundefinedundefined| Pattern | Action |
|---|---|
| Rewrite to use the Cognite SDK ( |
Custom | Remove — the SDK handles auth automatically |
| WebSocket connection to CDF endpoints | Rewrite to use SDK streaming methods |
| Proxy endpoint that forwards to CDF internally | Rewrite the proxy to use the SDK internally |
| Leave — but add a comment documenting why it's needed |
axiosfetch| 模式 | 操作 |
|---|---|
调用 | 重写为使用Cognite SDK( |
自定义 | 移除 — SDK会自动处理身份验证 |
| 与CDF端点建立WebSocket连接 | 重写为使用SDK的流处理方法 |
| 内部转发至CDF的代理端点 | 重写代理逻辑,使其内部使用SDK |
| 保留 — 但需添加注释说明必要性 |
axiosfetchsdk.files.*sdk.timeseries.*client.instances.*sdk.files.*sdk.timeseries.*client.instances.*undefinedundefined
For each hardcoded secret, replace it with an environment variable. Create or update `.env.example` with a placeholder. Add `.env` to `.gitignore` if missing.
对于每个硬编码的密钥,将其替换为环境变量。创建或更新`.env.example`文件,添加占位符。若`.gitignore`中缺少`.env`,请将其添加进去。import.meta.env.VITE_*const apiKey = "sk-abc123"const apiKey = import.meta.env.VITE_API_KEYconst token = "eyJhbG..."const token = import.meta.env.VITE_AUTH_TOKEN.env.exampleVITE_API_KEY=your-api-key-here.env.example.env.env.local.gitignoreconsole.logconsole.errorimport.meta.env.VITE_*const apiKey = "sk-abc123"const apiKey = import.meta.env.VITE_API_KEYconst token = "eyJhbG..."const token = import.meta.env.VITE_AUTH_TOKEN.env.exampleVITE_API_KEY=your-api-key-here.env.example.env.env.local.gitignoreconsole.logconsole.errorgrep -rn --include="*.tsx" --include="*.ts" \
-E "dangerouslySetInnerHTML|innerHTML\s*=|eval\(|new Function\(|setTimeout\(['\"]|setInterval\(['\"]" src/pnpm add dompurifypnpm add -D @types/dompurifygrep -rn --include="*.tsx" --include="*.ts" \
-E "dangerouslySetInnerHTML|innerHTML\s*=|eval\(|new Function\(|setTimeout\(['\"]|setInterval\(['\"]" src/pnpm add dompurifypnpm add -D @types/dompurifydangerouslySetInnerHTMLDOMPurify.sanitize()import DOMPurify from 'dompurify'// Before
<div dangerouslySetInnerHTML={{ __html: userContent }} />
// After
import DOMPurify from 'dompurify';
<div dangerouslySetInnerHTML={{ __html: DOMPurify.sanitize(userContent) }} />eval()new Function()JSON.parse()setTimeoutsetInterval// Before
setTimeout("doSomething()", 1000)
// After
setTimeout(() => doSomething(), 1000)dangerouslySetInnerHTMLDOMPurify.sanitize()import DOMPurify from 'dompurify'// 修复前
<div dangerouslySetInnerHTML={{ __html: userContent }} />
// 修复后
import DOMPurify from 'dompurify';
<div dangerouslySetInnerHTML={{ __html: DOMPurify.sanitize(userContent) }} />eval()new Function()JSON.parse()setTimeoutsetInterval// 修复前
setTimeout("doSomething()", 1000)
// 修复后
setTimeout(() => doSomething(), 1000)src/contexts/src/hooks/setup-flows-authuseCogniteClientsdkuseAtlasChatagentExternalIdexecuteargssrc/contexts/src/hooks/setup-flows-authuseCogniteClientsdkuseAtlasChatagentExternalIdexecuteargsuseCogniteClientexecuteargsuseCogniteClientexecuteargsundefinedundefined
For each unvalidated external input, add runtime validation. Install Zod if not present (`pnpm add zod`). Create a schema that matches the expected shape and use `.safeParse()` instead of type casts.
对于每个未验证的外部输入,添加运行时验证。若未安装Zod,请执行`pnpm add zod`。创建匹配预期格式的schema,并使用`.safeParse()`而非类型转换。import { z } from 'zod';
const paramSchema = z.object({
id: z.string().min(1),
page: z.coerce.number().int().positive().default(1),
});
const result = paramSchema.safeParse({ id: searchParams.get('id'), page: searchParams.get('page') });
if (!result.success) { /* handle error */ }as MyType.safeParse()searchParams.get()import { z } from 'zod';
const paramSchema = z.object({
id: z.string().min(1),
page: z.coerce.number().int().positive().default(1),
});
const result = paramSchema.safeParse({ id: searchParams.get('id'), page: searchParams.get('page') });
if (!result.success) { /* 处理错误 */ }as MyType.safeParse()searchParams.get()vite.config.tsserver.tsexpress.tsvite.config.tsserver.tsexpress.tsvite.config.tsserver.headersserver: {
headers: {
'Content-Security-Policy': "default-src 'self'; script-src 'self'; style-src 'self' 'unsafe-inline'; img-src 'self' data: https:; connect-src 'self' https://*.cognitedata.com",
'X-Frame-Options': 'DENY',
'X-Content-Type-Options': 'nosniff',
},
}Content-Security-Policydefinevite.config.tsimport.meta.envserver.proxyvite.config.tsserver.headersserver: {
headers: {
'Content-Security-Policy': "default-src 'self'; script-src 'self'; style-src 'self' 'unsafe-inline'; img-src 'self' data: https:; connect-src 'self' https://*.cognitedata.com",
'X-Frame-Options': 'DENY',
'X-Content-Type-Options': 'nosniff',
},
}Content-Security-Policyvite.config.tsdefineimport.meta.envserver.proxypnpm audit --audit-level=highpnpm audit --audit-level=highpnpm audit fixpackage.jsonpnpm installpnpm audit fixpackage.jsonpnpm install| Step | What was fixed | Remaining issues |
|---|---|---|
| 2 — CDF SDK | Migrated N raw calls to SDK | (any that couldn't be migrated) |
| 3 — Credentials | Replaced N hardcoded secrets with env vars | (any that need human decision) |
| 4 — DOM | Sanitized N dangerous patterns | (any that need refactoring) |
| 5 — Auth | Wrapped N unguarded routes | (any architectural gaps) |
| 6 — Validation | Added Zod schemas to N inputs | (any that need custom logic) |
| 7 — Vite config | Added N security headers | (any CSP tuning needed) |
| 8 — Dependencies | Fixed N vulnerable packages | (any with no available fix) |
| 步骤 | 已修复内容 | 剩余问题 |
|---|---|---|
| 2 — CDF SDK | 将N个原始调用迁移至SDK | (无法迁移的调用) |
| 3 — 凭证管理 | 将N个硬编码密钥替换为环境变量 | (需要人工决策的内容) |
| 4 — DOM安全 | 对N个危险模式进行了 sanitize 处理 | (需要重构的内容) |
| 5 — 权限校验 | 包裹了N个未受保护的路由 | (架构层面的漏洞) |
| 6 — 输入验证 | 为N个输入添加了Zod schema | (需要自定义逻辑的内容) |
| 7 — Vite配置 | 添加了N个安全头 | (需要调整CSP的内容) |
| 8 — 依赖管理 | 修复了N个漏洞包 | (无可用修复的包) |