Files
outlookEmailPlus/web_outlook_app.py
T
胡绍康andClaude Opus 4.6 2aca6d9954 fix: 修复安全问题和错误处理改进
P0 安全修复:
- 添加 IP 信任链验证,防止 X-Forwarded-For 伪造攻击
- 导出验证 token 增加 IP 和 User-Agent 绑定校验
- 改用请求头传递导出 token,避免 URL 泄露

P1 改进:
- 错误响应自动使用正确的 HTTP 状态码(400/500)
- 4xx 错误使用 WARNING 日志级别,5xx 使用 ERROR

P2 文档更新:
- 更新 CLAUDE.md 架构说明,体现 controllers 层
- 添加 TRUSTED_PROXIES 和 PROXY_FIX_ENABLED 配置说明
- 修正登录锁定时长为 5 分钟

P3 工程卫生:
- 清理乱码字符
- 删除意外创建的 nul 文件

测试修复:
- 更新测试以适应新的 HTTP 状态码行为
- 添加测试前清理登录限制记录的逻辑

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-02-25 16:11:33 +08:00

70 lines
2.2 KiB
Python
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""
Outlook 邮件 Web 应用(兼容入口)
目标:
- 保持部署入口兼容:`web_outlook_app:app`
- 内部实现已迁移到 `outlook_web/` 模块化架构
关联文档:
- PRD:docs/PRD/Outlook邮件管理工具-前后端拆分与模块化PRD.md
- FD:docs/FD/Outlook邮件管理工具-前后端拆分与模块化FD.md
- TDD:docs/TDD/Outlook邮件管理工具-前后端拆分与模块化TDD.md
- DEV:docs/DEV/00002-前后端拆分-开发者指南.md
"""
import os
from outlook_web.app import create_app
from outlook_web.services import scheduler as scheduler_service
from outlook_web.services import graph as graph_service
from outlook_web.db import create_sqlite_connection
# 兼容导入:从各模块导出常用函数
from outlook_web.security.auth import MAX_LOGIN_ATTEMPTS
from outlook_web.errors import sanitize_error_details, build_error_payload
from outlook_web.security.crypto import decrypt_data, encrypt_data
from outlook_web.repositories.distributed_locks import (
acquire_distributed_lock,
release_distributed_lock,
)
# 在脚本运行场景(__main__)中,调度器由 main block 统一控制,
# 避免 debug reloader 父进程误启后台线程。
app = create_app(autostart_scheduler=None if __name__ != "__main__" else False)
__all__ = [
"app",
"create_sqlite_connection",
"MAX_LOGIN_ATTEMPTS",
"sanitize_error_details",
"build_error_payload",
"decrypt_data",
"encrypt_data",
"acquire_distributed_lock",
"release_distributed_lock",
]
if __name__ == "__main__":
port = int(os.getenv("PORT", 5000))
host = os.getenv("HOST", "0.0.0.0")
debug = os.getenv("FLASK_ENV", "production") != "production"
print("=" * 60)
print("Outlook 邮件 Web 应用")
print("=" * 60)
print(f"访问地址: http://{host}:{port}")
print(f"运行模式: {'开发' if debug else '生产'}")
print("=" * 60)
# 初始化定时任务(与旧版行为保持一致)
if not debug or os.getenv("WERKZEUG_RUN_MAIN") == "true":
scheduler_service.init_scheduler(app, graph_service.test_refresh_token)
else:
print("✓ 调试重载器父进程:跳过启动调度器")
app.run(debug=debug, host=host, port=port)