# RuntimeError: 会话 cookie 未标记为安全。这是一个安全问题。请在生产环境中将 SESSION_COOKIE_SECURE 设置为 True。

- **ID:** `python/flask-session-cookie-secure-error`
- **领域:** python
- **类别:** config_error
- **验证级别:** ai_generated
- **修复率:** 80%

## 根因

在生产环境中运行时，Flask 警告或报错，因为未设置安全 cookie。

## 版本兼容性

| 版本 | 状态 | 引入 | 弃用 |
|------|------|------|------|
| 3.x | active | — | — |

## 解决方案

1. **** (100% 成功率)
   ```
   Set app.config.update(SESSION_COOKIE_SECURE=True, SESSION_COOKIE_HTTPONLY=True)
   ```
2. **** (90% 成功率)
   ```
   Use environment variables to toggle secure cookies based on environment: app.config['SESSION_COOKIE_SECURE'] = os.getenv('FLASK_ENV') == 'production'
   ```

## 无效尝试

- **** — This exposes session cookies over HTTP, leading to security vulnerabilities. (90% 失败率)
- **** — In some Flask versions, this may become an error or cause security audit failures. (70% 失败率)
