安全漏洞修复:修复后端管理员面板认证绕过、DoS 防护缺失等多项安全漏洞,新增 10 项安全验证测试。#93
Open
dhjs0000 wants to merge 1 commit into
Open
Conversation
CRITICAL: - Remove hardcoded ADMIN_PASSWORD_SHA512, read from env var instead - Move admin auth from URL query param to Authorization: Bearer header - Add rate limiting to admin login (8 attempts/300s window) HIGH: - Add global API rate limiting (30 req/60s light, 8 req/60s heavy endpoints) - Add input field max length validation (title/content/category/tags) - Validate history record_id as 32-char hex to prevent path traversal/SQLi MEDIUM: - Tighten CORS: allow_methods/allow_headers from wildcard to explicit whitelist - Add global request body size limit middleware (default 350MB) - Add temp video directory total size enforcement with LRU eviction - Admin page returns 503 when password not configured Tests: - Add test_security.py with 10 verification tests (all 21 tests pass)
Collaborator
|
感谢您的贡献!我就这督促队长jmr赶紧去审核( |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
修复后端管理员面板认证绕过、DoS 防护缺失等多项安全漏洞,新增 10 项安全验证测试。
Security Vulnerabilities Fixed
CRITICAL
硬编码管理员密码哈希 (admin_api.py:20)
ADMIN_PASSWORD_SHA512明文写在源码中,任何人接触到仓库即可离线碰撞密码ADMIN_PASSWORD_SHA512或ADMIN_PASSWORD环境变量读取,未配置时返回 503 并输出 critical 日志密码通过 URL Query Parameter 传输 (admin_api.py:156-158)
?password=xxx导致密码明文出现在 Nginx 访问日志、浏览器历史、Referer 头Authorization: Bearer <token>HTTP Header,同步更新 Admin HTML 前端 JSHIGH
管理员登录无速率限制 → 暴力破解无防护
LLM 高消耗端点无防护 → API 额度可被滥用耗尽
Form 输入字段无长度校验 → 内存/日志炸弹
_validate_input_fields():title≤200, content≤10000, category≤50, tags≤500/diagnose,/diagnose-stream,/pre-score,/optimize,/generate-comments所有入口历史记录 record_id 无格式校验 → 路径穿越/SQL 注入风险
^[a-f0-9]{32}$,仅接受合法 hex UUIDMEDIUM
allow_methods/allow_headers从["*"]收紧为显式白名单BodySizeLimitMiddleware,默认 350MB 上限Files Changed
backend/app/api/admin_api.pybackend/app/main.pybackend/app/api/diagnose.pybackend/app/api/history_api.pybackend/app/api/comments_api.pybackend/app/api/optimize_api.py.env.examplebackend/tests/test_security.pyTest Results
Deployment Checklist
生产环境必须配置:
Breaking Changes
/admin/api/stats不再接受?password=查询参数,必须使用Authorization: Bearer头ADMIN_PASSWORD_SHA512或ADMIN_PASSWORD环境变量时返回 503注意
原密码在Git Log中仍可见,在GPU算力市场中RTX5090的价格通常为3元/小时,RTX 5090的算力是28-35 GH/s(38.4 万亿次/元),意味着含小写字母与数字的密码只需要最多~12 秒就可以完全计算完毕(取8卡并行速率: 235.5 GH/s )。如果你不打算换,需要保证密码有大小写特殊符号且>10位:
字符集: a-z (26)
6位: 308,915,776 | 单卡可扫 372917 遍 | 8卡可扫 2744670 遍
7位: 8,031,810,176 | 单卡可扫 14343 遍 | 8卡可扫 105564 遍
8位: 208,827,064,576 | 单卡可扫 552 遍 | 8卡可扫 4060 遍
9位: 5,429,503,678,976 | 单卡可扫 21 遍 | 8卡可扫 156 遍
10位: 141,167,095,653,376 | 单卡覆盖 81.61% | 8卡可扫 6 遍
字符集: a-z0-9 (36)
6位: 2,176,782,336 | 单卡可扫 52922 遍 | 8卡可扫 389507 遍
7位: 78,364,164,096 | 单卡可扫 1470 遍 | 8卡可扫 10820 遍
8位: 2,821,109,907,456 | 单卡可扫 41 遍 | 8卡可扫 301 遍
9位: 101,559,956,668,416 | 单卡可扫 1 遍 | 8卡可扫 8 遍
10位: 3,656,158,440,062,976 | 单卡覆盖 3.15% | 8卡覆盖 23.19%
字符集: a-zA-Z0-9 (62)
6位: 56,800,235,584 | 单卡可扫 2028 遍 | 8卡可扫 14927 遍
7位: 3,521,614,606,208 | 单卡可扫 33 遍 | 8卡可扫 241 遍
8位: 218,340,105,584,896 | 单卡覆盖 52.76% | 8卡可扫 4 遍
9位: 13,537,086,546,263,552 | 单卡覆盖 0.85% | 8卡覆盖 6.26%
10位: 839,299,365,868,340,224 | 单卡覆盖 0.01% | 8卡覆盖 0.10%