fix(backend): 复查修复(一码两单 / 回调重放 / 跨进程覆盖 / sweep 误删 等)+ 回执

Browse Source
- submit/activate:查码与绑码同锁(redeem_bind),防并发一码两单
- submit:卡密规则按 max(前端 nTotal, 实际模板数) 与模板并集校验;拒未知模板
- 爱发电回调:发码或激活过一律幂等原样回;回调与账本读写串行(HOOK_LOCK)
- LOCK 加跨进程 flock;jsave 唯一临时文件 + fsync + 沿用权限
- admin.py sweep 不删 waiting/working/paid;retry 加锁
- 卡密/订单号/取件码改用 secrets
- redo 换皮肤走 PNG 核验;feedback 限频 + 磁盘闸 + 只收图片
- 下载/取皮肤边读边发;zip 成品 STORED + 同时只打一个包
- H.finish 与 socketserver.finish 重名 → 改名 finish_upload(路径不变)
- 部分失败:记 plan_total/partial,通知金钻,页面说实话
- /claim 新增 terms_v 字段(只增,渲染机无需改)
- ys_local.py:只接受本机页面的 POST(Host/Origin 校验)
- 两份 回执-Claude.md + tests/回执复现测试.py(原版 13/27 失败,改后全过)

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
yws
2026-10-05 12:14:02 +00:00
co-authored by Claude Opus 5.5
parent 11eb16ccae
commit 651d21d882
6 changed files with 1164 additions and 116 deletions
+20
View File
@@ -325,8 +325,28 @@ class H(BaseHTTPRequestHandler):
return self.send(200, f.read(), "image/png", {"Content-Disposition": cd}) return self.send(200, f.read(), "image/png", {"Content-Disposition": cd})
return self.send(404, "not found", "text/plain; charset=utf-8") return self.send(404, "not found", "text/plain; charset=utf-8")
def _same_site(self):
"""只认本机页面发来的请求(2026-10-05 外部复查加)。
⚠️ 这个工具只监听回环,但**本机浏览器里打开的任何网页**都能往 localhost 发 POST ——
text/plain 的跨站 POST 不需要预检,原来照单全收:一个恶意网页就能往队列里塞任意多个
渲染(把机器顶满)、往留档目录里写没经过核验的「皮肤」、或者直接 /api/quit 把工具关掉。
规则:Host 必须是本机地址(挡 DNS 重绑定);带了 Origin 就必须是本机这个端口。
本机页面自己发的请求两条都满足,用法不变。
"""
host = (self.headers.get("Host") or "").strip().lower()
ok_hosts = {"localhost:%d" % PORT, "127.0.0.1:%d" % PORT, "[::1]:%d" % PORT}
if host not in ok_hosts:
return False
origin = (self.headers.get("Origin") or "").strip().lower()
if origin and origin not in {"http://" + h for h in ok_hosts}:
return False
return True
def do_POST(self): def do_POST(self):
u = urllib.parse.urlparse(self.path) u = urllib.parse.urlparse(self.path)
if not self._same_site():
return self.js({"ok": False, "error": "只接受本机页面的请求"}, 403)
n = int(self.headers.get("Content-Length") or 0) n = int(self.headers.get("Content-Length") or 0)
if n > 64 * 1024 * 1024: if n > 64 * 1024 * 1024:
return self.js({"ok": False, "error": "请求过大"}, 413) return self.js({"ok": False, "error": "请求过大"}, 413)