File size: 39,145 Bytes
c8d30bc
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
# tools/cwe_database.py
# MITRE CWE ้›ข็ทš่ณ‡ๆ–™ๅบซ โ€” ThreatHunter ๅฏไฟกไฝ่ญ‰ไพ†ๆบ
#
# ไพ†ๆบ๏ผšMITRE CWE v4.14๏ผˆhttps://cwe.mitre.org/๏ผ‰
# ๆณจๆ„๏ผšๆญคๆช”ๆกˆๅ…งๅฎนไพ†่‡ช MITRE ๅฎ˜ๆ–นๅฎš็พฉ๏ผŒ้ž LLM ็”Ÿๆˆ
# ๆ›ดๆ–ฐๆ—ฅๆœŸ๏ผš2026-04-21
#
# ็”จ้€”๏ผš
#   ็•ถ Security Guard ๅตๆธฌๅˆฐ code pattern ๆ™‚๏ผŒ
#   ๅผ•็”จๆญค่ณ‡ๆ–™ๅบซๆไพ›ๅฎ˜ๆ–นๅฎš็พฉใ€NIST ๅšด้‡ๆ€งใ€OWASP ๅฐๆ‡‰ใ€ไฟฎๅพฉๅปบ่ญฐ
#   ไปฅๅŠไปฃ่กจๆ€ง CVE๏ผˆๅŒ้กžๅผฑ้ปž็œŸๅฏฆ่ขซๅˆฉ็”จๆกˆไพ‹๏ผ‰ใ€‚
#
# ้‡่ฆๅ…่ฒฌ่ฒๆ˜Ž๏ผš
#   ไปฃ่กจๆ€ง CVE ไธไปฃ่กจ็”จๆˆถ็š„็จ‹ๅผ็ขผใ€Œๅฐฑๆ˜ฏใ€่ฉฒ CVE๏ผŒ
#   ่€Œๆ˜ฏใ€ŒๅŒ้กžๅผฑ้ปž่ขซๅˆฉ็”จ็š„็œŸๅฏฆๆกˆไพ‹ใ€๏ผŒ็”จๆ–ผ่ชชๆ˜Ž้ขจ้šชๅšด้‡ๆ€งใ€‚

from __future__ import annotations

import logging
from typing import Any

logger = logging.getLogger("ThreatHunter.cwe_database")

# โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•
# MITRE CWE ่ณ‡ๆ–™ๅบซ
# ๆฌ„ไฝ่ชชๆ˜Ž๏ผš
#   name            : CWE ็Ÿญๅ็จฑ
#   full_name       : MITRE ๅฎ˜ๆ–นๅฎŒๆ•ดๅ็จฑ
#   source          : ่ณ‡ๆ–™ไพ†ๆบ็‰ˆๆœฌ
#   nist_severity   : NIST ่ฉ•ๅฎšๅšด้‡็ญ‰็ดš
#   cvss_base       : ๅ…ธๅž‹ CVSS v3.1 ๅŸบ็คŽๅˆ†ๆ•ธ๏ผˆไพ†่‡ช NVD ็ตฑ่จˆ๏ผ‰
#   owasp_2021      : OWASP Top 10 2021 ๅฐๆ‡‰
#   cwe_url         : MITRE ๅฎ˜ๆ–น URL
#   description     : ๅฎ˜ๆ–นๅฎš็พฉๆ‘˜่ฆ๏ผˆ่‹ฑๆ–‡๏ผŒMITRE ๅŽŸๆ–‡๏ผ‰
#   remediation_en  : ่‹ฑๆ–‡ไฟฎๅพฉๅปบ่ญฐ
#   remediation_zh  : ไธญๆ–‡ไฟฎๅพฉๅปบ่ญฐ
#   representative_cves : ไปฃ่กจๆ€ง CVE๏ผˆ็œŸๅฏฆๆกˆไพ‹๏ผŒ้ž็”จๆˆถ็จ‹ๅผ็ขผ็š„็›ดๆŽฅๆ˜ ๅฐ„๏ผ‰
# โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•

CWE_DATABASE: dict[str, dict[str, Any]] = {

    # โ”€โ”€ ๆณจๅ…ฅ้กž (Injection) โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€

    "CWE-89": {
        "name": "SQL Injection",
        "full_name": "Improper Neutralization of Special Elements used in an SQL Command",
        "source": "MITRE CWE v4.14",
        "nist_severity": "HIGH",
        "cvss_base": 8.1,
        "owasp_2021": "A03:2021 โ€“ Injection",
        "cwe_url": "https://cwe.mitre.org/data/definitions/89.html",
        "description": (
            "Without sufficient removal or quoting of SQL syntax in user-controllable inputs, "
            "the generated SQL query can cause those inputs to be interpreted as SQL instead of "
            "ordinary user data. This can be used to alter query logic to bypass authentication, "
            "retrieve, modify, or delete data."
        ),
        "remediation_en": "Use parameterized queries (prepared statements). Never concatenate user input into SQL strings.",
        "remediation_zh": "ไฝฟ็”จๅƒๆ•ธๅŒ–ๆŸฅ่ฉข๏ผˆPrepared Statements๏ผ‰ใ€‚็ต•ไธๅฐ‡็”จๆˆถ่ผธๅ…ฅ็›ดๆŽฅๆ‹ผๆŽฅ้€ฒ SQL ๅญ—ไธฒใ€‚",
        "representative_cves": [
            {"id": "CVE-2023-23752", "cvss": 7.5, "vendor": "Joomla", "year": 2023,
             "note": "Improper access checks allow SQL injection via URL parameter"},
            {"id": "CVE-2022-21661", "cvss": 7.5, "vendor": "WordPress", "year": 2022,
             "note": "SQL injection via WP_Query in core component"},
            {"id": "CVE-2023-40028", "cvss": 8.8, "vendor": "Ghost CMS", "year": 2023,
             "note": "SQL injection leading to data exposure"},
        ],
    },

    "CWE-78": {
        "name": "OS Command Injection",
        "full_name": "Improper Neutralization of Special Elements used in an OS Command",
        "source": "MITRE CWE v4.14",
        "nist_severity": "CRITICAL",
        "cvss_base": 9.8,
        "owasp_2021": "A03:2021 โ€“ Injection",
        "cwe_url": "https://cwe.mitre.org/data/definitions/78.html",
        "description": (
            "The product constructs all or part of an OS command using externally-influenced input "
            "but does not neutralize elements that can modify the intended OS command, allowing "
            "attackers to execute arbitrary commands with the privileges of the vulnerable process."
        ),
        "remediation_en": "Avoid shell execution functions. Use language APIs that accept argument arrays (not strings).",
        "remediation_zh": "้ฟๅ…ไฝฟ็”จ shell ๅŸท่กŒๅ‡ฝๅผใ€‚ๆ”น็”จ่ชž่จ€ API ไธฆไปฅ้™ฃๅˆ—ๆ–นๅผๅ‚ณ้žๅƒๆ•ธ๏ผˆไธไฝฟ็”จๅญ—ไธฒๆ‹ผๆŽฅ๏ผ‰ใ€‚",
        "representative_cves": [
            {"id": "CVE-2021-44228", "cvss": 10.0, "vendor": "Apache Log4j", "year": 2021,
             "note": "JNDI injection leading to Remote Code Execution (Log4Shell)"},
            {"id": "CVE-2022-33891", "cvss": 8.8, "vendor": "Apache Spark", "year": 2022,
             "note": "Shell injection via HTTP query parameter"},
            {"id": "CVE-2023-44487", "cvss": 7.5, "vendor": "Multiple HTTP servers", "year": 2023,
             "note": "HTTP/2 Rapid Reset Attack enabling code execution"},
        ],
    },

    "CWE-77": {
        "name": "Command Injection",
        "full_name": "Improper Neutralization of Special Elements used in a Command",
        "source": "MITRE CWE v4.14",
        "nist_severity": "CRITICAL",
        "cvss_base": 9.8,
        "owasp_2021": "A03:2021 โ€“ Injection",
        "cwe_url": "https://cwe.mitre.org/data/definitions/77.html",
        "description": "The product constructs a command using externally-influenced input without proper neutralization.",
        "remediation_en": "Validate and whitelist all input. Use safe APIs instead of direct command execution.",
        "remediation_zh": "้ฉ—่ญ‰ไธฆ็™ฝๅๅ–ฎๅŒ–ๆ‰€ๆœ‰่ผธๅ…ฅใ€‚ไฝฟ็”จๅฎ‰ๅ…จ API ๆ›ฟไปฃ็›ดๆŽฅๅ‘ฝไปคๅŸท่กŒใ€‚",
        "representative_cves": [
            {"id": "CVE-2021-44228", "cvss": 10.0, "vendor": "Apache Log4j", "year": 2021,
             "note": "Command injection via JNDI lookup"},
        ],
    },

    "CWE-79": {
        "name": "Cross-Site Scripting (XSS)",
        "full_name": "Improper Neutralization of Input During Web Page Generation",
        "source": "MITRE CWE v4.14",
        "nist_severity": "MEDIUM",
        "cvss_base": 6.1,
        "owasp_2021": "A03:2021 โ€“ Injection",
        "cwe_url": "https://cwe.mitre.org/data/definitions/79.html",
        "description": (
            "The product does not neutralize or incorrectly neutralizes user-controllable input "
            "before it is placed in output that is used as a web page that is served to other users."
        ),
        "remediation_en": "Encode all output. Use Content Security Policy (CSP). Use framework's built-in escaping.",
        "remediation_zh": "ๅฐๆ‰€ๆœ‰่ผธๅ‡บ้€ฒ่กŒ HTML ็ทจ็ขผใ€‚ๅ•Ÿ็”จ CSPใ€‚ไฝฟ็”จๆก†ๆžถๅ…งๅปบ็š„ escape ๆฉŸๅˆถใ€‚",
        "representative_cves": [
            {"id": "CVE-2023-32235", "cvss": 6.1, "vendor": "WordPress Plugin", "year": 2023,
             "note": "Reflected XSS via unescaped URL parameter"},
            {"id": "CVE-2022-40082", "cvss": 5.4, "vendor": "Multiple CMS", "year": 2022,
             "note": "Stored XSS via input field"},
        ],
    },

    "CWE-80": {
        "name": "Basic XSS (Improper HTML Encoding)",
        "full_name": "Improper Neutralization of Script-Related HTML Tags in a Web Page",
        "source": "MITRE CWE v4.14",
        "nist_severity": "MEDIUM",
        "cvss_base": 5.4,
        "owasp_2021": "A03:2021 โ€“ Injection",
        "cwe_url": "https://cwe.mitre.org/data/definitions/80.html",
        "description": "The product does not neutralize or incorrectly neutralizes script tags in user input.",
        "remediation_en": "HTML-encode all user output using htmlspecialchars() or equivalent.",
        "remediation_zh": "ไฝฟ็”จ htmlspecialchars() ๆˆ–ๅŒ็ญ‰ๅ‡ฝๅผๅฐๆ‰€ๆœ‰็”จๆˆถ่ผธๅ‡บ้€ฒ่กŒ HTML ็ทจ็ขผใ€‚",
        "representative_cves": [
            {"id": "CVE-2023-32235", "cvss": 6.1, "vendor": "WordPress Plugin", "year": 2023,
             "note": "Script injection via unencoded output"},
        ],
    },

    "CWE-94": {
        "name": "Code Injection",
        "full_name": "Improper Control of Generation of Code",
        "source": "MITRE CWE v4.14",
        "nist_severity": "CRITICAL",
        "cvss_base": 9.8,
        "owasp_2021": "A03:2021 โ€“ Injection",
        "cwe_url": "https://cwe.mitre.org/data/definitions/94.html",
        "description": "User input is interpreted as executable code by the application.",
        "remediation_en": "Never use eval() or equivalent with user input. Use safe alternatives (JSON.parse, predefined mappings).",
        "remediation_zh": "็ต•ไธๅฐ็”จๆˆถ่ผธๅ…ฅไฝฟ็”จ eval()ใ€‚ไฝฟ็”จๅฎ‰ๅ…จๆ›ฟไปฃ๏ผˆJSON.parseใ€้ ๅฎš็พฉๆ˜ ๅฐ„๏ผ‰ใ€‚",
        "representative_cves": [
            {"id": "CVE-2021-41773", "cvss": 7.5, "vendor": "Apache HTTP Server", "year": 2021,
             "note": "Path traversal + code injection in CGI"},
        ],
    },

    "CWE-95": {
        "name": "Dynamic Code Evaluation (eval Injection)",
        "full_name": "Improper Neutralization of Directives in Dynamically Evaluated Code",
        "source": "MITRE CWE v4.14",
        "nist_severity": "CRITICAL",
        "cvss_base": 9.8,
        "owasp_2021": "A03:2021 โ€“ Injection",
        "cwe_url": "https://cwe.mitre.org/data/definitions/95.html",
        "description": (
            "The software receives input from an upstream component, but it does not neutralize "
            "codes in the input before using it as part of a dynamically-evaluated code."
        ),
        "remediation_en": "Remove all uses of eval() with dynamic input. Use JSON.parse() for data, or a switch/map for logic.",
        "remediation_zh": "็งป้™คๆ‰€ๆœ‰ๅฐๅ‹•ๆ…‹่ผธๅ…ฅ็š„ eval() ไฝฟ็”จใ€‚่ณ‡ๆ–™ๆ”น็”จ JSON.parse()๏ผŒ้‚่ผฏๆ”น็”จ switch/mapใ€‚",
        "representative_cves": [
            {"id": "CVE-2023-29017", "cvss": 10.0, "vendor": "vm2 (Node.js sandbox)", "year": 2023,
             "note": "Sandbox escape via eval injection leading to RCE"},
            {"id": "CVE-2021-22911", "cvss": 9.8, "vendor": "Rocket.Chat", "year": 2021,
             "note": "Server-side eval injection leading to RCE"},
        ],
    },

    "CWE-98": {
        "name": "PHP File Inclusion",
        "full_name": "Improper Control of Filename for Include/Require Statement in PHP",
        "source": "MITRE CWE v4.14",
        "nist_severity": "HIGH",
        "cvss_base": 8.8,
        "owasp_2021": "A03:2021 โ€“ Injection",
        "cwe_url": "https://cwe.mitre.org/data/definitions/98.html",
        "description": (
            "The PHP application receives input from an upstream component, but does not restrict "
            "or incorrectly restricts the input before its use in a require, include, or similar "
            "statement, allowing the web server to include and execute unintended PHP files."
        ),
        "remediation_en": "Use a strict whitelist of allowed filenames. Never use user input directly in include/require.",
        "remediation_zh": "ไฝฟ็”จๅšดๆ ผ็™ฝๅๅ–ฎ้™ๅˆถๅ…่จฑ็š„ๆช”ๆกˆๅ็จฑใ€‚็ต•ไธๅฐ‡็”จๆˆถ่ผธๅ…ฅ็›ดๆŽฅๅ‚ณๅ…ฅ include/requireใ€‚",
        "representative_cves": [
            {"id": "CVE-2023-23752", "cvss": 7.5, "vendor": "Joomla", "year": 2023,
             "note": "Improper access check leading to Local File Inclusion"},
            {"id": "CVE-2021-39165", "cvss": 9.8, "vendor": "Cachet", "year": 2021,
             "note": "Remote File Inclusion via template engine"},
        ],
    },

    "CWE-90": {
        "name": "LDAP Injection",
        "full_name": "Improper Neutralization of Special Elements used in an LDAP Query",
        "source": "MITRE CWE v4.14",
        "nist_severity": "HIGH",
        "cvss_base": 7.5,
        "owasp_2021": "A03:2021 โ€“ Injection",
        "cwe_url": "https://cwe.mitre.org/data/definitions/90.html",
        "description": "User-supplied input is incorporated into LDAP queries without sufficient sanitization.",
        "remediation_en": "Escape all special LDAP characters. Use parameterized LDAP queries.",
        "remediation_zh": "ๅฐๆ‰€ๆœ‰็‰นๆฎŠ LDAP ๅญ—ๅ…ƒ้€ฒ่กŒ่ฝ‰็พฉใ€‚ไฝฟ็”จๅƒๆ•ธๅŒ– LDAP ๆŸฅ่ฉขใ€‚",
        "representative_cves": [
            {"id": "CVE-2021-40539", "cvss": 9.8, "vendor": "ManageEngine", "year": 2021,
             "note": "LDAP injection enabling authentication bypass"},
        ],
    },

    "CWE-611": {
        "name": "XML External Entity (XXE)",
        "full_name": "Improper Restriction of XML External Entity Reference",
        "source": "MITRE CWE v4.14",
        "nist_severity": "HIGH",
        "cvss_base": 8.6,
        "owasp_2021": "A05:2021 โ€“ Security Misconfiguration",
        "cwe_url": "https://cwe.mitre.org/data/definitions/611.html",
        "description": (
            "The software processes an XML document that can contain XML entities with URIs that "
            "resolve to documents outside of the intended sphere of control, causing the product "
            "to embed incorrect documents into its output."
        ),
        "remediation_en": "Disable external entity processing in XML parser. Use allowlist of allowed entities.",
        "remediation_zh": "ๅœ็”จ XML ่งฃๆžๅ™จ็š„ๅค–้ƒจๅฏฆ้ซ”่™•็†ใ€‚ไฝฟ็”จๅ…่จฑ็š„ๅฏฆ้ซ”็™ฝๅๅ–ฎใ€‚",
        "representative_cves": [
            {"id": "CVE-2021-44228", "cvss": 10.0, "vendor": "Apache Log4j", "year": 2021,
             "note": "XXE via JNDI lookup in log messages"},
            {"id": "CVE-2022-21363", "cvss": 7.0, "vendor": "MySQL Connector/J", "year": 2022,
             "note": "XXE in XML data processing"},
        ],
    },

    # โ”€โ”€ ่ทฏๅพ‘่ˆ‡ๆ–‡ไปถๆ“ไฝœ โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€

    "CWE-22": {
        "name": "Path Traversal",
        "full_name": "Improper Limitation of a Pathname to a Restricted Directory",
        "source": "MITRE CWE v4.14",
        "nist_severity": "HIGH",
        "cvss_base": 7.5,
        "owasp_2021": "A01:2021 โ€“ Broken Access Control",
        "cwe_url": "https://cwe.mitre.org/data/definitions/22.html",
        "description": (
            "The software uses external input to construct a pathname that is intended to identify "
            "a file or directory located underneath a restricted parent directory, but does not "
            "properly neutralize special elements within the pathname that can cause it to resolve "
            "to a location outside of that directory."
        ),
        "remediation_en": "Canonicalize paths before validation. Validate against a strict whitelist of allowed paths.",
        "remediation_zh": "ๅœจ้ฉ—่ญ‰ๅ‰ๆญฃ่ฆๅŒ–่ทฏๅพ‘ใ€‚ไฝฟ็”จๅšดๆ ผ็™ฝๅๅ–ฎ้ฉ—่ญ‰ๅ…่จฑ็š„่ทฏๅพ‘ใ€‚",
        "representative_cves": [
            {"id": "CVE-2021-41773", "cvss": 7.5, "vendor": "Apache HTTP Server", "year": 2021,
             "note": "Path traversal allowing arbitrary file read"},
            {"id": "CVE-2022-22965", "cvss": 9.8, "vendor": "Spring Framework", "year": 2022,
             "note": "Spring4Shell: path traversal leading to RCE"},
        ],
    },

    "CWE-73": {
        "name": "External Control of File Name or Path",
        "full_name": "External Control of File Name or Path",
        "source": "MITRE CWE v4.14",
        "nist_severity": "HIGH",
        "cvss_base": 7.5,
        "owasp_2021": "A01:2021 โ€“ Broken Access Control",
        "cwe_url": "https://cwe.mitre.org/data/definitions/73.html",
        "description": "The software allows user input to control or influence paths used in filesystem operations.",
        "remediation_en": "Use a whitelist of allowed filenames. Sanitize directory separator characters.",
        "remediation_zh": "ไฝฟ็”จๅ…่จฑ็š„ๆช”ๆกˆๅ็จฑ็™ฝๅๅ–ฎใ€‚้Žๆฟพ็›ฎ้Œ„ๅˆ†้š”ๅญ—ๅ…ƒใ€‚",
        "representative_cves": [
            {"id": "CVE-2021-41773", "cvss": 7.5, "vendor": "Apache HTTP Server", "year": 2021,
             "note": "File path control leading to arbitrary file access"},
        ],
    },

    "CWE-134": {
        "name": "Uncontrolled Format String",
        "full_name": "Use of Externally-Controlled Format String",
        "source": "MITRE CWE v4.14",
        "nist_severity": "HIGH",
        "cvss_base": 8.1,
        "owasp_2021": "A03:2021 โ€“ Injection",
        "cwe_url": "https://cwe.mitre.org/data/definitions/134.html",
        "description": "User input is used as a format string in functions like printf, allowing memory read/write.",
        "remediation_en": "Always use a literal format string. Never pass user input directly as the format argument.",
        "remediation_zh": "ๆฐธ้ ไฝฟ็”จๅญ—้ขๆ ผๅผๅญ—ไธฒใ€‚็ต•ไธๅฐ‡็”จๆˆถ่ผธๅ…ฅ็›ดๆŽฅไฝœ็‚บๆ ผๅผๅƒๆ•ธๅ‚ณๅ…ฅใ€‚",
        "representative_cves": [
            {"id": "CVE-2021-3156", "cvss": 7.8, "vendor": "sudo", "year": 2021,
             "note": "Heap-based buffer overflow via format string (Baron Samedit)"},
        ],
    },

    # โ”€โ”€ ๅๅบๅˆ—ๅŒ–่ˆ‡็จ‹ๅผๅฎŒๆ•ดๆ€ง โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€

    "CWE-502": {
        "name": "Deserialization of Untrusted Data",
        "full_name": "Deserialization of Untrusted Data",
        "source": "MITRE CWE v4.14",
        "nist_severity": "CRITICAL",
        "cvss_base": 9.8,
        "owasp_2021": "A08:2021 โ€“ Software and Data Integrity Failures",
        "cwe_url": "https://cwe.mitre.org/data/definitions/502.html",
        "description": (
            "The application deserializes untrusted data without sufficiently verifying that the "
            "resulting data will be valid, allowing attackers to control the state or flow of "
            "execution, and potentially execute arbitrary code."
        ),
        "remediation_en": "Use safe data formats (JSON). Implement class allowlisting. Sign serialized data.",
        "remediation_zh": "ไฝฟ็”จๅฎ‰ๅ…จ็š„่ณ‡ๆ–™ๆ ผๅผ๏ผˆJSON๏ผ‰ใ€‚ๅฏฆไฝœ้กžๅˆฅ็™ฝๅๅ–ฎใ€‚ๅฐๅบๅˆ—ๅŒ–่ณ‡ๆ–™้€ฒ่กŒ็ฐฝๅใ€‚",
        "representative_cves": [
            {"id": "CVE-2018-2628", "cvss": 9.8, "vendor": "Oracle WebLogic", "year": 2018,
             "note": "Java deserialization RCE via T3 protocol"},
            {"id": "CVE-2017-9248", "cvss": 9.8, "vendor": "Telerik UI", "year": 2017,
             "note": ".NET deserialization leading to RCE"},
            {"id": "CVE-2022-22947", "cvss": 10.0, "vendor": "Spring Cloud Gateway", "year": 2022,
             "note": "Code injection via SPEL in actuator endpoint"},
        ],
    },

    "CWE-494": {
        "name": "Download of Code Without Integrity Check",
        "full_name": "Download of Code Without Integrity Check",
        "source": "MITRE CWE v4.14",
        "nist_severity": "HIGH",
        "cvss_base": 8.1,
        "owasp_2021": "A08:2021 โ€“ Software and Data Integrity Failures",
        "cwe_url": "https://cwe.mitre.org/data/definitions/494.html",
        "description": "The product downloads source code or an executable from a remote location without verifying its integrity.",
        "remediation_en": "Verify checksums/signatures before execution. Use HTTPS. Pin dependency versions.",
        "remediation_zh": "ๅŸท่กŒๅ‰้ฉ—่ญ‰ๆ ก้ฉ—ๅ’Œ/็ฐฝๅใ€‚ไฝฟ็”จ HTTPSใ€‚้Ž–ๅฎšไพ่ณด็‰ˆๆœฌใ€‚",
        "representative_cves": [
            {"id": "CVE-2022-3602", "cvss": 7.5, "vendor": "OpenSSL", "year": 2022,
             "note": "Certificate verification bypass enabling MitM"},
        ],
    },

    # โ”€โ”€ ๆ•ๆ„Ÿ่ณ‡ๆ–™ๆšด้œฒ โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€

    "CWE-312": {
        "name": "Cleartext Storage of Sensitive Information",
        "full_name": "Cleartext Storage of Sensitive Information",
        "source": "MITRE CWE v4.14",
        "nist_severity": "MEDIUM",
        "cvss_base": 5.5,
        "owasp_2021": "A02:2021 โ€“ Cryptographic Failures",
        "cwe_url": "https://cwe.mitre.org/data/definitions/312.html",
        "description": "Sensitive information (passwords, keys, PII) is stored in cleartext.",
        "remediation_en": "Encrypt sensitive data at rest. Use hardware security modules for keys.",
        "remediation_zh": "ๅŠ ๅฏ†้œๆ…‹ๆ•ๆ„Ÿ่ณ‡ๆ–™ใ€‚ไฝฟ็”จ็กฌ้ซ”ๅฎ‰ๅ…จๆจก็ต„็ฎก็†้‡‘้‘ฐใ€‚",
        "representative_cves": [
            {"id": "CVE-2023-27163", "cvss": 7.5, "vendor": "request-baskets", "year": 2023,
             "note": "SSRF exposing internal credentials in cleartext"},
        ],
    },

    "CWE-200": {
        "name": "Exposure of Sensitive Information",
        "full_name": "Exposure of Sensitive Information to an Unauthorized Actor",
        "source": "MITRE CWE v4.14",
        "nist_severity": "MEDIUM",
        "cvss_base": 5.3,
        "owasp_2021": "A02:2021 โ€“ Cryptographic Failures",
        "cwe_url": "https://cwe.mitre.org/data/definitions/200.html",
        "description": "The product exposes sensitive information to an actor that is not explicitly authorized to access it.",
        "remediation_en": "Apply least-privilege principle. Audit error messages and logs for sensitive data leakage.",
        "remediation_zh": "ๆ‡‰็”จๆœ€ๅฐๆฌŠ้™ๅŽŸๅ‰‡ใ€‚ๅฏฉๆ ธ้Œฏ่ชค่จŠๆฏๅ’Œๆ—ฅ่ชŒไธญ็š„ๆ•ๆ„Ÿ่ณ‡ๆ–™ๆดฉๆผใ€‚",
        "representative_cves": [
            {"id": "CVE-2023-23752", "cvss": 7.5, "vendor": "Joomla", "year": 2023,
             "note": "Unauthorized information disclosure via REST API"},
        ],
    },

    "CWE-798": {
        "name": "Use of Hard-coded Credentials",
        "full_name": "Use of Hard-coded Credentials",
        "source": "MITRE CWE v4.14",
        "nist_severity": "CRITICAL",
        "cvss_base": 9.8,
        "owasp_2021": "A07:2021 โ€“ Identification and Authentication Failures",
        "cwe_url": "https://cwe.mitre.org/data/definitions/798.html",
        "description": "The software contains hard-coded credentials such as passwords or cryptographic keys.",
        "remediation_en": "Remove all hard-coded credentials. Use environment variables or secret management systems.",
        "remediation_zh": "็งป้™คๆ‰€ๆœ‰็กฌ็ทจ็ขผๆ†‘่ญ‰ใ€‚ๆ”น็”จ็’ฐๅขƒ่ฎŠๆ•ธๆˆ–ๅฏ†้‘ฐ็ฎก็†็ณป็ตฑ๏ผˆVaultใ€AWS Secrets Manager ็ญ‰๏ผ‰ใ€‚",
        "representative_cves": [
            {"id": "CVE-2022-29303", "cvss": 9.8, "vendor": "SolarView Compact", "year": 2022,
             "note": "Hard-coded credentials enabling backdoor access"},
            {"id": "CVE-2021-20090", "cvss": 9.8, "vendor": "Buffalo Router", "year": 2021,
             "note": "Hard-coded admin credentials"},
        ],
    },

    # โ”€โ”€ ๅŠ ๅฏ†ๅผฑ้ปž โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€

    "CWE-326": {
        "name": "Inadequate Encryption Strength",
        "full_name": "Inadequate Encryption Strength",
        "source": "MITRE CWE v4.14",
        "nist_severity": "MEDIUM",
        "cvss_base": 5.9,
        "owasp_2021": "A02:2021 โ€“ Cryptographic Failures",
        "cwe_url": "https://cwe.mitre.org/data/definitions/326.html",
        "description": "The software stores or transmits sensitive data using an algorithm that is insufficiently strong given current conditions.",
        "remediation_en": "Use AES-256 for symmetric encryption. Use RSA-2048+ or ECC P-256+ for asymmetric. Avoid MD5, SHA-1, DES.",
        "remediation_zh": "ๅฐ็จฑๅŠ ๅฏ†ไฝฟ็”จ AES-256ใ€‚้žๅฐ็จฑไฝฟ็”จ RSA-2048+ ๆˆ– ECC P-256+ใ€‚้ฟๅ… MD5ใ€SHA-1ใ€DESใ€‚",
        "representative_cves": [
            {"id": "CVE-2022-3602", "cvss": 7.5, "vendor": "OpenSSL", "year": 2022,
             "note": "Inadequate certificate verification"},
        ],
    },

    "CWE-295": {
        "name": "Improper Certificate Validation",
        "full_name": "Improper Certificate Validation",
        "source": "MITRE CWE v4.14",
        "nist_severity": "HIGH",
        "cvss_base": 7.4,
        "owasp_2021": "A02:2021 โ€“ Cryptographic Failures",
        "cwe_url": "https://cwe.mitre.org/data/definitions/295.html",
        "description": "The software does not validate, or incorrectly validates, a certificate.",
        "remediation_en": "Enable full certificate chain validation. Pin certificates for high-value connections.",
        "remediation_zh": "ๅ•Ÿ็”จๅฎŒๆ•ด็š„ๆ†‘่ญ‰้ˆ้ฉ—่ญ‰ใ€‚ๅฐ้ซ˜ๅƒนๅ€ผ้€ฃ็ทšไฝฟ็”จๆ†‘่ญ‰้Ž–ๅฎš๏ผˆCertificate Pinning๏ผ‰ใ€‚",
        "representative_cves": [
            {"id": "CVE-2021-3449", "cvss": 5.9, "vendor": "OpenSSL", "year": 2021,
             "note": "NULL pointer dereference during certificate validation"},
        ],
    },

    # โ”€โ”€ ๅญ˜ๅ–ๆŽงๅˆถ โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€

    "CWE-862": {
        "name": "Missing Authorization",
        "full_name": "Missing Authorization",
        "source": "MITRE CWE v4.14",
        "nist_severity": "HIGH",
        "cvss_base": 8.8,
        "owasp_2021": "A01:2021 โ€“ Broken Access Control",
        "cwe_url": "https://cwe.mitre.org/data/definitions/862.html",
        "description": "The software does not perform an authorization check when an actor attempts to access a resource or perform an action.",
        "remediation_en": "Implement authorization checks on every endpoint. Use deny-by-default policy.",
        "remediation_zh": "ๅœจๆฏๅ€‹็ซฏ้ปžๅฏฆไฝœๆŽˆๆฌŠๆชขๆŸฅใ€‚ไฝฟ็”จ้ ่จญๆ‹’็ต•็ญ–็•ฅใ€‚",
        "representative_cves": [
            {"id": "CVE-2023-23752", "cvss": 7.5, "vendor": "Joomla", "year": 2023,
             "note": "Missing authorization allowing data access"},
            {"id": "CVE-2022-27096", "cvss": 8.8, "vendor": "Multiple Web Apps", "year": 2022,
             "note": "Broken access control leading to privilege escalation"},
        ],
    },

    "CWE-287": {
        "name": "Improper Authentication",
        "full_name": "Improper Authentication",
        "source": "MITRE CWE v4.14",
        "nist_severity": "CRITICAL",
        "cvss_base": 9.8,
        "owasp_2021": "A07:2021 โ€“ Identification and Authentication Failures",
        "cwe_url": "https://cwe.mitre.org/data/definitions/287.html",
        "description": "When an actor claims to have a given identity, the software does not prove or insufficiently proves that the claim is correct.",
        "remediation_en": "Use strong multi-factor authentication. Validate session tokens properly.",
        "remediation_zh": "ไฝฟ็”จๅผทๅคšๅ› ็ด ่ช่ญ‰ใ€‚ๆญฃ็ขบ้ฉ—่ญ‰ Session Tokenใ€‚",
        "representative_cves": [
            {"id": "CVE-2022-35405", "cvss": 9.8, "vendor": "Zoho ManageEngine", "year": 2022,
             "note": "Authentication bypass via improper validation"},
        ],
    },

    "CWE-306": {
        "name": "Missing Authentication for Critical Function",
        "full_name": "Missing Authentication for Critical Function",
        "source": "MITRE CWE v4.14",
        "nist_severity": "CRITICAL",
        "cvss_base": 9.8,
        "owasp_2021": "A07:2021 โ€“ Identification and Authentication Failures",
        "cwe_url": "https://cwe.mitre.org/data/definitions/306.html",
        "description": "The software does not perform any authentication for functionality that requires a provable user identity.",
        "remediation_en": "Require authentication for all sensitive operations. Implement zero-trust model.",
        "remediation_zh": "ๆ‰€ๆœ‰ๆ•ๆ„Ÿๆ“ไฝœ้ƒฝ่ฆๆฑ‚่ช่ญ‰ใ€‚ๅฏฆไฝœ้›ถไฟกไปปๆจกๅž‹ใ€‚",
        "representative_cves": [
            {"id": "CVE-2021-20090", "cvss": 9.8, "vendor": "Buffalo Network Device", "year": 2021,
             "note": "Authentication bypass allowing unauthorized access"},
        ],
    },

    # โ”€โ”€ ้–‹ๆ”พ้‡ๅฎšๅ‘่ˆ‡ SSRF โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€

    "CWE-601": {
        "name": "Open Redirect",
        "full_name": "URL Redirection to Untrusted Site",
        "source": "MITRE CWE v4.14",
        "nist_severity": "MEDIUM",
        "cvss_base": 6.1,
        "owasp_2021": "A01:2021 โ€“ Broken Access Control",
        "cwe_url": "https://cwe.mitre.org/data/definitions/601.html",
        "description": "The web application accepts a user-controlled input that specifies a link to an external site, and uses that link in a Redirect.",
        "remediation_en": "Use a whitelist of allowed redirect URLs. Avoid using user input in redirect destinations.",
        "remediation_zh": "ไฝฟ็”จๅ…่จฑ็š„้‡ๅฎšๅ‘ URL ็™ฝๅๅ–ฎใ€‚้ฟๅ…ๅœจ้‡ๅฎšๅ‘็›ฎๆจ™ไธญไฝฟ็”จ็”จๆˆถ่ผธๅ…ฅใ€‚",
        "representative_cves": [
            {"id": "CVE-2023-33246", "cvss": 7.5, "vendor": "Apache RocketMQ", "year": 2023,
             "note": "Open redirect enabling phishing attacks"},
        ],
    },

    "CWE-918": {
        "name": "Server-Side Request Forgery (SSRF)",
        "full_name": "Server-Side Request Forgery (SSRF)",
        "source": "MITRE CWE v4.14",
        "nist_severity": "HIGH",
        "cvss_base": 8.6,
        "owasp_2021": "A10:2021 โ€“ Server-Side Request Forgery",
        "cwe_url": "https://cwe.mitre.org/data/definitions/918.html",
        "description": "The server can be induced to make requests to unintended locations, including internal network services.",
        "remediation_en": "Validate and whitelist URLs. Block access to internal IP ranges. Disable unnecessary URL schemes.",
        "remediation_zh": "้ฉ—่ญ‰ไธฆ็™ฝๅๅ–ฎๅŒ– URLใ€‚ๅฐ้Ž–ๅฐๅ…ง้ƒจ IP ็ฏ„ๅœ็š„ๅญ˜ๅ–ใ€‚ๅœ็”จไธๅฟ…่ฆ็š„ URL ๅ”ๅฎšใ€‚",
        "representative_cves": [
            {"id": "CVE-2023-27163", "cvss": 7.5, "vendor": "request-baskets", "year": 2023,
             "note": "SSRF allowing internal network access"},
            {"id": "CVE-2019-8451", "cvss": 6.8, "vendor": "Jira", "year": 2019,
             "note": "SSRF via IconUriServlet endpoint"},
        ],
    },

    # โ”€โ”€ ่จ˜ๆ†ถ้ซ”่ˆ‡่ณ‡ๆบๅ•้กŒ โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€

    "CWE-119": {
        "name": "Buffer Overflow",
        "full_name": "Improper Restriction of Operations within the Bounds of a Memory Buffer",
        "source": "MITRE CWE v4.14",
        "nist_severity": "CRITICAL",
        "cvss_base": 9.8,
        "owasp_2021": "A03:2021 โ€“ Injection",
        "cwe_url": "https://cwe.mitre.org/data/definitions/119.html",
        "description": "The software performs operations on a memory buffer but can read from or write to a memory location outside of its intended bounds.",
        "remediation_en": "Use memory-safe languages. Enable stack canaries, ASLR, and NX. Use bounds-checked functions.",
        "remediation_zh": "ไฝฟ็”จ่จ˜ๆ†ถ้ซ”ๅฎ‰ๅ…จ่ชž่จ€ใ€‚ๅ•Ÿ็”จๆฃง้‡‘็ตฒ้›€ใ€ASLR ๅ’Œ NXใ€‚ไฝฟ็”จๆœ‰้‚Š็•ŒๆชขๆŸฅ็š„ๅ‡ฝๅผใ€‚",
        "representative_cves": [
            {"id": "CVE-2022-3602", "cvss": 7.5, "vendor": "OpenSSL", "year": 2022,
             "note": "Buffer overflow in X.509 certificate verification"},
        ],
    },

    "CWE-120": {
        "name": "Classic Buffer Overflow",
        "full_name": "Buffer Copy without Checking Size of Input",
        "source": "MITRE CWE v4.14",
        "nist_severity": "CRITICAL",
        "cvss_base": 9.8,
        "owasp_2021": "A03:2021 โ€“ Injection",
        "cwe_url": "https://cwe.mitre.org/data/definitions/120.html",
        "description": "The program copies an input buffer to an output buffer without verifying that the size of the input buffer is less than the size of the output buffer.",
        "remediation_en": "Use strncpy/strncat with explicit size limits. Prefer C++ std::string or Rust.",
        "remediation_zh": "ไฝฟ็”จๅธถๅคงๅฐ้™ๅˆถ็š„ strncpy/strncatใ€‚ๅ„ชๅ…ˆไฝฟ็”จ C++ std::string ๆˆ– Rustใ€‚",
        "representative_cves": [
            {"id": "CVE-2021-3156", "cvss": 7.8, "vendor": "sudo", "year": 2021,
             "note": "Heap-based buffer overflow (Baron Samedit)"},
        ],
    },

    "CWE-416": {
        "name": "Use After Free",
        "full_name": "Use After Free",
        "source": "MITRE CWE v4.14",
        "nist_severity": "HIGH",
        "cvss_base": 7.8,
        "owasp_2021": "A03:2021 โ€“ Injection",
        "cwe_url": "https://cwe.mitre.org/data/definitions/416.html",
        "description": "The software references memory after it has been freed, which may cause it to crash, use unexpected values, or execute code.",
        "remediation_en": "Set pointers to NULL after freeing. Use smart pointers in C++. Use memory-safe languages.",
        "remediation_zh": "้‡‹ๆ”พๅพŒๅฐ‡ๆŒ‡ๆจ™่จญ็‚บ NULLใ€‚ๅœจ C++ ไธญไฝฟ็”จๆ™บๆ…งๆŒ‡ๆจ™ใ€‚ๅ„ชๅ…ˆ่€ƒๆ…ฎ่จ˜ๆ†ถ้ซ”ๅฎ‰ๅ…จ่ชž่จ€ใ€‚",
        "representative_cves": [
            {"id": "CVE-2022-0185", "cvss": 8.4, "vendor": "Linux Kernel", "year": 2022,
             "note": "Use-after-free in filesystem context leading to privilege escalation"},
        ],
    },

    "CWE-400": {
        "name": "Uncontrolled Resource Consumption (ReDoS/DoS)",
        "full_name": "Uncontrolled Resource Consumption",
        "source": "MITRE CWE v4.14",
        "nist_severity": "HIGH",
        "cvss_base": 7.5,
        "owasp_2021": "A04:2021 โ€“ Insecure Design",
        "cwe_url": "https://cwe.mitre.org/data/definitions/400.html",
        "description": "The software does not properly control the allocation and maintenance of a limited resource, allowing attackers to cause denial of service via resource exhaustion.",
        "remediation_en": "Implement rate limiting. Audit regex for exponential backtracking. Set resource limits.",
        "remediation_zh": "ๅฏฆไฝœ้€Ÿ็އ้™ๅˆถใ€‚ๅฏฉๆ ธๆญฃๅ‰‡่กจ้”ๅผๆ˜ฏๅฆๆœ‰ๆŒ‡ๆ•ธๅ›žๆบฏใ€‚่จญ็ฝฎ่ณ‡ๆบ้™ๅˆถใ€‚",
        "representative_cves": [
            {"id": "CVE-2023-28155", "cvss": 7.5, "vendor": "Node.js request", "year": 2023,
             "note": "ReDoS via specially crafted URL"},
        ],
    },

    "CWE-1333": {
        "name": "Inefficient Regular Expression Complexity (ReDoS)",
        "full_name": "Inefficient Regular Expression Complexity",
        "source": "MITRE CWE v4.14",
        "nist_severity": "HIGH",
        "cvss_base": 7.5,
        "owasp_2021": "A04:2021 โ€“ Insecure Design",
        "cwe_url": "https://cwe.mitre.org/data/definitions/1333.html",
        "description": "The product uses a regular expression with an inefficient, exponential worst-case computational complexity that consumes excessive CPU cycles.",
        "remediation_en": "Audit regex for catastrophic backtracking. Use linear-time regex engines. Enforce timeouts.",
        "remediation_zh": "ๅฏฉๆ ธๆญฃๅ‰‡่กจ้”ๅผ็š„็ฝ้›ฃๆ€งๅ›žๆบฏๅ•้กŒใ€‚ไฝฟ็”จ็ทšๆ€งๆ™‚้–“ๆญฃๅ‰‡ๅผ•ๆ“Žใ€‚ๅผทๅˆถ่จญ็ฝฎ่ถ…ๆ™‚ใ€‚",
        "representative_cves": [
            {"id": "CVE-2022-24999", "cvss": 7.5, "vendor": "qs (npm)", "year": 2022,
             "note": "ReDoS in query string parsing"},
        ],
    },

    "CWE-1321": {
        "name": "Prototype Pollution",
        "full_name": "Improperly Controlled Modification of Object Prototype Attributes",
        "source": "MITRE CWE v4.14",
        "nist_severity": "HIGH",
        "cvss_base": 8.1,
        "owasp_2021": "A03:2021 โ€“ Injection",
        "cwe_url": "https://cwe.mitre.org/data/definitions/1321.html",
        "description": "Modifying the Object prototype in JavaScript can affect all objects, allowing attackers to inject malicious properties.",
        "remediation_en": "Use Object.create(null) for maps. Validate keys. Use hasOwnProperty checks.",
        "remediation_zh": "ไฝฟ็”จ Object.create(null) ไฝœ็‚บๆ˜ ๅฐ„ใ€‚้ฉ—่ญ‰้ตๅใ€‚ไฝฟ็”จ hasOwnProperty ๆชขๆŸฅใ€‚",
        "representative_cves": [
            {"id": "CVE-2022-37601", "cvss": 9.8, "vendor": "loader-utils (npm)", "year": 2022,
             "note": "Prototype pollution via webpack loader configuration"},
            {"id": "CVE-2021-23337", "cvss": 7.2, "vendor": "lodash", "year": 2021,
             "note": "Prototype pollution via merge/zipObjectDeep"},
        ],
    },

}

# โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•
# ๆŸฅ่ฉขๅ‡ฝๅผ
# โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•

def get_cwe_info(cwe_id: str) -> dict | None:
    """
    ๆŸฅ่ฉข CWE ๅฎ˜ๆ–น่ณ‡่จŠใ€‚

    Args:
        cwe_id: CWE ่ญ˜ๅˆฅ็ขผ๏ผŒไพ‹ๅฆ‚ "CWE-89"

    Returns:
        CWE ่ณ‡่จŠๅญ—ๅ…ธ๏ผŒ่‹ฅๆœชๆ‰พๅˆฐๅ‰‡ๅ›žๅ‚ณ None
    """
    normalized = cwe_id.strip().upper()
    result = CWE_DATABASE.get(normalized)
    if result is None:
        logger.debug("[CWE_DB] CWE not found in database: %s", normalized)
    return result


def format_cwe_for_advisor(cwe_id: str, include_cves: bool = True) -> str:
    """
    ๆ ผๅผๅŒ– CWE ่ณ‡่จŠ๏ผŒไพ› Advisor ่ผธๅ‡บไฝฟ็”จใ€‚

    ๆ ผๅผ่จญ่จˆๅŽŸๅ‰‡๏ผš
    - ๆ˜Ž็ขบๆจ™ๆณจไพ†ๆบ๏ผˆ้ž LLM ็”Ÿๆˆ๏ผ‰
    - ๅŒ…ๅซ MITRE ๅฎ˜ๆ–นๅฎš็พฉใ€NIST ๅšด้‡ๆ€งใ€OWASP ๅฐๆ‡‰
    - ๅฏ้ธ๏ผšไปฃ่กจๆ€ง CVE๏ผˆ้™„ๅ…่ฒฌ่ฒๆ˜Ž๏ผ‰

    Args:
        cwe_id: CWE ่ญ˜ๅˆฅ็ขผ
        include_cves: ๆ˜ฏๅฆๅŒ…ๅซไปฃ่กจๆ€ง CVE

    Returns:
        ๆ ผๅผๅŒ–ๅพŒ็š„ๅญ—ไธฒ
    """
    info = get_cwe_info(cwe_id)
    if not info:
        return f"[{cwe_id}] No official data found in MITRE CWE v4.14 database"

    lines = [
        f"[{cwe_id}] {info['name']}",
        f"ไพ†ๆบ๏ผš{info.get('source', 'MITRE CWE')} | "
        f"NIST ๅšด้‡ๆ€ง๏ผš{info.get('nist_severity', 'N/A')} | "
        f"CVSS Base๏ผš{info.get('cvss_base', 'N/A')}",
        f"OWASP๏ผš{info.get('owasp_2021', 'N/A')}",
        f"ๅฎ˜ๆ–นURL๏ผš{info.get('cwe_url', '')}",
        f"ๅฎš็พฉ๏ผš{info.get('description', '')}",
        f"ไฟฎๅพฉ๏ผš{info.get('remediation_zh', info.get('remediation_en', 'N/A'))}",
    ]

    if include_cves:
        rep_cves = info.get("representative_cves", [])
        if rep_cves:
            lines.append(
                "ไปฃ่กจๆ€ง CVE๏ผˆๅŒ้กžๅผฑ้ปž็œŸๅฏฆๆกˆไพ‹๏ผŒ้žๆœฌ็จ‹ๅผ็ขผ็š„็›ดๆŽฅ CVE๏ผ‰๏ผš"
            )
            for cve in rep_cves[:3]:  # ๆœ€ๅคš 3 ๅ€‹
                lines.append(
                    f"  โ†’ {cve['id']} | CVSS {cve['cvss']} | "
                    f"{cve.get('vendor', '')} ({cve.get('year', '')}) | "
                    f"{cve.get('note', '')}"
                )

    return "\n".join(lines)


def get_cwe_severity(cwe_id: str) -> str:
    """ๅ›žๅ‚ณ CWE ็š„ NIST ๅšด้‡ๆ€ง็ญ‰็ดš๏ผˆHIGH/CRITICAL/MEDIUM/LOW๏ผ‰๏ผŒๆœช็Ÿฅๅ‰‡ๅ›žๅ‚ณ UNKNOWN"""
    info = get_cwe_info(cwe_id)
    return info.get("nist_severity", "UNKNOWN") if info else "UNKNOWN"


def get_representative_cves(cwe_id: str) -> list[dict]:
    """ๅ›žๅ‚ณ CWE ็š„ไปฃ่กจๆ€ง CVE ๅˆ—่กจ๏ผˆๆœ€ๅคš 3 ๅ€‹๏ผ‰๏ผŒๆœช็Ÿฅๅ‰‡ๅ›žๅ‚ณ็ฉบๅˆ—่กจ"""
    info = get_cwe_info(cwe_id)
    return info.get("representative_cves", [])[:3] if info else []


def list_covered_cwes() -> list[str]:
    """ๅ›žๅ‚ณ่ณ‡ๆ–™ๅบซไธญๆ‰€ๆœ‰่ฆ†่“‹็š„ CWE ID"""
    return sorted(CWE_DATABASE.keys())