Skip to content

Commit ec6920c

Browse files
committed
Fix CSRF cookie default for HTTP deployments
1 parent cb75a98 commit ec6920c

2 files changed

Lines changed: 10 additions & 1 deletion

File tree

README.md

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -162,6 +162,8 @@ services:
162162
- TG_API_ID=your-api-id
163163
- TG_API_HASH=your-api-hash
164164
- TZ=Asia/Shanghai
165+
# 如通过 HTTPS 反向代理访问,建议开启:
166+
# - APP_REFRESH_COOKIE_SECURE=true
165167
# 可选:AI 功能配置
166168
- OPENAI_API_KEY=your-openai-key
167169
- OPENAI_BASE_URL=https://api.openai.com/v1
@@ -193,6 +195,12 @@ docker run -d \
193195
sfun/tg-sign-plus:latest
194196
```
195197

198+
如果使用 `http://服务器IP:8080` 或局域网 IP 直接访问,请保持
199+
`APP_REFRESH_COOKIE_SECURE` 未设置或为 `false`。否则浏览器不会保存登录后
200+
下发的 CSRF cookie,后续保存配置、修改用户名等写操作会返回 403。
201+
如通过 HTTPS 反向代理访问,可在 `docker run` 中额外添加
202+
`-e APP_REFRESH_COOKIE_SECURE=true`
203+
196204
### 构建自定义镜像
197205

198206
```bash
@@ -390,6 +398,7 @@ tg-signer list my_account
390398
| `TZ` | 时区 | `Asia/Shanghai` |
391399
| `BASE_DIR` | 数据目录 | `/data` |
392400
| `DATABASE_URL` | 数据库连接(支持 PostgreSQL);未设置时使用可写数据目录下的 `db.sqlite`,Docker 通常为 `/data/db.sqlite` | `sqlite:////data/db.sqlite` |
401+
| `APP_REFRESH_COOKIE_SECURE` | 仅通过 HTTPS 访问时设为 `true`;HTTP/IP 直连需保持 `false`,否则写操作会因 CSRF cookie 丢失返回 403 | `false` |
393402
| `OPENAI_API_KEY` | OpenAI API 密钥 | - |
394403
| `OPENAI_BASE_URL` | OpenAI API 地址 | `https://api.openai.com/v1` |
395404
| `OPENAI_MODEL` | 使用的模型 | `gpt-4o-mini` |

backend/core/config.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ class Settings(BaseSettings):
8585
access_token_expire_minutes: int = 30
8686
refresh_token_expire_days: int = 14
8787
refresh_cookie_name: str = "tg-signer-refresh"
88-
refresh_cookie_secure: bool = True
88+
refresh_cookie_secure: bool = False
8989
refresh_cookie_samesite: str = "lax"
9090
refresh_cookie_path: str = "/api"
9191
cors_allow_origin_regex: str = r"https?://(localhost|127\.0\.0\.1)(:\d+)?$"

0 commit comments

Comments
 (0)