solely 0.2.4 → 0.2.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +41 -3
- package/package.json +4 -2
package/README.md
CHANGED
|
@@ -458,16 +458,54 @@ Solely 框架内置了多层安全防护机制,有效防止常见的 XSS(跨
|
|
|
458
458
|
| 对用户输入进行验证和清理 | 直接操作 DOM 插入不可信内容 |
|
|
459
459
|
| 使用 CSP (Content Security Policy) | 信任未经检验的第三方 API 数据 |
|
|
460
460
|
| 富文本使用白名单过滤 | 动态构造模板字符串 |
|
|
461
|
+
| 对 `:href` 进行协议白名单过滤 | 将用户输入直接绑定到 `:href` |
|
|
462
|
+
| 对 `:src` 也建议进行过滤 | - |
|
|
463
|
+
| 使用 `@click` 框架事件绑定 | - |
|
|
461
464
|
|
|
462
465
|
### 注意事项
|
|
463
466
|
|
|
464
|
-
⚠️
|
|
467
|
+
⚠️ **`:innerHTML` 指令(高危)**:
|
|
465
468
|
|
|
466
|
-
-
|
|
467
|
-
-
|
|
469
|
+
- **永远不要**将用户输入绑定到 `:innerHTML`
|
|
470
|
+
- **永远不要**将第三方 API 数据直接绑定到 `:innerHTML`
|
|
468
471
|
- 仅对完全可信的静态内容使用 `:innerHTML`
|
|
469
472
|
- 如需渲染富文本,请使用专门的富文本组件并进行白名单过滤
|
|
470
473
|
|
|
474
|
+
⚠️ **`:href` 属性绑定(高危)**:
|
|
475
|
+
|
|
476
|
+
- **永远不要**将用户输入直接绑定到 `:href`
|
|
477
|
+
- 恶意 URL 如 `javascript:alert('XSS')` 会在点击时执行代码
|
|
478
|
+
- 建议对 URL 进行协议白名单过滤(只允许 `http://`, `https://`)
|
|
479
|
+
- 示例:
|
|
480
|
+
|
|
481
|
+
```typescript
|
|
482
|
+
function sanitizeUrl(url: string): string {
|
|
483
|
+
if (!url) return '#';
|
|
484
|
+
// 只允许 http/https 协议
|
|
485
|
+
if (/^(https?:)?\/\//i.test(url)) {
|
|
486
|
+
return url;
|
|
487
|
+
}
|
|
488
|
+
return '#';
|
|
489
|
+
}
|
|
490
|
+
// 使用过滤后的 URL
|
|
491
|
+
<a :href="sanitizeUrl($data.userWebsite)">链接</a>
|
|
492
|
+
```
|
|
493
|
+
|
|
494
|
+
ℹ️ **`:src` 属性绑定(低风险)**:
|
|
495
|
+
|
|
496
|
+
- 虽然现代浏览器不会执行 `javascript:` 协议,但仍建议进行过滤
|
|
497
|
+
- Solely 框架不支持 IE,因此不存在旧版浏览器的风险
|
|
498
|
+
|
|
499
|
+
ℹ️ **`:onclick` 属性绑定(无风险)**:
|
|
500
|
+
|
|
501
|
+
- Solely 通过设置 DOM property 实现绑定,字符串值不会被执行
|
|
502
|
+
- 但仍建议使用 `@click` 框架事件绑定语法,语义更清晰
|
|
503
|
+
|
|
504
|
+
ℹ️ **`:style` 属性绑定(无风险)**:
|
|
505
|
+
|
|
506
|
+
- 通过 CSS `url('javascript:...')` 执行代码仅在旧版 IE 中有效
|
|
507
|
+
- Solely 框架不支持 IE,且现代浏览器已修复此漏洞
|
|
508
|
+
|
|
471
509
|
查看 [安全演示示例](./examples/security-demo/) 了解框架如何防护 XSS 攻击。
|
|
472
510
|
|
|
473
511
|
## � API 参考
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "solely",
|
|
3
3
|
"private": false,
|
|
4
|
-
"version": "0.2.
|
|
4
|
+
"version": "0.2.5",
|
|
5
5
|
"description": "A lightweight TypeScript framework for building web components with compile-time optimizations",
|
|
6
6
|
"type": "module",
|
|
7
7
|
"sideEffects": false,
|
|
@@ -204,6 +204,9 @@
|
|
|
204
204
|
"dev:debug": "node --inspect-brk ./node_modules/vite/bin/vite.js",
|
|
205
205
|
"prepare": "husky"
|
|
206
206
|
},
|
|
207
|
+
"dependencies": {
|
|
208
|
+
"magic-string": "^0.30.21"
|
|
209
|
+
},
|
|
207
210
|
"devDependencies": {
|
|
208
211
|
"@rollup/plugin-strip": "^3.0.4",
|
|
209
212
|
"@testing-library/dom": "^10.4.1",
|
|
@@ -219,7 +222,6 @@
|
|
|
219
222
|
"husky": "^9.0.0",
|
|
220
223
|
"jsdom": "27.0.0",
|
|
221
224
|
"lint-staged": "^15.0.0",
|
|
222
|
-
"magic-string": "^0.30.21",
|
|
223
225
|
"prettier": "^3.0.0",
|
|
224
226
|
"rimraf": "^5.0.10",
|
|
225
227
|
"sass": "^1.83.0",
|