@blueking/bkui-knowledge 0.0.1-beta.1 → 0.0.1-beta.11

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.
Files changed (50) hide show
  1. package/README.md +166 -58
  2. package/bin/bkui-knowledge.js +229 -86
  3. package/knowledge/manifest.json +38 -1
  4. package/knowledge/skills/.template/README.md +1 -1
  5. package/knowledge/skills/bk-security-redlines/SKILL.md +47 -0
  6. package/knowledge/skills/bk-security-redlines/references/auth-check.md +73 -0
  7. package/knowledge/skills/bk-security-redlines/references/data-encryption.md +78 -0
  8. package/knowledge/skills/bk-security-redlines/references/input-validation.md +96 -0
  9. package/knowledge/skills/bk-skill-creator/SKILL.md +37 -0
  10. package/knowledge/skills/bk-skill-creator/references/common-mistakes.md +43 -0
  11. package/knowledge/skills/bk-skill-creator/references/quick-start.md +42 -0
  12. package/knowledge/skills/bk-skill-creator/references/skill-checklist.md +93 -0
  13. package/knowledge/skills/bk-skill-creator/references/structure-guide.md +88 -0
  14. package/knowledge/skills/bk-skill-creator/references/writing-tips.md +153 -0
  15. package/knowledge/skills/bkui-quick-start/SKILL.md +52 -0
  16. package/knowledge/skills/bkui-quick-start/references/components-list.md +17 -0
  17. package/knowledge/skills/bkui-quick-start/references/skills-index.md +26 -0
  18. package/knowledge/skills/external/vue-skills/LICENSE +21 -0
  19. package/knowledge/skills/external/vue-skills/README.md +69 -0
  20. package/knowledge/skills/external/vue-skills/skills/vue-best-practices/SKILL.md +42 -0
  21. package/knowledge/skills/external/vue-skills/skills/vue-best-practices/rules/codeactions-save-performance.md +79 -0
  22. package/knowledge/skills/external/vue-skills/skills/vue-best-practices/rules/data-attributes-config.md +74 -0
  23. package/knowledge/skills/external/vue-skills/skills/vue-best-practices/rules/deep-watch-numeric.md +102 -0
  24. package/knowledge/skills/external/vue-skills/skills/vue-best-practices/rules/define-model-update-event.md +79 -0
  25. package/knowledge/skills/external/vue-skills/skills/vue-best-practices/rules/duplicate-plugin-detection.md +102 -0
  26. package/knowledge/skills/external/vue-skills/skills/vue-best-practices/rules/fallthrough-attributes.md +63 -0
  27. package/knowledge/skills/external/vue-skills/skills/vue-best-practices/rules/hmr-vue-ssr.md +124 -0
  28. package/knowledge/skills/external/vue-skills/skills/vue-best-practices/rules/module-resolution-bundler.md +81 -0
  29. package/knowledge/skills/external/vue-skills/skills/vue-best-practices/rules/pinia-store-mocking.md +159 -0
  30. package/knowledge/skills/external/vue-skills/skills/vue-best-practices/rules/script-setup-jsdoc.md +85 -0
  31. package/knowledge/skills/external/vue-skills/skills/vue-best-practices/rules/strict-css-modules.md +68 -0
  32. package/knowledge/skills/external/vue-skills/skills/vue-best-practices/rules/unplugin-auto-import-conflicts.md +97 -0
  33. package/knowledge/skills/external/vue-skills/skills/vue-best-practices/rules/volar-3-breaking-changes.md +66 -0
  34. package/knowledge/skills/external/vue-skills/skills/vue-best-practices/rules/vue-directive-comments.md +73 -0
  35. package/knowledge/skills/external/vue-skills/skills/vue-best-practices/rules/vue-router-typed-params.md +81 -0
  36. package/knowledge/skills/external/vue-skills/skills/vue-best-practices/rules/vue-tsc-strict-templates.md +69 -0
  37. package/knowledge/skills/external/vue-skills/skills/vue-best-practices/rules/with-defaults-union-types.md +102 -0
  38. package/knowledge/skills/web-security-guide/SKILL.md +48 -0
  39. package/knowledge/skills/web-security-guide/references/access-control.md +123 -0
  40. package/knowledge/skills/web-security-guide/references/auth-session.md +99 -0
  41. package/knowledge/skills/web-security-guide/references/csrf.md +59 -0
  42. package/knowledge/skills/web-security-guide/references/data-exposure.md +108 -0
  43. package/knowledge/skills/web-security-guide/references/deserialization.md +59 -0
  44. package/knowledge/skills/web-security-guide/references/injection.md +357 -0
  45. package/knowledge/skills/web-security-guide/references/logging-monitoring.md +47 -0
  46. package/knowledge/skills/web-security-guide/references/security-config.md +73 -0
  47. package/knowledge/skills/web-security-guide/references/ssrf.md +55 -0
  48. package/knowledge/skills/web-security-guide/references/xss.md +134 -0
  49. package/package.json +3 -3
  50. package/server/mcp-core.js +48 -33
@@ -0,0 +1,73 @@
1
+ ---
2
+ title: Vue Template Directive Comments
3
+ impact: HIGH
4
+ impactDescription: enables fine-grained control over template type checking
5
+ type: capability
6
+ tags: vue-directive, vue-ignore, vue-expect-error, vue-skip, template, type-checking
7
+ ---
8
+
9
+ # Vue Template Directive Comments
10
+
11
+ **Impact: HIGH** - enables fine-grained control over template type checking
12
+
13
+ Vue Language Tools supports special directive comments to control type checking behavior in templates.
14
+
15
+ ## Available Directives
16
+
17
+ ### @vue-ignore
18
+
19
+ Suppress type errors for the next line:
20
+
21
+ ```vue
22
+ <template>
23
+ <!-- @vue-ignore -->
24
+ <Component :prop="valueWithTypeError" />
25
+ </template>
26
+ ```
27
+
28
+ ### @vue-expect-error
29
+
30
+ Assert that the next line should have a type error (useful for testing):
31
+
32
+ ```vue
33
+ <template>
34
+ <!-- @vue-expect-error -->
35
+ <Component :invalid-prop="value" />
36
+ </template>
37
+ ```
38
+
39
+ ### @vue-skip
40
+
41
+ Skip type checking for an entire block:
42
+
43
+ ```vue
44
+ <template>
45
+ <!-- @vue-skip -->
46
+ <div>
47
+ <!-- Everything in here is not type-checked -->
48
+ <LegacyComponent :any="props" :go="here" />
49
+ </div>
50
+ </template>
51
+ ```
52
+
53
+ ### @vue-generic
54
+
55
+ Declare template-level generic types:
56
+
57
+ ```vue
58
+ <template>
59
+ <!-- @vue-generic {T extends string} -->
60
+ <GenericList :items="items as T[]" />
61
+ </template>
62
+ ```
63
+
64
+ ## Use Cases
65
+
66
+ - Migrating legacy components with incomplete types
67
+ - Working with third-party components that have incorrect type definitions
68
+ - Temporarily suppressing errors during refactoring
69
+ - Testing that certain patterns produce expected type errors
70
+
71
+ ## Reference
72
+
73
+ - [Vue Language Tools Wiki - Directive Comments](https://github.com/vuejs/language-tools/wiki/Directive-Comments)
@@ -0,0 +1,81 @@
1
+ ---
2
+ title: Vue Router useRoute Params Union Type Narrowing
3
+ impact: MEDIUM
4
+ impactDescription: fixes "Property does not exist" errors with typed route params
5
+ type: capability
6
+ tags: vue-router, useRoute, unplugin-vue-router, typed-routes, params
7
+ ---
8
+
9
+ # Vue Router useRoute Params Union Type Narrowing
10
+
11
+ **Impact: MEDIUM** - fixes "Property does not exist" errors with typed route params
12
+
13
+ With `unplugin-vue-router` typed routes, `route.params` becomes a union of ALL page param types. TypeScript cannot narrow `Record<never, never> | { id: string }` properly, causing "Property 'id' does not exist" errors even on the correct page.
14
+
15
+ ## Symptoms
16
+
17
+ - "Property 'id' does not exist on type 'RouteParams'"
18
+ - `route.params.id` shows as `string | undefined` everywhere
19
+ - Union type of all route params instead of specific route
20
+ - Type narrowing with `if (route.name === 'users-id')` doesn't work
21
+
22
+ ## Root Cause
23
+
24
+ `unplugin-vue-router` generates a union type of all possible route params. TypeScript's control flow analysis can't narrow this union based on route name checks.
25
+
26
+ ## Fix
27
+
28
+ **Option 1: Pass route name to useRoute (recommended)**
29
+ ```typescript
30
+ // pages/users/[id].vue
31
+ import { useRoute } from 'vue-router/auto'
32
+
33
+ // Specify the route path for proper typing
34
+ const route = useRoute('/users/[id]')
35
+
36
+ // Now properly typed as { id: string }
37
+ console.log(route.params.id) // string, not string | undefined
38
+ ```
39
+
40
+ **Option 2: Type assertion with specific route**
41
+ ```typescript
42
+ import { useRoute } from 'vue-router'
43
+ import type { RouteLocationNormalized } from 'vue-router/auto-routes'
44
+
45
+ const route = useRoute() as RouteLocationNormalized<'/users/[id]'>
46
+ route.params.id // Properly typed
47
+ ```
48
+
49
+ **Option 3: Define route-specific param type**
50
+ ```typescript
51
+ // In your page component
52
+ interface UserRouteParams {
53
+ id: string
54
+ }
55
+
56
+ const route = useRoute()
57
+ const { id } = route.params as UserRouteParams
58
+ ```
59
+
60
+ ## Required tsconfig Setting
61
+
62
+ Ensure `moduleResolution: "bundler"` for unplugin-vue-router:
63
+ ```json
64
+ {
65
+ "compilerOptions": {
66
+ "moduleResolution": "bundler"
67
+ }
68
+ }
69
+ ```
70
+
71
+ ## Caveat: Route Name Format
72
+
73
+ The route name matches the file path pattern:
74
+ - `pages/users/[id].vue` → `/users/[id]`
75
+ - `pages/posts/[slug]/comments.vue` → `/posts/[slug]/comments`
76
+
77
+ ## Reference
78
+
79
+ - [unplugin-vue-router#337](https://github.com/posva/unplugin-vue-router/issues/337)
80
+ - [unplugin-vue-router#176](https://github.com/posva/unplugin-vue-router/discussions/176)
81
+ - [unplugin-vue-router TypeScript docs](https://uvr.esm.is/guide/typescript.html)
@@ -0,0 +1,69 @@
1
+ ---
2
+ title: Enable Strict Template Checking
3
+ impact: HIGH
4
+ impactDescription: catches undefined components and props at compile time
5
+ type: capability
6
+ tags: vue-tsc, typescript, type-checking, templates, vueCompilerOptions
7
+ ---
8
+
9
+ # Enable Strict Template Checking
10
+
11
+ **Impact: HIGH** - catches undefined components and props at compile time
12
+
13
+ By default, vue-tsc does not report errors for undefined components in templates. Enable `strictTemplates` to catch these issues during type checking.
14
+
15
+ ## Which tsconfig?
16
+
17
+ Add `vueCompilerOptions` to the tsconfig that includes Vue source files. In projects with multiple tsconfigs (like those created with `create-vue`), this is typically `tsconfig.app.json`, not the root `tsconfig.json` or `tsconfig.node.json`.
18
+
19
+ **Incorrect (missing strict checking):**
20
+
21
+ ```json
22
+ {
23
+ "compilerOptions": {
24
+ "strict": true
25
+ }
26
+ // vueCompilerOptions not configured - undefined components won't error
27
+ }
28
+ ```
29
+
30
+ **Correct (strict template checking enabled):**
31
+
32
+ ```json
33
+ {
34
+ "compilerOptions": {
35
+ "strict": true
36
+ },
37
+ "vueCompilerOptions": {
38
+ "strictTemplates": true
39
+ }
40
+ }
41
+ ```
42
+
43
+ ## Available Options
44
+
45
+ | Option | Default | Effect |
46
+ |--------|---------|--------|
47
+ | `strictTemplates` | `false` | Enables all checkUnknown* options below |
48
+ | `checkUnknownComponents` | `false` | Error on undefined/unregistered components |
49
+ | `checkUnknownProps` | `false` | Error on props not declared in component definition |
50
+ | `checkUnknownEvents` | `false` | Error on events not declared via `defineEmits` |
51
+ | `checkUnknownDirectives` | `false` | Error on unregistered custom directives |
52
+
53
+ ## Granular Control
54
+
55
+ If `strictTemplates` is too strict, enable individual checks:
56
+
57
+ ```json
58
+ {
59
+ "vueCompilerOptions": {
60
+ "checkUnknownComponents": true,
61
+ "checkUnknownProps": false
62
+ }
63
+ }
64
+ ```
65
+
66
+ ## Reference
67
+
68
+ - [Vue Compiler Options](https://github.com/vuejs/language-tools/wiki/Vue-Compiler-Options)
69
+ - [Vite Vue+TS Template](https://github.com/vitejs/vite/tree/main/packages/create-vite/template-vue-ts)
@@ -0,0 +1,102 @@
1
+ ---
2
+ title: withDefaults Incorrect Default with Union Types
3
+ impact: MEDIUM
4
+ impactDescription: fixes incorrect default value behavior with union type props
5
+ type: capability
6
+ tags: withDefaults, defineProps, union-types, defaults, vue-3.5
7
+ ---
8
+
9
+ # withDefaults Incorrect Default with Union Types
10
+
11
+ **Impact: MEDIUM** - fixes spurious "Missing required prop" warning with union type props
12
+
13
+ Using `withDefaults` with union types like `false | string` may produce a Vue runtime warning "Missing required prop" even when a default is provided. The runtime value IS applied correctly, but the warning can be confusing.
14
+
15
+ ## Symptoms
16
+
17
+ - Vue warns "Missing required prop" despite default being set
18
+ - Warning appears only with union types like `false | string`
19
+ - TypeScript types are correct
20
+ - Runtime value IS correct (the default is applied)
21
+
22
+ ## Problematic Pattern
23
+
24
+ ```typescript
25
+ // This produces a spurious warning (but works at runtime)
26
+ interface Props {
27
+ value: false | string // Union type
28
+ }
29
+
30
+ const props = withDefaults(defineProps<Props>(), {
31
+ value: 'default' // Runtime value IS correct, but Vue warns about missing prop
32
+ })
33
+ ```
34
+
35
+ ## Fix
36
+
37
+ **Option 1: Use Reactive Props Destructure (Vue 3.5+)**
38
+ ```vue
39
+ <script setup lang="ts">
40
+ interface Props {
41
+ value: false | string
42
+ }
43
+
44
+ // Preferred in Vue 3.5+
45
+ const { value = 'default' } = defineProps<Props>()
46
+ </script>
47
+ ```
48
+
49
+ **Option 2: Use runtime declaration**
50
+ ```vue
51
+ <script setup lang="ts">
52
+ const props = defineProps({
53
+ value: {
54
+ type: [Boolean, String] as PropType<false | string>,
55
+ default: 'default'
56
+ }
57
+ })
58
+ </script>
59
+ ```
60
+
61
+ **Option 3: Split into separate props**
62
+ ```typescript
63
+ interface Props {
64
+ enabled: boolean
65
+ customValue?: string
66
+ }
67
+
68
+ const props = withDefaults(defineProps<Props>(), {
69
+ enabled: false,
70
+ customValue: 'default'
71
+ })
72
+ ```
73
+
74
+ ## Why Reactive Props Destructure Works
75
+
76
+ Vue 3.5's Reactive Props Destructure handles default values at the destructuring level, bypassing the type inference issues with `withDefaults`.
77
+
78
+ ```typescript
79
+ // The default is applied during destructuring, not type inference
80
+ const { prop = 'default' } = defineProps<{ prop?: string }>()
81
+ ```
82
+
83
+ ## Enable Reactive Props Destructure
84
+
85
+ This is enabled by default in Vue 3.5+. For older versions:
86
+ ```javascript
87
+ // vite.config.js
88
+ export default {
89
+ plugins: [
90
+ vue({
91
+ script: {
92
+ propsDestructure: true
93
+ }
94
+ })
95
+ ]
96
+ }
97
+ ```
98
+
99
+ ## Reference
100
+
101
+ - [vuejs/core#12897](https://github.com/vuejs/core/issues/12897)
102
+ - [Reactive Props Destructure RFC](https://github.com/vuejs/rfcs/discussions/502)
@@ -0,0 +1,48 @@
1
+ ---
2
+ id: security/web-security-guide
3
+ name: Web 安全漏洞学习指南
4
+ category: security
5
+ description: OWASP 十大漏洞原理、影响与修复方案,覆盖 Python/Java 场景
6
+ tags: [security, owasp, vulnerability, injection, xss, csrf, ssrf]
7
+ updated_at: 2026-01-23
8
+ ---
9
+
10
+ # Web 安全漏洞学习指南
11
+
12
+ ## ⚠️ 核心规则
13
+
14
+ 1. **永不信任用户输入** - 所有外部数据必须校验、转义、参数化
15
+ 2. **最小权限原则** - 仅授予完成任务所需的最小权限
16
+ 3. **纵深防御** - 多层安全措施,不依赖单一防护
17
+
18
+ ## 十大漏洞速查
19
+
20
+ | 漏洞 | 危害 | 核心防御 |
21
+ |------|------|----------|
22
+ | 🔴 注入 | RCE/数据泄露 | 参数化查询 |
23
+ | 🔴 XSS | 会话劫持 | 转义输出 |
24
+ | 🔴 认证缺陷 | 账户接管 | 强Token+限速 |
25
+ | 🔴 敏感数据泄露 | 隐私泄露 | 加密+脱敏 |
26
+ | 🔴 访问控制缺失 | 越权操作 | 后端鉴权 |
27
+ | 🟡 安全配置错误 | 信息泄露 | 关闭Debug |
28
+ | 🟡 CSRF | 伪造操作 | Token验证 |
29
+ | 🟡 反序列化 | RCE | 禁用危险接口 |
30
+ | 🟡 SSRF | 内网探测 | 白名单URL |
31
+ | ⚪ 日志不足 | 无法溯源 | 完整审计 |
32
+
33
+ ## 📦 按需加载资源
34
+
35
+ | 漏洞类型 | URI |
36
+ |----------|-----|
37
+ | 注入漏洞 | `skill://web-security-guide/references/injection.md` |
38
+ | XSS攻击 | `skill://web-security-guide/references/xss.md` |
39
+ | 认证会话 | `skill://web-security-guide/references/auth-session.md` |
40
+ | 数据泄露 | `skill://web-security-guide/references/data-exposure.md` |
41
+ | 访问控制 | `skill://web-security-guide/references/access-control.md` |
42
+ | 配置错误 | `skill://web-security-guide/references/security-config.md` |
43
+ | CSRF | `skill://web-security-guide/references/csrf.md` |
44
+ | 反序列化 | `skill://web-security-guide/references/deserialization.md` |
45
+ | SSRF | `skill://web-security-guide/references/ssrf.md` |
46
+ | 日志监控 | `skill://web-security-guide/references/logging-monitoring.md` |
47
+
48
+ > 💡 先用速查表定位问题,再按需加载详细文档
@@ -0,0 +1,123 @@
1
+ # 访问控制缺失
2
+
3
+ ## 1. 漏洞原理
4
+
5
+ - 访问控制缺失(Broken Access Control)是指应用未对用户访问的功能或资源进行严格的 身份认证与权限校验,导致攻击者可以越权访问、操作他人数据或调用敏感功能。
6
+
7
+ - 常见问题:
8
+ - 鉴权仅在前端或网关,后端未做校验。
9
+ - ID 可控(IDOR,Insecure Direct Object Reference)。
10
+ - 垂直越权(普通用户可调用管理员接口)。
11
+ - 鉴权逻辑存在绕过漏洞(路径编码、大小写、截断)。
12
+
13
+ ## 2. 漏洞影响
14
+
15
+ - 水平越权:攻击者可读取/修改其他用户的数据(如查看他人订单、转账记录)。
16
+ - 垂直越权:普通用户可调用管理员功能(如创建用户、删除数据)。
17
+ - 内部绕过:通过内网直连后端,绕过网关鉴权。
18
+ - 逻辑绕过:利用路径大小写、编码差异,绕过黑名单/路径匹配规则。
19
+
20
+ ## 3. 典型业务场景
21
+
22
+ ### 3.1 功能隐藏在前端 UI,但后端未鉴权
23
+
24
+ - 前端页面隐藏"导出数据"按钮,但后端接口 /admin/export 无鉴权。
25
+ - 攻击者直接访问接口即可导出敏感数据。
26
+
27
+ ### 3.2 API 可越权访问其他用户数据(IDOR)
28
+
29
+ - URL 参数可控:/api/user/profile?id=1002。
30
+ - 用户 A 修改参数即可获取用户 B 的信息。
31
+
32
+ ```
33
+ GET /api/user/profile?id=1001 # 合法
34
+ GET /api/user/profile?id=1002 # 越权读取
35
+ ```
36
+
37
+ ### 3.3 水平越权:用户可修改 URL 参数访问他人资源
38
+
39
+ - 类似 IDOR,但更广:订单、合同、文件下载接口。
40
+ - 攻击者通过修改 URL order_id=xxx,获取他人订单详情。
41
+
42
+ ### 3.4 垂直越权:普通用户调用管理员接口
43
+
44
+ - 普通用户调用 /admin/deleteUser。
45
+ - 若仅靠前端按钮控制权限,后端无校验,则直接越权成功。
46
+
47
+ ### 3.5 鉴权逻辑仅在网关,后端未鉴权
48
+
49
+ - API Gateway / Nginx 配置了鉴权规则,但后端服务自身无鉴权。
50
+ - 攻击者通过 SSRF / 内网跳板 直连后端,绕过网关调用接口。
51
+
52
+ ```
53
+ # 外网访问被网关阻挡
54
+ GET https://api.example.com/admin/deleteUser?id=123 -> 403 Forbidden
55
+
56
+ # 内网直连绕过网关
57
+ GET http://10.0.0.5:8080/admin/deleteUser?id=123 -> 200 OK
58
+ ```
59
+
60
+ ### 3.6 鉴权逻辑被编码/截断/大小写绕过
61
+
62
+ - 仅拦截 /admin/,但攻击者用 /admin%2F、/Admin、/admin;.jsp 绕过。
63
+
64
+ ```java
65
+ // Bad:基于 startsWith() 的字符串判断
66
+ if (uri.startsWith("/admin")) {
67
+ checkAdmin();
68
+ }
69
+ // 绕过:双编码
70
+ GET /admin%2fdeleteUser?id=1 -> 绕过鉴权
71
+ ```
72
+
73
+ ## 4. 漏洞修复方案
74
+
75
+ ### 4.1 【必须】所有权限校验在后端完成
76
+
77
+ - 不依赖前端按钮或网关规则,后端每个接口都必须有鉴权逻辑。
78
+
79
+ ### 4.2 【必须】资源级/行级权限控制(user_id/tenant_id)
80
+
81
+ - 在数据查询层面增加 user_id/tenant_id 条件,保证只能访问自己的数据。
82
+
83
+ ```python
84
+ # Bad Code: 根据传入 ID 查询
85
+ User findUser(Long id);
86
+ ```
87
+
88
+ ```python
89
+ # Good Code: 限制为当前登录用户
90
+ User findUserByIdAndTenant(Long id, Long tenantId);
91
+ ```
92
+
93
+ ### 4.3 【必须】敏感接口必须加角色/权限控制注解
94
+
95
+ - Spring Security: @PreAuthorize("hasRole('ADMIN')")
96
+ - Django: @permission_required("app.delete_user")
97
+
98
+ ### 4.4 【建议】使用统一的 RBAC/ABAC 框架
99
+
100
+ - 统一鉴权框架,避免业务线各自实现,减少漏鉴权。
101
+
102
+ ### 4.5 【必须】后端服务自身必须做鉴权,不能仅依赖网关
103
+
104
+ - 网关鉴权是 第一道防线,后端鉴权是 最后一道防线。
105
+
106
+ ### 4.6 【建议】服务间调用采用 mTLS / JWT / API Key
107
+
108
+ - 即使是内网调用,也要有身份凭证,避免伪造请求。
109
+
110
+ ### 4.7 【必须】统一路径规范化再鉴权
111
+
112
+ - URL 统一大小写、解码、normalize 后再匹配。
113
+
114
+ ```java
115
+ // Good Code: Spring Security 推荐方式
116
+ http.authorizeHttpRequests()
117
+ .requestMatchers("/admin/**").hasRole("ADMIN")
118
+ .anyRequest().authenticated();
119
+ ```
120
+
121
+ ### 4.8 【建议】敏感操作二次确认
122
+
123
+ - 如转账、删号、权限变更,需要二次验证码/密码确认。
@@ -0,0 +1,99 @@
1
+ # 认证和会话管理不当
2
+
3
+ ## 1. 漏洞原理
4
+
5
+ - 认证和会话管理不当指应用程序在登录验证、身份令牌(如JWT、SessionID)、Cookie配置等关键身份凭据的生成、传输、验证过程中存在设计或实现缺陷,导致攻击者可以冒充合法用户或维持非法会话。
6
+
7
+ ## 2. 漏洞影响
8
+
9
+ - 账户暴力破解:登录接口无限制尝试密码
10
+ - Token猜解/重放:弱Token或无过期机制导致账号被劫持
11
+ - 会话劫持:Cookie 被JS或中间人窃取
12
+ - 权限穿越:身份伪造后访问其他用户数据或管理接口
13
+ - 长时间控制:Token 永不过期、用户退出无效化
14
+
15
+ ## 3. 典型业务场景
16
+
17
+ ### 3.1 登录未限速或缺验证码(暴力破解)
18
+
19
+ - 漏洞示例代码如下:
20
+
21
+ ```python
22
+ # Flask 示例:无限尝试登录
23
+ @app.route('/login', methods=['POST'])
24
+ def login():
25
+ username = request.form['user']
26
+ password = request.form['pass']
27
+ if check_user(username, password):
28
+ return 'login ok'
29
+ else:
30
+ return 'fail'
31
+ ```
32
+
33
+ ### 3.2 Token 可预测或未过期(重放攻击)
34
+
35
+ - 漏洞示例代码如下:
36
+
37
+ ```python
38
+ # 使用时间戳或用户名作为token
39
+ token = hashlib.md5(username.encode() + str(time.time()).encode()).hexdigest()
40
+ ```
41
+
42
+ ### 3.3 Cookie 未设置 HttpOnly / Secure / SameSite(被盗用)
43
+
44
+ - 漏洞示例代码如下:
45
+
46
+ ```python
47
+ # Flask 设置 cookie 时未加 HttpOnly / Secure
48
+ resp.set_cookie('session_id', session_id)
49
+ ```
50
+
51
+ - 修复建议:
52
+
53
+ ```python
54
+ resp.set_cookie('session_id', session_id,
55
+ httponly=True, # 防止JS读取
56
+ secure=True, # 仅HTTPS传输
57
+ samesite='Strict') # 防止跨站携带
58
+ ```
59
+
60
+ ### 3.4 JWT 签名绕过或私钥泄露
61
+
62
+ - 使用不安全的算法,如 alg: none
63
+ - JWT 密钥泄露、使用弱秘钥(如 test、123456)
64
+
65
+ ### 3.5 用户登出无效,旧会话仍可用
66
+
67
+ - JWT/Session未绑定设备信息,登出后未销毁旧 token,攻击者可长期使用
68
+
69
+ ## 4. 漏洞修复方案
70
+
71
+ ### 4.1 【必须】使用强随机 Token + 签名验证机制
72
+
73
+ - 使用 secrets、uuid4、os.urandom 生成随机Token
74
+ - JWT等结构化Token需添加签名 + 加密 + 时效控制
75
+ - 明确算法算法配置(HS256、RS256),禁用"none"
76
+
77
+ ### 4.2 【必须】Token 设置过期时间并支持吊销
78
+
79
+ - Access Token 推荐有效期 ≤ 15分钟
80
+ - Refresh Token 设置较长时间,并限制单设备有效
81
+ - 可在 Redis 维护 blacklist、revoked 状态表
82
+
83
+ ### 4.3 【必须】配置 Cookie 安全属性
84
+
85
+ - 开启HttpOnly:禁止 JS 读取 cookie
86
+ - Secure:仅在 HTTPS 下传输
87
+ - SameSite=Strict 阻止第三方携带 Cookie 发起请求
88
+
89
+ ### 4.4 【必须】登录限速 + 验证码策略
90
+
91
+ - IP维度/账号维度做登录次数限制
92
+ - 多次失败需冷却或触发验证码
93
+ - 应记录登录日志并告警异常登录行为
94
+
95
+ ### 4.5 【建议】用户绑定多端设备与会话管理
96
+
97
+ - 多终端登录记录中应显示设备、IP、登录时间
98
+ - 后台可选择"踢出其他设备"、"只允许单端登录"
99
+ - 所有 token 使用者身份变化时强制刷新
@@ -0,0 +1,59 @@
1
+ # 跨站请求伪造(CSRF)
2
+
3
+ ## 1. 漏洞原理
4
+
5
+ - 跨站请求伪造(Cross-Site Request Forgery, CSRF),是指攻击者诱导已登录的用户,在不知情的情况下向受信任站点发起恶意请求,从而执行敏感操作。
6
+ - 本质:应用只依赖 Cookie/Session 等隐式凭证鉴权,而未绑定用户意图(缺乏额外验证),导致用户在第三方页面访问时也能"自动带上凭证"。
7
+
8
+ ## 2. 漏洞影响
9
+
10
+ - 用户账户被盗用:攻击者可伪造请求修改用户信息、邮箱、密码。
11
+ - 金融类业务损失:伪造转账、支付、购买请求。
12
+ - 权限维持与系统破坏:攻击者可在后台添加管理员、开启恶意配置。
13
+ - 长期隐患:攻击可通过钓鱼站点、广告投放、论坛嵌入图片等途径批量触发。
14
+
15
+ ## 3. 典型业务场景
16
+
17
+ ### 3.1 用户已登录,访问恶意站点触发转账/改密
18
+
19
+ - 攻击者在钓鱼网站放置隐藏表单或图片:
20
+
21
+ ```html
22
+ <img src="https://bank.com/transfer?to=attacker&amount=1000">
23
+ ```
24
+
25
+ - 如果银行网站仅依赖 Cookie 鉴权,用户已登录时就会直接完成转账。
26
+
27
+ ### 3.2 使用 GET 请求执行敏感操作
28
+
29
+ - 系统用 GET 请求处理改密:
30
+
31
+ ```
32
+ https://example.com/resetpwd?new=123456
33
+ ```
34
+
35
+ - 攻击者只需诱导点击链接即可完成修改。
36
+
37
+ ### 3.3 未校验 Origin/Referer
38
+
39
+ - 后端只依赖 Cookie 验证,未检查请求来源,导致任意第三方页面可发起敏感请求。
40
+
41
+ ## 4. 漏洞修复方案
42
+
43
+ ### 4.1 【必须】启用 CSRF Token / 双提交 Cookie
44
+
45
+ - 后端生成随机 Token,绑定到用户会话,在表单或请求头中附带,后端验证一致性。
46
+ - 双提交 Cookie 模式:前端 JS 写入 Cookie 和请求参数,后端校验两者一致。
47
+
48
+ ### 4.2 【必须】敏感操作使用 POST/PUT/DELETE
49
+
50
+ - 禁止使用 GET 请求执行转账、改密、删除等操作。
51
+
52
+ ### 4.3 【必须】校验 Origin/Referer 请求头
53
+
54
+ - 服务端必须验证请求来源域名与白名单匹配。
55
+ - 对跨域请求强制使用 CORS 配置。
56
+
57
+ ### 4.4 【建议】关键操作需二次确认(验证码/密码输入)
58
+
59
+ - 转账、改密等高风险操作要求再次输入验证码或密码,增加攻击难度。