fix(protocol): parse Qzone feeds without eval + stop getCookies hanging (#182)

真机抓包定位到 get_qzone_feeds 的两个问题:

1) feeds3_html_more 的响应体是**JS 对象字面量**(键无引号、单引号字符串、\xNN
   转义、数组含 undefined),不是 JSON → JSON.parse 报 "Expected property name
   at position 66"(报告者看到的「响应结构问题」)。实测调参数(outputhtmlfeed/
   format)改不掉这个格式,且 feeds 是纯远程 H5(native i64 里无相关 CGI),没有
   干净 JSON 端点。改用**非执行的递归下降解析器** parseJsLiteral 把它当数据解析——
   绝不 eval 远程内容(vm 沙箱不是安全边界,被篡改的响应可逃逸到 RCE)。解析器只认
   对象/数组/字符串/数字/true|false|null|undefined,丢弃 __proto__ 键防原型污染;
   mapFeeds 过滤数组尾部的 undefined 洞。

2) getCookies 卡死:HttpsGetCookies 无超时、无深度上限地递归跟随 302;当某跳目标
   不可达(数据中心/Docker 上 qzone.qq.com 裸域超时)→ 永久挂死所有 cookie-backed
   web 动作。加 8s 超时 + 深度上限(5) + 失败/超时保留已收集 cookie(不再 reject)。

两处修复均在 tempserver 真机验证:getCookies 从卡死 3 分钟变正常返回;抓到的真实
feeds 响应体做成测试 fixture,非执行解析器正确解出 uin/nickname/html(\x3C→<)。
读接口加了 TRACE 原始体日志 + 结构失败错误带响应片段,方便后续排查。
(msglist 的 -10000「使用人数过多」判定为 taotao 服务端风控——同 cookie 下 feeds
能成功、msglist 单独挂,非代码 bug,代码已正确透传。)

protocol 572 全绿、typecheck 干净;两轮对抗性 Agent:先揪出 vm 版可 RCE 逼我换非执行
解析器,再确认新解析器构造上不执行代码、无原型污染、真机数据解析正确。
This commit is contained in:
DrSmoothl committed 2026-07-01 21:56:28 +08:00
1 parent 3932958c39
commit 63ab7a1846
5 files changed
+251 -35

No files matched your search

+29 -26
View File
@@ -4,41 +4,44 @@ import https from 'node:https';
type RequestBody = string | Buffer | Uint8Array | Record<string, unknown> | undefined;
export class RequestUtil {
static async HttpsGetCookies(url: string): Promise<{ [key: string]: string; }> {
// Collect Set-Cookie across the ptlogin2 jump's redirect chain. NEVER hangs:
// a per-request timeout + a redirect-depth cap guarantee termination, and any
// failed/slow hop resolves with the cookies gathered so far rather than
// throwing. This matters because the jump's final hop can target a host the
// deployment can't reach (e.g. a datacenter网络 that times out on
// qzone.qq.com) — without the ceiling that would hang every cookie-backed web
// action forever (the essential cookies are already set by the first hop).
static async HttpsGetCookies(url: string, depth = 0): Promise<{ [key: string]: string; }> {
const client = url.startsWith('https') ? https : http;
return new Promise((resolve, reject) => {
return new Promise((resolve) => {
const cookies: { [key: string]: string; } = {};
let settled = false;
const done = (extra?: { [key: string]: string; }) => {
if (settled) return;
settled = true;
resolve(extra ? { ...cookies, ...extra } : cookies);
};
const req = client.get(url, (res) => {
const cookies: { [key: string]: string; } = {};
res.on('data', () => { }); // 必须消耗流
res.on('end', () => {
this.handleRedirect(res, url, cookies)
.then(resolve)
.catch(reject);
});
if (res.headers['set-cookie']) {
this.extractCookies(res.headers['set-cookie'], cookies);
}
res.on('data', () => { }); // 必须消耗流
res.on('end', () => {
const location = res.headers.location;
if ((res.statusCode === 301 || res.statusCode === 302) && location && depth < 5) {
this.HttpsGetCookies(new URL(location, url).href, depth + 1)
.then((rc) => done(rc))
.catch(() => done());
} else {
done();
}
});
});
req.on('error', (error: Error) => {
reject(error);
});
req.setTimeout(8000, () => { req.destroy(); done(); });
req.on('error', () => done());
});
}
private static async handleRedirect(res: http.IncomingMessage, url: string, cookies: { [key: string]: string; }): Promise<{ [key: string]: string; }> {
if (res.statusCode === 301 || res.statusCode === 302) {
if (res.headers.location) {
const redirectUrl = new URL(res.headers.location, url);
const redirectCookies = await this.HttpsGetCookies(redirectUrl.href);
return { ...cookies, ...redirectCookies };
}
}
return cookies;
}
private static extractCookies(setCookieHeaders: string[], cookies: { [key: string]: string; }) {
setCookieHeaders.forEach((cookie) => {
const parts = cookie.split(';')[0]?.split('=');