fix(security): P0 - JWT密钥强制环境变量 + 日志敏感信息过滤 #8

Merged
xiaoxia merged 7 commits from fix/security-p0-jwt-logging into main 2026-06-26 18:09:24 +08:00
Owner

安全修复 P0

P0-1: JWT 密钥硬编码默认值

修复内容:

  • apps/api/app/config.py: JWT_SECRET_KEY 从硬编码默认值改为 Optional[str] = None,通过 Pydantic field_validator 强制校验环境变量是否设置,且拒绝已知的 insecure 默认值
  • packages/domain/auth/jwt_service.py: JWTConfig 不再允许无参数实例化,必须通过构造函数传入有效的 secret_key

安全效果: 生产环境如果不设置 JWT_SECRET_KEY 环境变量,应用将拒绝启动。

P0-2: 日志记录敏感信息

修复内容:

  • apps/api/app/middleware/logging.py: 添加 filter_sensitive_params() 函数,过滤 query string 中的敏感参数(password, token, secret, key, authorization 等)

安全效果: 日志中敏感参数的值被替换为 ***,不会被明文记录。


本修复包含安全相关的代码变更,建议尽快 review 并合并。

## 安全修复 P0 ### P0-1: JWT 密钥硬编码默认值 ✅ **修复内容:** - `apps/api/app/config.py`: JWT_SECRET_KEY 从硬编码默认值改为 `Optional[str] = None`,通过 Pydantic `field_validator` 强制校验环境变量是否设置,且拒绝已知的 insecure 默认值 - `packages/domain/auth/jwt_service.py`: JWTConfig 不再允许无参数实例化,必须通过构造函数传入有效的 secret_key **安全效果:** 生产环境如果不设置 JWT_SECRET_KEY 环境变量,应用将拒绝启动。 ### P0-2: 日志记录敏感信息 ✅ **修复内容:** - `apps/api/app/middleware/logging.py`: 添加 `filter_sensitive_params()` 函数,过滤 query string 中的敏感参数(password, token, secret, key, authorization 等) **安全效果:** 日志中敏感参数的值被替换为 `***`,不会被明文记录。 --- 本修复包含安全相关的代码变更,建议尽快 review 并合并。
xiaoxia added 3 commits 2026-06-26 17:43:50 +08:00
fix(security): P0 - 日志过滤敏感参数(token/password/secret等)
CI/CD Pipeline / Validate Code Quality And Tests (pull_request) Failing after 1m0s
Tests / test (pull_request) Failing after 1m0s
Tests / lint (pull_request) Failing after 1m0s
e58293a51f
xiaoxia added 1 commit 2026-06-26 18:00:13 +08:00
fix: resolve CI check failures - format code and add nosec comment
CI/CD Pipeline / Validate Code Quality And Tests (pull_request) Failing after 1m0s
Tests / lint (pull_request) Failing after 0s
Tests / test (pull_request) Failing after 1m0s
950f63bb69
xiaoxia added 1 commit 2026-06-26 18:00:38 +08:00
fix: resolve CI check failures - format code and add nosec comment
CI/CD Pipeline / Validate Code Quality And Tests (pull_request) Failing after 0s
Tests / test (pull_request) Failing after 0s
Tests / lint (pull_request) Failing after 0s
071f0e990e
xiaoxia added 1 commit 2026-06-26 18:00:55 +08:00
fix: resolve CI check failures - format code and fix line length issues
CI/CD Pipeline / Validate Code Quality And Tests (pull_request) Failing after 0s
Tests / test (pull_request) Failing after 0s
Tests / lint (pull_request) Failing after 0s
3d29dc0c83
xiaoxia added 1 commit 2026-06-26 18:01:02 +08:00
fix: resolve CI check failures - format code and fix line length issues
CI/CD Pipeline / Validate Code Quality And Tests (pull_request) Failing after 0s
Tests / test (pull_request) Failing after 0s
Tests / lint (pull_request) Failing after 1m0s
a4f721528e
xiaoxia merged commit f34f654a84 into main 2026-06-26 18:09:24 +08:00
Sign in to join this conversation.