Compare commits

...
Author SHA1 Message Date
qaiu 792d7210a7 fix(parser): 蓝奏跨站 ajax 对齐浏览器头,避免空 body 被报成空响应
密码页官方 ajax 在 apifile2.woozooo.com,属跨站 XHR。原先固定
Sec-Fetch-Site: same-origin 且不带 Origin,与 Referer 矛盾。
空响应时 bodyAsString 为 null 会 NPE,最终只看到「空响应」。
2026-11-29 13:44:12 +08:00
3 changed files with 92 additions and 4 deletions

No files matched your search

@@ -423,6 +423,38 @@ public class LzTool extends PanBase {
return "/" + ajax.group(1);
}
/** 分享页 / iframe 里的文件 ajax 表单;提取不到时返回 null。 */
static Map<String, String> fileAjaxForm(String html, String pwd) {
AjaxCall call = extractAjaxFromHtml(html, pwd);
return call == null ? null : call.form();
}
/**
* 文件 ajax 头。官方页把下载 POST 打到 apifile / apifile2 等跨站主机,
* 浏览器会带 Origin 且 Sec-Fetch-Site=cross-site;写 same-origin 与 Referer 矛盾,部分出口会被 ESA 拦。
*/
static MultiMap fileAjaxHeaders(String pageUrl, String ajaxTarget) {
MultiMap headers = HeaderUtils.parseHeaders(DOWN_AJAX_HEADERS);
String page = pageUrl == null ? "" : pageUrl.trim();
if (!page.isEmpty()) {
headers.set("referer", page);
}
String pageOrigin = normalizeOrigin(originOf(page, ""));
String ajaxOrigin = originFromAjaxTarget(ajaxTarget);
if (ajaxOrigin.isEmpty()) {
ajaxOrigin = pageOrigin;
}
if (!pageOrigin.isEmpty()) {
headers.set("origin", pageOrigin);
}
if (!ajaxOrigin.isEmpty() && !ajaxOrigin.equalsIgnoreCase(pageOrigin)) {
headers.set("Sec-Fetch-Site", "cross-site");
} else {
headers.set("Sec-Fetch-Site", "same-origin");
}
return headers;
}
private static void addAjaxOrigin(List<String> origins, String origin) {
if (origin != null && origin.contains("://") && !origins.contains(origin)) {
origins.add(origin);
@@ -814,13 +846,12 @@ public class LzTool extends PanBase {
}
private void getDownURL(String referer, AjaxCall call) {
MultiMap headers = HeaderUtils.parseHeaders(DOWN_AJAX_HEADERS);
// 文件 ajax 优先用页面里的绝对地址(常见 apifile.lanzouw.com)。
// 文件 ajax 优先用页面里的绝对地址(常见 apifile / apifile2)。
// 页面源站空响应再换 FILE_AJAX_FALLBACK_ORIGINS,wwww 仍在最后。
// iframe / 分享页的 Referer 保持原主机,不把页面 GET 改写到 wwww。
String page = referer != null && !referer.isBlank() ? referer : resolveShareUrl();
headers.set("referer", page);
String target = call.absoluteUrl() != null ? call.absoluteUrl() : call.path();
MultiMap headers = fileAjaxHeaders(page, target);
postAjaxAt(fileAjaxOrigins(page, target), 0, call, headers, this::handleAjaxDownResponse, null);
}
@@ -92,7 +92,17 @@ public class HttpResponseHelper {
// -------------------- Buffer 转换 --------------------
private static Buffer toBuffer(HttpResponse<?> res) {
return res.body() instanceof Buffer ? (Buffer) res.body() : Buffer.buffer(res.bodyAsString());
Object raw = res.body();
if (raw instanceof Buffer buf) {
return buf;
}
// 407/空 body 时 body() 与 bodyAsString() 都可能是 null,Buffer.buffer(null) 会 NPE,
// 最终被当成「ajax 返回非JSON: 空响应」。
if (raw == null) {
return Buffer.buffer();
}
String text = res.bodyAsString();
return text == null ? Buffer.buffer() : Buffer.buffer(text);
}
private static void ensureBodyLimit(Buffer body) {
@@ -237,4 +237,51 @@ public class LzToolShareUrlTest {
assertEquals("https://wwww.lanzoux.com", origins.get(origins.size() - 1));
assertFalse(origins.get(0).contains("wwww"));
}
@Test
public void passwordPageUsesApifile2AndIsngisSign() {
String html = """
<div class="passwddiv-btn" onclick="down_p();"></div>
<input id="pwd" />
<script type="text/javascript">
function down_p(){
var kdns =1;
var isngis = '';
var isngis = 'SIGNVALUEFROMISNGIS';
var pwd =document.getElementById('pwd').value;
$.ajax({
type : 'post',
url : 'https://apifile2.woozooo.com/ajaxfile.php?file=333149117',
data : { 'action':'downprocess','sign':isngis,'kd':kdns,'p':pwd, },
dataType : 'json'
});
}
</script>
""";
String target = LzTool.fileAjaxTarget(html);
assertEquals("https://apifile2.woozooo.com/ajaxfile.php?file=333149117", target);
Map<String, String> form = LzTool.fileAjaxForm(html, "1t54");
assertEquals("downprocess", form.get("action"));
assertEquals("SIGNVALUEFROMISNGIS", form.get("sign"));
assertEquals("1", form.get("kd"));
assertEquals("1t54", form.get("p"));
List<String> origins = LzTool.fileAjaxOrigins("https://wwaov.lanzouw.com/iNUOu4hbih4h", target);
assertEquals("https://apifile2.woozooo.com", origins.get(0));
io.vertx.core.MultiMap headers = LzTool.fileAjaxHeaders(
"https://wwaov.lanzouw.com/iNUOu4hbih4h", target);
assertEquals("https://wwaov.lanzouw.com/iNUOu4hbih4h", headers.get("referer"));
assertEquals("https://wwaov.lanzouw.com", headers.get("origin"));
assertEquals("cross-site", headers.get("Sec-Fetch-Site"));
}
@Test
public void sameOriginFileAjaxKeepsSameSiteFetchMetadata() {
io.vertx.core.MultiMap headers = LzTool.fileAjaxHeaders(
"https://apifile.lanzouw.com/fn?x", "/ajaxfile.php?file=1");
assertEquals("same-origin", headers.get("Sec-Fetch-Site"));
assertEquals("https://apifile.lanzouw.com", headers.get("origin"));
assertEquals("https://apifile.lanzouw.com/fn?x", headers.get("referer"));
}
}