python config_error ai_generated true

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

RuntimeError: The session cookie is not marked as secure. This is a security issue. Please set SESSION_COOKIE_SECURE to True in production.

ID: python/flask-session-cookie-secure-error

其他格式: JSON · Markdown 中文 · English
80%修复率
84%置信度
0证据数
2024-03-30首次发现

版本兼容性

版本状态引入弃用备注
3.x active

根因分析

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

English

Flask warns or errors when running in production without a secure cookie setting.

generic

解决方案

  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'

无效尝试

常见但无效的做法:

  1. 90% 失败

    This exposes session cookies over HTTP, leading to security vulnerabilities.

  2. 70% 失败

    In some Flask versions, this may become an error or cause security audit failures.