我的sub2api 登不上了,一登录进后台就秒过期退出登录
刚刚自动更新到最新版以后就出现这个问题.回退部署到老版本也不行,一进后台就被秒踢.
I encountered the same issue and confirmed that it is related to the session binding feature introduced in v0.1.158.
Environment
- Sub2API v0.1.158
- Docker deployment
- Cloudflare proxy
server.trusted_proxiesis not configuredsession_binding_enableduses its default value oftrue
Request flow
POST /api/v1/auth/loginreturns 200.- The subsequent
GET /api/v1/auth/mereturns 401 with error codeSESSION_BINDING_MISMATCH. - After the session family is revoked,
POST /api/v1/auth/refreshalso returns 401, with the log messageRefresh token not found, possible reuse attack.
Root cause
SessionBindingContext obtains the client IP through ip.GetTrustedClientIP(c) and combines it with the User-Agent to generate a session fingerprint. When the service is behind Cloudflare and server.trusted_proxies is empty, the backend may use the Cloudflare edge node IP instead of the actual client IP. If the login request and subsequent requests pass through different edge nodes, the fingerprint changes and the newly issued session is immediately revoked.
The startup log also contains this warning:
Warning: server.trusted_proxies is empty in release mode; client IP trust chain is disabled
Temporary workaround
Disable session binding:
INSERT INTO settings (key, value, updated_at)
VALUES ('session_binding_enabled', 'false', NOW())
ON CONFLICT (key)
DO UPDATE SET value = EXCLUDED.value, updated_at = EXCLUDED.updated_at;
After disabling it and restarting the service, I verified the complete flow through the public domain:
- Login: 200
/auth/me: 200- Token refresh: 200
/auth/mewith the new access token: 200
我遇到了同样的问题,并确认这与 v0.1.158 中引入的会话绑定功能有关。
Environment
- Sub2API v0.1.158
- Docker 部署
- Cloudflare 代理
server.trusted_proxies没有配置session_binding_enabled使用其默认值trueRequest flow
POST /api/v1/auth/login返回 200。- 随后的
GET /api/v1/auth/me返回 401,错误代码为SESSION_BINDING_MISMATCH。- After the session family is revoked,
POST /api/v1/auth/refreshalso returns 401, with the log messageRefresh token not found, possible reuse attack.Root cause
SessionBindingContextobtains the client IP throughip.GetTrustedClientIP(c)and combines it with the User-Agent to generate a session fingerprint. When the service is behind Cloudflare andserver.trusted_proxiesis empty, the backend may use the Cloudflare edge node IP instead of the actual client IP. If the login request and subsequent requests pass through different edge nodes, the fingerprint changes and the newly issued session is immediately revoked.The startup log also contains this warning:
Warning: server.trusted_proxies is empty in release mode; client IP trust chain is disabledTemporary workaround
Disable session binding:
INSERT INTO settings (key, value, updated_at) VALUES ('session_binding_enabled', 'false', NOW()) ON CONFLICT (key) DO UPDATE SET value = EXCLUDED.value, updated_at = EXCLUDED.updated_at; 禁用后重启服务,我通过公共域验证了完整流程:
- 登录:200
/auth/me:200- 令牌刷新:200
/auth/mewith the new access token: 200
You didn’t just fix the bug, you saved my sanity. My hair thanks you. 🫡
+1
我也遇到了这个问题
可以测试一下 这个方法 只能临时使用
在Postgres 的settings表 按照它的格式 添加一条session_binding_enabled=false
这傻X项目。。。VIBE之后真的自己检查过么
I had the same problem, and I was able to fix it by following your workaround. Thanks!
真是傻逼吧 每一个版本都有这种鬼问题
一直退出我还以为是我机器出啦问题 修一下吧
在系统设置中 安全与认证 会话 IP/UA 绑定 关闭就可以了 ,默认是开启的
容器部署的直接执行这个命令就行 docker exec -i sub2api-postgres psql -U sub2api -d sub2api -v ON_ERROR_STOP=1 <<'SQL' INSERT INTO settings (key, value, updated_at) VALUES ('session_binding_enabled', 'false', NOW()) ON CONFLICT (key) DO UPDATE SET value = EXCLUDED.value, updated_at = EXCLUDED.updated_at;
SELECT key, value, updated_at FROM settings WHERE key = 'session_binding_enabled'; SQL
Confirmed the same issue on Sub2API v0.1.160 in a Docker deployment behind Cloudflare.
Reproduction:
POST /api/v1/auth/loginreturns HTTP 200.- The immediately following
GET /api/v1/auth/mereturns HTTP 401 withSESSION_BINDING_MISMATCH. - The refresh token is then rejected because the session family has already been revoked.
Temporarily disabling session IP/UA binding restored the complete login, /auth/me, token refresh, and post-refresh authentication flow.
PR #4463 matches this failure mode and provides a safer fallback when no trusted proxy chain is configured. Please consider updating/rebasing and merging #4463.