Skip to content

armgit / cindy

Public Imported from GitHub
0

Consider it done. The open-source AI agent that works out of the box · 想到,就能做到。开源、开箱即用的 AI Agent。

fix(browser): 收紧配方域名判断并移除歧义回溯

Dash568de6024084
diff --git a/packages/lizi-mcps/src/browser/opencli-recipes.test.ts b/packages/lizi-mcps/src/browser/opencli-recipes.test.ts
index 832d3efd7a..a068aede6c 100644
--- a/packages/lizi-mcps/src/browser/opencli-recipes.test.ts
+++ b/packages/lizi-mcps/src/browser/opencli-recipes.test.ts
@@ -47,6 +47,20 @@ import { buildEutilsUrl } from '../../../opencli-vendor/clis/pubmed/utils.js';
import { log as recipeLog } from '@jackwener/opencli/logger';
import { createProgressBar, DownloadProgressTracker } from '@jackwener/opencli/download/progress';
import { CommandExecutionError } from '@jackwener/opencli/errors';
+// @ts-expect-error Pinned upstream JavaScript helpers have no declarations.
+import { decodeLinkedInSafetyUrl } from '../../../opencli-vendor/clis/linkedin/shared.js';
+// @ts-expect-error Pinned upstream JavaScript helpers have no declarations.
+import { canonicalizeProductUrl } from '../../../opencli-vendor/clis/coupang/utils.js';
+// @ts-expect-error Pinned upstream JavaScript helpers have no declarations.
+import { __test__ as jd } from '../../../opencli-vendor/clis/jd/item.js';
+// @ts-expect-error Pinned upstream JavaScript helpers have no declarations.
+import { ensureOnYollomi } from '../../../opencli-vendor/clis/yollomi/utils.js';
+// @ts-expect-error Pinned upstream JavaScript helpers have no declarations.
+import { splitDoubanTitle } from '../../../opencli-vendor/clis/douban/utils.js';
+// @ts-expect-error Pinned upstream JavaScript helpers have no declarations.
+import { requirePackageName } from '../../../opencli-vendor/clis/packagist/utils.js';
+import { render } from '../../../opencli-vendor/src/pipeline/template.js';
+import { wrapForEval } from '../../../opencli-vendor/src/browser/utils.js';
// Wrap the native namespace so tests can replace only the subprocess boundary.
vi.mock('node:child_process', async importOriginal => ({
@@ -61,6 +75,51 @@ afterEach(() => {
});
describe("bundled OpenCLI recipes", () => {
+ // #6826 CodeQL URL family, unit: real adapter helpers must distinguish
+ // a site's host from attacker-controlled prefixes, suffixes and query text.
+ // Existing navigation tests used only legitimate origins.
+ it.each(['https://evilqianwen.com', 'https://qianwen.com.evil.test', 'https://evil.test/?qianwen.com'])
+ ('does not reuse an unrelated Qianwen page: %s', async url => {
+ expect(await qwen.isOnQianwen({ evaluate: async () => url })).toBe(false);
+ });
+
+ it('checks real site hosts before navigation reuse and redirect decoding', async () => {
+ const goto = vi.fn();
+ await ensureOnYollomi({ evaluate: async () => 'https://evil.test/?yollomi.com', goto, wait: async () => {} });
+ expect(goto).toHaveBeenCalledWith('https://yollomi.com');
+ const fake = 'https://evillinkedin.com/safety/go/?url=https%3A%2F%2Fexample.test';
+ expect(decodeLinkedInSafetyUrl(fake)).toBe(fake);
+ expect(decodeLinkedInSafetyUrl('https://www.linkedin.com/safety/go/?url=https%3A%2F%2Fexample.test'))
+ .toBe('https://example.test/');
+ expect(canonicalizeProductUrl('https://coupang.com.evil.test/vp/products/123456', '')).toBe('');
+ expect(canonicalizeProductUrl('https://www.coupang.com/vp/products/123456', ''))
+ .toBe('https://www.coupang.com/vp/products/123456');
+ expect(jd.normalizeJdImageUrl('https://evil.test/?360buyimg.com')).toBe('');
+ expect(jd.normalizeJdImageUrl('https://img10.360buyimg.com/n1/jfs/image.jpg'))
+ .toBe('https://img10.360buyimg.com/n1/jfs/image.jpg');
+ vi.stubGlobal('location', { href: 'https://itemXjdYcom/123Xhtml' });
+ vi.stubGlobal('document', { title: '商品', body: { innerText: '商品详情' }, querySelector: () => ({}) });
+ const state = jd.detectJdPageState('123');
+ expect(state.onExpectedItemUrl).toBe(false);
+ vi.stubGlobal('location', { href: 'https://item.jd.com/123.html' });
+ expect(jd.detectJdPageState('123').isProductPage).toBe(true);
+ });
+
+ // CodeQL backtracking family, unit: actual parser/evaluate helpers. Cover
+ // valid object/mixed templates, IIFEs and title/name results; strict timing
+ // and adversarial large-input checks are run separately from default unit.
+ it('preserves template, title and evaluate results with unambiguous parsing', () => {
+ expect(render('${{ { value: args.n } }}', { args: { n: 3 } })).toEqual({ value: 3 });
+ expect(render('${{ args.n }}-${{ args.n + 1 }}', { args: { n: 3 } })).toBe('3-4');
+ expect(render('unfinished ${{ args.n', {})).toBe('unfinished ${{ args.n');
+ expect(render("${{ '${{ literal' }}", {})).toBe('${{ literal');
+ expect(wrapForEval('(() => 3)()')).toBe('(() => 3)()');
+ expect(wrapForEval('() => 3')).toBe('(() => 3)()');
+ expect(splitDoubanTitle('中文 第二 English title')).toEqual({ title: '中文 第二', originalTitle: 'English title' });
+ expect(splitDoubanTitle('中文 标题')).toEqual({ title: '中文', originalTitle: '标题' });
+ expect(requirePackageName('vendor/foo-bar.123').full).toBe('vendor/foo-bar.123');
+ expect(() => requirePackageName('vendor/foo..bar')).toThrow('not a valid Composer name');
+ });
// #6826 / 4353868420, unit: metadata discovery and execution must reject the
// retired code-extraction mode before any browser operation. No previous OTP case.
it.each([true, false, 'true'])('rejects Proton code mode %s before page effects', async value => {
diff --git a/packages/opencli-vendor/README.md b/packages/opencli-vendor/README.md
index 792fa5d3fd..5a40ffcea2 100644
--- a/packages/opencli-vendor/README.md
+++ b/packages/opencli-vendor/README.md
@@ -101,6 +101,18 @@
## 验证范围和运行条件
+安全扫描按 Cindy 实际边界判断:来源中的去标签和实体解码用于文本/Markdown 提取,
+不是 HTML 安全清洗器;返回值经结构化工具结果传递,聊天 Markdown 禁用原始 HTML,
+不能把这些格式转换函数当作允许执行网页标签的入口。浏览器 evaluate 则有意执行配方
+源代码,数据参数通过 JSON 序列化;源码规范化不是不可信代码的沙箱或安全清洗。
+已排除站点和未打包的原始浏览器/终端实现仍作为完整来源保留,不进入 Cindy 执行目录。
+扫描误报按具体告警记录证据,不关闭规则或排除整个来源目录。
+
+站点判断使用 URL 的 hostname 和标签边界,不接受域名出现在其他主机、路径或查询中。
+京东图片在统一规范化入口校验 CDN 主机,商品页比较实际 hostname/pathname。
+模板分隔符、豆瓣标题和商品包名解析避免歧义重复正则;页面表达式保留 IIFE,
+不对整段代码运行嵌套回溯匹配。脉脉请求标识使用系统随机字节,格式保持不变。
+
全量校验覆盖所有模块注册、ID、访问分类、可发现性、源文件摘要和生产 CJS 打包。
真实 Chrome 的隔离本地页面覆盖 evaluate、参数传递、输入、点击、连续 CDP、跨导航
网络捕获、截图及文章提取。它不代表 1,223 条命令都已在真实账号上逐一验收。
diff --git a/packages/opencli-vendor/UPSTREAM.json b/packages/opencli-vendor/UPSTREAM.json
index 38a11c4da3..fbc8b4964d 100644
--- a/packages/opencli-vendor/UPSTREAM.json
+++ b/packages/opencli-vendor/UPSTREAM.json
@@ -273,6 +273,33 @@
},
"src/download/progress.ts": {
"upstreamSha256": "98f9ff046388d58f9347ed31fd26a9dc86d29e53d5ec9040ec47e34cae09608f"
+ },
+ "clis/coupang/utils.js": {
+ "upstreamSha256": "55a66fe7841f53424ac299e750b4baa6337e03e570c50899f64522272f0b7b28"
+ },
+ "clis/douban/utils.js": {
+ "upstreamSha256": "4e79668ba8ce73c3ca8b1f1c4b878251ae6df9ece45b92e790a7c0e230344def"
+ },
+ "clis/jd/item.js": {
+ "upstreamSha256": "831ccece883cb1676680df78714a0efa9b93b92bdfec378c1ea9289128088a0d"
+ },
+ "clis/jianyu/search.js": {
+ "upstreamSha256": "24f1a78ae500ed7403a35b21f6353a273d5ca0a6678516ae8d79bc8b68793738"
+ },
+ "clis/linkedin/shared.js": {
+ "upstreamSha256": "a1646085abc5035e76115f1153ac8ac43c16f96e19d31e28e0dd7b51a6cd8957"
+ },
+ "clis/packagist/utils.js": {
+ "upstreamSha256": "0126fb8ea4b9c6b18502f1cae62324f755f73b7de2660e423e527734c9f41b41"
+ },
+ "clis/qwen/utils.js": {
+ "upstreamSha256": "b99ce7c0388eada2cb5199545c9df6019868b91cae026a1a15f01b9e745aeff8"
+ },
+ "src/browser/utils.ts": {
+ "upstreamSha256": "f7839db0124c7ed46181fc22766f1b3669c47ccdef6de615e0cde9f75cc095fa"
+ },
+ "src/pipeline/template.ts": {
+ "upstreamSha256": "d40d5c10552395ddf8763fa938566cb40488100e13da3602acee6751e287b28b"
}
},
"files": {
@@ -481,7 +508,7 @@
"clis/coupang/auth.js": "c14dab7e96791d1642fcd073e015eb1f7352b42f862d9affe6ca76ea486be4fe",
"clis/coupang/product.js": "fd6d40aa1d6023d43fdc8bf432329798ec81b4a362e2d3c26da5e837563ad499",
"clis/coupang/search.js": "f76bdcc883e8c5de84c28218e7c3857834dc2f6268f9cb071c75ce4b72f69749",
- "clis/coupang/utils.js": "55a66fe7841f53424ac299e750b4baa6337e03e570c50899f64522272f0b7b28",
+ "clis/coupang/utils.js": "7250c78a7813ab2e2cc8305844bac056221cdd322b2a886ff0a1e8da26fa87a5",
"clis/crates/crate.js": "603a1030042313613316d51519e2f5bb9fd5d67c68e11339688905e2d8737dfb",
"clis/crates/search.js": "1b9988e60f5ce14478064e279587190f15b71386aad522e6911872ca504ed2dc",
"clis/crates/utils.js": "3dc594c1b140ee3a250f4ff21d5c8c17367448e8968508e1ee1846eee71d9d76",
@@ -552,7 +579,7 @@
"clis/douban/search.js": "28b1d6e80ae7e5efcc581846439d1b239768a5eb7afedcbc8cf92718c7b23cbc",
"clis/douban/subject.js": "3005a8096e32ea867855e495c7c4917589cb56602bb331728cff7b7ddf7363dc",
"clis/douban/top250.js": "a07a9fe04a950334bb2e892d5c133e70a4b6660328a560e02b5e6075f6a6aac1",
- "clis/douban/utils.js": "4e79668ba8ce73c3ca8b1f1c4b878251ae6df9ece45b92e790a7c0e230344def",
+ "clis/douban/utils.js": "6235fa7ef7d8e5d9c3bea2bc479b3e90fd648fe128533ec57a27a15a739ca234",
"clis/doubao/ask.js": "96dbeec3cb5b7b3201f51d9f5c6338d9e76d5f342b8e9e9deec8975f4db9f54a",
"clis/doubao/auth.js": "c0d270c5c12e3d2e79abf143fa10c47307feec3a67a8bc7f9420becc12a59172",
"clis/doubao/detail.js": "6eb0b5b93adae16a37fee0e4db140aaf5e25f6ade8d8ff8ea1516035aac0cc2f",
@@ -797,12 +824,12 @@
"clis/jd/auth.js": "fbeb128f30bbe159503e6b3573c86369b9fcf00afb42458c6f6081cb5f7de63b",
"clis/jd/cart.js": "b6f5885f70782fb106ecb4cf8466bc0811c94ff13ab1a261058b26f38dd87ad4",
"clis/jd/detail.js": "7be0102b500674c7c2c378c19a77640b1be78bc1c0c11b83359899cad0bab9e7",
- "clis/jd/item.js": "831ccece883cb1676680df78714a0efa9b93b92bdfec378c1ea9289128088a0d",
+ "clis/jd/item.js": "a020577238c12fac8dd4c80a98885a7d864be8737d4c686fffc9f406ef7c0561",
"clis/jd/reviews.js": "74e99ff5d8ad31aefc54326ced3da286d188c0541d2fa6d7283d6fc196bc957e",
"clis/jd/search.js": "d7fcd4806b1e795b594b5aa7eaa201c6598eb9e884f850c6945098be66cfe77a",
"clis/jianyu/auth.js": "9a97028a044f805caaa72c24ae23e96778fda1ba29f57eb7c56c9abaff3d86dc",
"clis/jianyu/detail.js": "a3ab8f01875f74bd584072ac82e2037a4902de4215fbcb89175d7e298aa0cebb",
- "clis/jianyu/search.js": "24f1a78ae500ed7403a35b21f6353a273d5ca0a6678516ae8d79bc8b68793738",
+ "clis/jianyu/search.js": "eaca3f4e8c8ccb6dcae21aa33cdbca93a394536456224078c3425dd0ea21c072",
"clis/jianyu/shared/china-bid-search.js": "5687c796675bcc288276cffb2902801f5347e160861c509cbf8e2c2b696e703b",
"clis/jianyu/shared/procurement-contract.js": "9acf20f5e8b04516ef15ce71c8243402185b8651332017ca95555e073ce2842c",
"clis/jianyu/shared/procurement-detail.js": "5df3ac4bf1598c25a889c02f4eccc949eff8a6cf526de73b54727ec886849c7a",
@@ -888,7 +915,7 @@
"clis/linkedin/search.js": "dd0cf530b1004eb7d392a0a6b0d2b33cf55c011aeb4e9cd306b61d1e4c7911fc",
"clis/linkedin/sent-invitations.js": "62c11dde159b19671a270eaabf3278344eb78ff25d3e4513bce1870aac9a4360",
"clis/linkedin/services-read.js": "79c31222b3f5f4e3dbae465973aa6d3cc691b1b2fccc610138fc08afad7456a9",
- "clis/linkedin/shared.js": "a1646085abc5035e76115f1153ac8ac43c16f96e19d31e28e0dd7b51a6cd8957",
+ "clis/linkedin/shared.js": "a17a652cbbe9441215963441ac376e4dde2a7604e1961b7e35409a419a314d64",
"clis/linkedin/thread-snapshot.js": "6e7dd6aa70af475d481172d9f26530ad4fff7eb3bff13c002af745924a826d29",
"clis/linkedin/timeline.js": "15e9b9906daafb11afc2e3c0dcc5e67ee5297822bd4c6e4cbabf3788a81ef20a",
"clis/linkedin-learning/auth.js": "ba99d4e0c540c810fdfa15e17cb57ca25c47007663546397bc19d5da39660443",
@@ -914,7 +941,7 @@
"clis/lobsters/read.js": "e25827148fadc1811f5c77c9559d8a717d670177e24a6d7cc39bc4fbe47d2809",
"clis/lobsters/tag.js": "314dfe59ad10de0f7a0766b71a771b0f33a31bc137915ef50b51d1b2f58c68b9",
"clis/maimai/auth.js": "a9982cf023ce13d34b23014ecee735687bcd21487c61febb8bc80888e9d43f74",
- "clis/maimai/search-talents.js": "18fc50cd19c3fe5be69785bb3b2466435fbd0e8ccc77f55a156feebe8f64eaba",
+ "clis/maimai/search-talents.js": "d9014d6650de0223c703eab69c43f305705c4533f28a7e1930436c92a699cb85",
"clis/manus/_utils.js": "d5d8c7ae6f4bc77cd367192d128844372cd2cbe0bdf737752fbfd78a38cdb142",
"clis/manus/auth.js": "ad526ed7abcbbef890537b0d445e99bc763787f7f3d30420758a14af92d75018",
"clis/manus/connectors.js": "3114bac64cc4506187598cc42c9cce1bac82c7d46d284930d1689fb297c1bfbe",
@@ -1037,7 +1064,7 @@
"clis/osv/vulnerability.js": "436acdf866b71fb860661edae7e431eab8840a01b1eaff7ede4f0036f80b6ab8",
"clis/packagist/package.js": "913ddb80dda420496362dd965bf158fb7c186496e08cb2b03a835cd95c31da8b",
"clis/packagist/search.js": "d1338e0c9fe37cd9ced3cadbf2cd6b2d316634c7e00137703bca2ac73cfd93db",
- "clis/packagist/utils.js": "0126fb8ea4b9c6b18502f1cae62324f755f73b7de2660e423e527734c9f41b41",
+ "clis/packagist/utils.js": "bfc32e7c3daeaba3701a544e3548377c2dced808c24725c080a57c648dc6053e",
"clis/paperreview/feedback.js": "198fb6ff0c8c151e7d42ea5853781460bf273a96be685bf74fc072977141f5a2",
"clis/paperreview/review.js": "5f9c372061f10e5329d5711523457537aee7c21b10d8a2fb790937492b1d1f74",
"clis/paperreview/submit.js": "a618f96d7f0b1e9c887a3ca44e23f411f471845cd521c72fb41df8fef6b335fb",
@@ -1120,7 +1147,7 @@
"clis/qwen/read.js": "eed8e892c3e35bef9008ece254a8702984978b7eccb6f519874d9e72a72457ab",
"clis/qwen/send.js": "f6e6de80d9059fd33f8e250db1d56fc50d0d511abf76372451bb527d2c82bf9d",
"clis/qwen/status.js": "74fd05dad4a1ad24acd700cb71d739295e54fed03eda5c6ad97efc3be955353e",
- "clis/qwen/utils.js": "b99ce7c0388eada2cb5199545c9df6019868b91cae026a1a15f01b9e745aeff8",
+ "clis/qwen/utils.js": "a6250b9a0d6ac893546ad4ab55878160f6aa78eaab36e804138842586160d257",
"clis/reddit/auth.js": "72ba43e2a7e5e80441eb7d6cff79e40101c76500a16327f310ebe5a9b17ddf6b",
"clis/reddit/comment.js": "d3ce5ae3d14821f63720ac0ff2375b71b650ab291bc2f43ae272da99a31a2c79",
"clis/reddit/frontpage.js": "d4a12a672b67f9ca2db032143cf94a3284ee74d0bed9b5e65d24c1e1c270451c",
@@ -1477,7 +1504,7 @@
"clis/xiaohongshu/note.js": "09c08e2b8c69ee3a16daafc6fdcebf63fb016b99640adb8a157b80b3287f0833",
"clis/xiaohongshu/notifications.js": "1262c0172fabc45aa21ae65643d19e242856062e73caf0377a95cf94914000a3",
"clis/xiaohongshu/pinia-helpers.js": "c2b7639c4ddc2cd078a01eb62c66c0c37548b7b3fd5aac3c631ac53a36c68686",
- "clis/xiaohongshu/publish.js": "5e6a4cfd3bcb2f397f11c4bb006b344032593155b85d1f2d0d038db05c49f0c1",
+ "clis/xiaohongshu/publish.js": "26b30ff721231bc84e8e0319964a9966fcf23b94f8ef2dc5f8cf24f4c1694a90",
"clis/xiaohongshu/risk-control.js": "6e7c15a8a27de78a45fbe01d206bbbd43fab23bd9aa4cf39c900bf6c838c7242",
"clis/xiaohongshu/saved.js": "c69f484e82b016a07ac699d3622236b8e0d2440826ff497f1ddbabb97137a2c7",
"clis/xiaohongshu/search.js": "333f5db3d62dfb3227bb59f47b5ce8e509901d6438b42e3038ec61624ea0d329",
@@ -1521,7 +1548,7 @@
"clis/yollomi/try-on.js": "64b0cb281ff66f7f09bc15bc590ccb23245078f69b41027dfd458918947f1bfd",
"clis/yollomi/upload.js": "03ef841a7c9e9a898f69539d3a57093289edb1155372cae5b72e25dbb2a2bb1d",
"clis/yollomi/upscale.js": "c8af76d01004a75ba7cf5c2120777936d052ba0d1b4b96b558de0af5ba4f6f2e",
- "clis/yollomi/utils.js": "101c830cac8d3de2c4a2348032c7e11d04b11ff2d63a255eb119db6c4324d283",
+ "clis/yollomi/utils.js": "ba10169e4952b194e05f41e87ff05dd9df1752da9480b083e26ed4dacad83f83",
"clis/yollomi/video.js": "d9080992f8ecf4dc41627190014f760ccc255cad5b6f97e9d18c263892f50721",
"clis/youdao/note.js": "dd511f473dd50d84b4baade69da710f19f02d2f84d69719f016b022d8efb826d",
"clis/youtube/auth.js": "976f10a7fa03f2d46c5f0b27c113ee6e18faf1bbdaca8592528bae041e252039",
@@ -1624,7 +1651,7 @@
"src/browser/stealth.ts": "8c5a558720be91f23cf5e510984d9dd3b0d11fb9a24b13040b9e51e30506c1ec",
"src/browser/target-errors.ts": "8b98e897091549ba41b39b405de5c7a79ad8b45b1a76355f9dbffefe35a5ae60",
"src/browser/target-resolver.ts": "1d40f24d807ebd2f17a7a628970d8f4dd08174f036f56e4a228817e6ca42fe2e",
- "src/browser/utils.ts": "f7839db0124c7ed46181fc22766f1b3669c47ccdef6de615e0cde9f75cc095fa",
+ "src/browser/utils.ts": "5bd02a1ba8c54bd21b17b928f70f3b4c081d787226d9deba9ea1933151ce404c",
"src/browser/verify-fixture.ts": "e84f4d3d28caae812b4699be4e16bef79cf0fcd6fef94e0ec7874806a7106f5a",
"src/browser/visual-refs.ts": "9ad04a77d8f01763834a639ec09156d3e19bd52214a6313d69c8783b989d751d",
"src/build-manifest.ts": "f5aa2944e273945f8d6d91970f5ed7099aa0cb7f800d26c47607e30a5998eadf",
@@ -1682,7 +1709,7 @@
"src/pipeline/steps/intercept.ts": "c45a26c974489f621fd932b513ea742efea1a7bb3746d4c10d8a110613068aa7",
"src/pipeline/steps/tap.ts": "7e4a5f80656931feb358b3d9a655f32c257ab2aaf749b532f5751e6fba48b964",
"src/pipeline/steps/transform.ts": "2991a5aab8ab6f55369a6f1ad5c8a65c62eca421382fee294d8655e75980da5c",
- "src/pipeline/template.ts": "d40d5c10552395ddf8763fa938566cb40488100e13da3602acee6751e287b28b",
+ "src/pipeline/template.ts": "8146e6af60333dadd5e3defd1b6c30d3b2c09903e2a47ac2c4642e33423ae13d",
"src/plugin-manifest.ts": "84338fa7029f75a764722e83511d1b2edcfc09c5653c1aebafe84e2ad0076626",
"src/plugin-path.ts": "8081c7e5f6f1e13de0018ad10306a3daf0fdc78f4d2856cd18c3b17f80d192fd",
"src/plugin-runtime.ts": "7612ac88bd488cac8b5e7a5408bcc9bd087d637883d66a2e04b42bd9b95957eb",
diff --git a/packages/opencli-vendor/cindy/patches.json b/packages/opencli-vendor/cindy/patches.json
index 5492be7833..283e312001 100644
--- a/packages/opencli-vendor/cindy/patches.json
+++ b/packages/opencli-vendor/cindy/patches.json
@@ -4046,5 +4046,90 @@
"file": "clis/web/read.js",
"before": " const raw = await page.readNetworkCapture().catch(() => []);",
"after": " const raw = await page.readNetworkCapture();"
+ },
+ {
+ "file": "clis/coupang/utils.js",
+ "before": " if (raw) {\n try {\n const url = new URL(raw.startsWith('http') ? raw : `https://www.coupang.com${raw}`);\n if (!url.hostname.includes('coupang.com'))\n return '';\n const id = normalizeProductId(url.pathname) || normalizeProductId(productId);\n if (!id)\n",
+ "after": " if (raw) {\n try {\n const url = new URL(raw.startsWith('http') ? raw : `https://www.coupang.com${raw}`);\n if (url.hostname !== 'coupang.com' && !url.hostname.endsWith('.coupang.com'))\n return '';\n const id = normalizeProductId(url.pathname) || normalizeProductId(productId);\n if (!id)\n"
+ },
+ {
+ "file": "clis/douban/utils.js",
+ "before": " const normalized = normalizeText(fullTitle);\n if (!normalized)\n return { title: '', originalTitle: '' };\n const match = normalized.match(/^([\\u4e00-\\u9fff\\u3000-\\u303f\\uff00-\\uffef]+(?:\\s*[\\u4e00-\\u9fff\\u3000-\\u303f\\uff00-\\uffef·::!?]+)*)\\s+(.+)$/);\n if (!match) {\n return { title: normalized, originalTitle: '' };\n }\n return {\n title: normalizeText(match[1]),\n originalTitle: normalizeText(match[2]),\n };\n}\nasync function ensureDoubanReady(page) {\n",
+ "after": " const normalized = normalizeText(fullTitle);\n if (!normalized)\n return { title: '', originalTitle: '' };\n const words = normalized.split(' ');\n const chinese = /^[\\u4e00-\\u9fff\\u3000-\\u303f\\uff00-\\uffef]/;\n const titleWord = /^[\\u4e00-\\u9fff\\u3000-\\u303f\\uff00-\\uffef·::!?]+$/;\n if (words.length < 2 || !chinese.test(words[0]) || !titleWord.test(words[0])) {\n return { title: normalized, originalTitle: '' };\n }\n let split = 1;\n while (split < words.length - 1 && titleWord.test(words[split])) split += 1;\n return {\n title: words.slice(0, split).join(' '),\n originalTitle: words.slice(split).join(' '),\n };\n}\nasync function ensureDoubanReady(page) {\n"
+ },
+ {
+ "file": "clis/jd/item.js",
+ "before": " url = `https:${url}`;\n if (!/^https?:\\/\\//.test(url))\n return '';\n return url;\n}\nfunction normalizeJdImageSize(url) {\n return normalizeJdImageUrl(url)\n",
+ "after": " url = `https:${url}`;\n if (!/^https?:\\/\\//.test(url))\n return '';\n try {\n const host = new URL(url).hostname;\n return host === '360buyimg.com' || host.endsWith('.360buyimg.com') ? url : '';\n } catch { return ''; }\n}\nfunction normalizeJdImageSize(url) {\n return normalizeJdImageUrl(url)\n"
+ },
+ {
+ "file": "clis/jd/item.js",
+ "before": " };\n const push = (value) => {\n const url = normalizeJdImageUrl(value);\n if (url && url.includes('360buyimg.com'))\n urls.push(url);\n };\n for (const img of root.querySelectorAll?.('img') || []) {\n",
+ "after": " };\n const push = (value) => {\n const url = normalizeJdImageUrl(value);\n if (url)\n urls.push(url);\n };\n for (const img of root.querySelectorAll?.('img') || []) {\n"
+ },
+ {
+ "file": "clis/jd/item.js",
+ "before": " const urls = [];\n const push = (value) => {\n const url = normalizeJdImageUrl(value);\n if (url && url.includes('360buyimg.com'))\n urls.push(url);\n };\n for (const match of String(text || '').matchAll(/(?:https?:)?\\/\\/[^\"'`\\s<>)\\\\]+360buyimg\\.com[^\"'`\\s<>)\\\\]*/g)) {\n",
+ "after": " const urls = [];\n const push = (value) => {\n const url = normalizeJdImageUrl(value);\n if (url)\n urls.push(url);\n };\n for (const match of String(text || '').matchAll(/(?:https?:)?\\/\\/[^\"'`\\s<>)\\\\]+360buyimg\\.com[^\"'`\\s<>)\\\\]*/g)) {\n"
+ },
+ {
+ "file": "clis/jd/item.js",
+ "before": " const urls = [];\n const push = (value) => {\n const url = normalizeJdImageUrl(value);\n if (url && url.includes('360buyimg.com'))\n urls.push(url);\n };\n if (typeof payload === 'string') {\n",
+ "after": " const urls = [];\n const push = (value) => {\n const url = normalizeJdImageUrl(value);\n if (url)\n urls.push(url);\n };\n if (typeof payload === 'string') {\n"
+ },
+ {
+ "file": "clis/jd/item.js",
+ "before": " const hasSecurityChallenge = /risk_handler|安全验证|安全校验|完成安全验证|滑块|captcha|访问过于频繁|验证中心|京东验证/.test(`${href}\\n${text}`);\n const loginOnlyWithoutProduct = /请登录|登录/.test(text) && !hasProductMarker;\n const looksBlocked = isLoginPage || hasSecurityChallenge || loginOnlyWithoutProduct;\n const onExpectedItemUrl = new RegExp(`item\\.jd\\.com/${expectedSku}\\.html`).test(href);\n return {\n href,\n title,\n",
+ "after": " const hasSecurityChallenge = /risk_handler|安全验证|安全校验|完成安全验证|滑块|captcha|访问过于频繁|验证中心|京东验证/.test(`${href}\\n${text}`);\n const loginOnlyWithoutProduct = /请登录|登录/.test(text) && !hasProductMarker;\n const looksBlocked = isLoginPage || hasSecurityChallenge || loginOnlyWithoutProduct;\n let onExpectedItemUrl = false;\n try {\n const parsed = new URL(href);\n onExpectedItemUrl = parsed.hostname === 'item.jd.com' && parsed.pathname === `/${expectedSku}.html`;\n } catch { /* An invalid URL cannot identify the expected product. */ }\n return {\n href,\n title,\n"
+ },
+ {
+ "file": "clis/jianyu/search.js",
+ "before": " try {\n const parsed = new URL(normalized);\n const host = parsed.hostname.toLowerCase();\n if (!host.endsWith('duckduckgo.com'))\n return normalized;\n const uddg = parsed.searchParams.get('uddg');\n if (!uddg)\n",
+ "after": " try {\n const parsed = new URL(normalized);\n const host = parsed.hostname.toLowerCase();\n if (host !== 'duckduckgo.com' && !host.endsWith('.duckduckgo.com'))\n return normalized;\n const uddg = parsed.searchParams.get('uddg');\n if (!uddg)\n"
+ },
+ {
+ "file": "clis/linkedin/shared.js",
+ "before": " if (!url) return '';\n try {\n const parsed = new URL(url);\n if (parsed.hostname.endsWith('linkedin.com') && parsed.pathname === '/safety/go/') {\n return normalizeHttpUrl(parsed.searchParams.get('url') || '');\n }\n } catch {}\n",
+ "after": " if (!url) return '';\n try {\n const parsed = new URL(url);\n if ((parsed.hostname === 'linkedin.com' || parsed.hostname.endsWith('.linkedin.com')) && parsed.pathname === '/safety/go/') {\n return normalizeHttpUrl(parsed.searchParams.get('url') || '');\n }\n } catch {}\n"
+ },
+ {
+ "file": "clis/maimai/search-talents.js",
+ "before": " */\nimport { cli, Strategy } from '@jackwener/opencli/registry';\nimport { CommandExecutionError, EmptyResultError } from '@jackwener/opencli/errors';\n\ncli({\n site: 'maimai',\n",
+ "after": " */\nimport { cli, Strategy } from '@jackwener/opencli/registry';\nimport { CommandExecutionError, EmptyResultError } from '@jackwener/opencli/errors';\nimport { randomBytes } from 'node:crypto';\n\ncli({\n site: 'maimai',\n"
+ },
+ {
+ "file": "clis/maimai/search-talents.js",
+ "before": " await page.sleep(5);\n\n // Generate random session IDs\n const sessionid = 'b92d0fb5-f3fd-1f4b-fcdc-' + Math.random().toString(16).slice(2, 14);\n const deletesessionid = 'ae907d75-315c-8db7-2cc7-' + Math.random().toString(16).slice(2, 14);\n\n const requestBody = {\n search: {\n",
+ "after": " await page.sleep(5);\n\n // Generate random session IDs\n const sessionid = 'b92d0fb5-f3fd-1f4b-fcdc-' + randomBytes(6).toString('hex');\n const deletesessionid = 'ae907d75-315c-8db7-2cc7-' + randomBytes(6).toString('hex');\n\n const requestBody = {\n search: {\n"
+ },
+ {
+ "file": "clis/packagist/utils.js",
+ "before": "const UA = 'opencli-packagist-adapter (+https://github.com/jackwener/opencli)';\n\n// Each segment of a Composer package name (`vendor` and `package`).\nconst SEGMENT = /^[a-z0-9]([_.-]?[a-z0-9]+)*$/;\n\nexport function requireString(value, label) {\n const s = String(value ?? '').trim();\n",
+ "after": "const UA = 'opencli-packagist-adapter (+https://github.com/jackwener/opencli)';\n\n// Each segment of a Composer package name (`vendor` and `package`).\nconst SEGMENT = /^[a-z0-9]+(?:[_.-][a-z0-9]+)*$/;\n\nexport function requireString(value, label) {\n const s = String(value ?? '').trim();\n"
+ },
+ {
+ "file": "clis/qwen/utils.js",
+ "before": "\nexport async function isOnQianwen(page) {\n const url = await page.evaluate('window.location.href').catch(() => '');\n return typeof url === 'string' && url.includes('qianwen.com');\n}\n\nexport async function ensureOnQianwen(page) {\n",
+ "after": "\nexport async function isOnQianwen(page) {\n const url = await page.evaluate('window.location.href').catch(() => '');\n try {\n const parsed = new URL(url);\n return ['http:', 'https:'].includes(parsed.protocol)\n && (parsed.hostname === 'qianwen.com' || parsed.hostname.endsWith('.qianwen.com'));\n } catch { return false; }\n}\n\nexport async function ensureOnQianwen(page) {\n"
+ },
+ {
+ "file": "clis/xiaohongshu/publish.js",
+ "before": " await page.wait({ time: 3 });\n // Verify we landed on the creator site (not redirected to login)\n const pageUrl = await page.evaluate('() => location.href');\n if (!pageUrl.includes('creator.xiaohongshu.com')) {\n throw new Error('Redirected away from creator center — session may have expired. ' +\n 'Re-capture browser login via: opencli xiaohongshu creator-profile');\n }\n",
+ "after": " await page.wait({ time: 3 });\n // Verify we landed on the creator site (not redirected to login)\n const pageUrl = await page.evaluate('() => location.href');\n let onCreatorSite = false;\n try {\n const parsed = new URL(pageUrl);\n onCreatorSite = parsed.protocol === 'https:' && parsed.hostname === 'creator.xiaohongshu.com';\n } catch { /* Treat invalid URLs as a failed navigation. */ }\n if (!onCreatorSite) {\n throw new Error('Redirected away from creator center — session may have expired. ' +\n 'Re-capture browser login via: opencli xiaohongshu creator-profile');\n }\n"
+ },
+ {
+ "file": "clis/yollomi/utils.js",
+ "before": " */\nexport async function ensureOnYollomi(page) {\n const currentUrl = await page.evaluate(`(() => location.href)()`);\n if (!currentUrl || !currentUrl.includes('yollomi.com')) {\n await page.goto('https://yollomi.com');\n await page.wait(3);\n }\n",
+ "after": " */\nexport async function ensureOnYollomi(page) {\n const currentUrl = await page.evaluate(`(() => location.href)()`);\n let onSite = false;\n try {\n const parsed = new URL(currentUrl);\n onSite = ['http:', 'https:'].includes(parsed.protocol)\n && (parsed.hostname === 'yollomi.com' || parsed.hostname.endsWith('.yollomi.com'));\n } catch { /* Invalid locations must navigate to the real site. */ }\n if (!onSite) {\n await page.goto('https://yollomi.com');\n await page.wait(3);\n }\n"
+ },
+ {
+ "file": "src/browser/utils.ts",
+ "before": " const code = js.trim();\n if (!code) return 'undefined';\n\n // Already an IIFE: `(async () => { ... })()` or `(function() {...})()`\n if (/^\\([\\s\\S]*\\)\\s*\\(.*\\)\\s*$/.test(code)) return code;\n\n // Arrow function: `() => ...` or `async () => ...`\n if (/^(async\\s+)?(\\([^)]*\\)|[A-Za-z_]\\w*)\\s*=>/.test(code)) return `(${code})()`;\n\n // Function declaration: `function ...` or `async function ...`\n if (/^(async\\s+)?function[\\s(]/.test(code)) return `(${code})()`;\n",
+ "after": " const code = js.trim();\n if (!code) return 'undefined';\n\n // Arrow function: `() => ...` or `async () => ...`\n // Exclude nested opening parentheses so an IIFE stays a bare expression.\n if (/^(async\\s+)?(\\([^()]*\\)|[A-Za-z_]\\w*)\\s*=>/.test(code)) return `(${code})()`;\n\n // Function declaration: `function ...` or `async function ...`\n if (/^(async\\s+)?function[\\s(]/.test(code)) return `(${code})()`;\n"
+ },
+ {
+ "file": "src/pipeline/template.ts",
+ "before": "export function render(template: unknown, ctx: RenderContext): unknown {\n if (typeof template !== 'string') return template;\n const trimmed = template.trim();\n // Full expression: entire string is a single ${{ ... }}\n // Use [^}] to prevent matching across }} boundaries (e.g. \"${{ a }}-${{ b }}\")\n const fullMatch = trimmed.match(/^\\$\\{\\{\\s*([^}]*(?:\\}[^}][^}]*)*)\\s*\\}\\}$/);\n if (fullMatch && !trimmed.includes('}}-') && !trimmed.includes('}}${{')) return evalExpr(fullMatch[1].trim(), ctx);\n // Check if the entire string is a single expression (no other text around it)\n const singleExpr = trimmed.match(/^\\$\\{\\{\\s*([\\s\\S]*?)\\s*\\}\\}$/);\n if (singleExpr) {\n // Verify it's truly a single expression (no other ${{ inside)\n const inner = singleExpr[1];\n if (!inner.includes('${{')) return evalExpr(inner.trim(), ctx);\n }\n return template.replace(/\\$\\{\\{\\s*(.*?)\\s*\\}\\}/g, (_m, expr) => String(evalExpr(expr.trim(), ctx)));\n}\n\nexport function evalExpr(expr: string, ctx: RenderContext): unknown {\n",
+ "after": "export function render(template: unknown, ctx: RenderContext): unknown {\n if (typeof template !== 'string') return template;\n const trimmed = template.trim();\n if (trimmed.startsWith('${{') && trimmed.endsWith('}}')) {\n const inner = trimmed.slice(3, -2);\n const singleClosingBraces = !inner.includes('}}') && !inner.endsWith('}');\n if (singleClosingBraces || !inner.includes('${{')) return evalExpr(inner.trim(), ctx);\n }\n // Scan delimiters once rather than retrying a backtracking regexp at each\n // opener. Keep malformed/unclosed templates as text, as before.\n const parts: string[] = [];\n let cursor = 0;\n while (cursor < template.length) {\n const start = template.indexOf('${{', cursor);\n if (start < 0) break;\n const end = template.indexOf('}}', start + 3);\n if (end < 0) break;\n const expr = template.slice(start + 3, end);\n parts.push(template.slice(cursor, start));\n parts.push(/[\\r\\n\\u2028\\u2029]/.test(expr)\n ? template.slice(start, end + 2) : String(evalExpr(expr.trim(), ctx)));\n cursor = end + 2;\n }\n parts.push(template.slice(cursor));\n return parts.join('');\n}\n\nexport function evalExpr(expr: string, ctx: RenderContext): unknown {\n"
}
]
diff --git a/packages/opencli-vendor/clis/coupang/utils.js b/packages/opencli-vendor/clis/coupang/utils.js
index 90993a0f16..0bc81748af 100644
--- a/packages/opencli-vendor/clis/coupang/utils.js
+++ b/packages/opencli-vendor/clis/coupang/utils.js
@@ -122,7 +122,7 @@ export function canonicalizeProductUrl(rawUrl, productId) {
if (raw) {
try {
const url = new URL(raw.startsWith('http') ? raw : `https://www.coupang.com${raw}`);
- if (!url.hostname.includes('coupang.com'))
+ if (url.hostname !== 'coupang.com' && !url.hostname.endsWith('.coupang.com'))
return '';
const id = normalizeProductId(url.pathname) || normalizeProductId(productId);
if (!id)
diff --git a/packages/opencli-vendor/clis/douban/utils.js b/packages/opencli-vendor/clis/douban/utils.js
index c317c5a33f..fcda16a2e3 100644
--- a/packages/opencli-vendor/clis/douban/utils.js
+++ b/packages/opencli-vendor/clis/douban/utils.js
@@ -72,13 +72,17 @@ export function splitDoubanTitle(fullTitle) {
const normalized = normalizeText(fullTitle);
if (!normalized)
return { title: '', originalTitle: '' };
- const match = normalized.match(/^([\u4e00-\u9fff\u3000-\u303f\uff00-\uffef]+(?:\s*[\u4e00-\u9fff\u3000-\u303f\uff00-\uffef·::!?]+)*)\s+(.+)$/);
- if (!match) {
+ const words = normalized.split(' ');
+ const chinese = /^[\u4e00-\u9fff\u3000-\u303f\uff00-\uffef]/;
+ const titleWord = /^[\u4e00-\u9fff\u3000-\u303f\uff00-\uffef·::!?]+$/;
+ if (words.length < 2 || !chinese.test(words[0]) || !titleWord.test(words[0])) {
return { title: normalized, originalTitle: '' };
}
+ let split = 1;
+ while (split < words.length - 1 && titleWord.test(words[split])) split += 1;
return {
- title: normalizeText(match[1]),
- originalTitle: normalizeText(match[2]),
+ title: words.slice(0, split).join(' '),
+ originalTitle: words.slice(split).join(' '),
};
}
async function ensureDoubanReady(page) {
diff --git a/packages/opencli-vendor/clis/jd/item.js b/packages/opencli-vendor/clis/jd/item.js
index ff15e7cdfa..ddf8a4892b 100644
--- a/packages/opencli-vendor/clis/jd/item.js
+++ b/packages/opencli-vendor/clis/jd/item.js
@@ -32,7 +32,10 @@ function normalizeJdImageUrl(rawUrl) {
url = `https:${url}`;
if (!/^https?:\/\//.test(url))
return '';
- return url;
+ try {
+ const host = new URL(url).hostname;
+ return host === '360buyimg.com' || host.endsWith('.360buyimg.com') ? url : '';
+ } catch { return ''; }
}
function normalizeJdImageSize(url) {
return normalizeJdImageUrl(url)
@@ -69,7 +72,7 @@ function collectImageUrlsFrom(root, options = {}) {
};
const push = (value) => {
const url = normalizeJdImageUrl(value);
- if (url && url.includes('360buyimg.com'))
+ if (url)
urls.push(url);
};
for (const img of root.querySelectorAll?.('img') || []) {
@@ -116,7 +119,7 @@ function collectImageUrlsFromText(text) {
const urls = [];
const push = (value) => {
const url = normalizeJdImageUrl(value);
- if (url && url.includes('360buyimg.com'))
+ if (url)
urls.push(url);
};
for (const match of String(text || '').matchAll(/(?:https?:)?\/\/[^"'`\s<>)\\]+360buyimg\.com[^"'`\s<>)\\]*/g)) {
@@ -160,7 +163,7 @@ function collectImageUrlsFromPayload(payload, seen = new Set(), depth = 0) {
const urls = [];
const push = (value) => {
const url = normalizeJdImageUrl(value);
- if (url && url.includes('360buyimg.com'))
+ if (url)
urls.push(url);
};
if (typeof payload === 'string') {
@@ -528,7 +531,11 @@ function detectJdPageState(expectedSku) {
const hasSecurityChallenge = /risk_handler|安全验证|安全校验|完成安全验证|滑块|captcha|访问过于频繁|验证中心|京东验证/.test(`${href}\n${text}`);
const loginOnlyWithoutProduct = /请登录|登录/.test(text) && !hasProductMarker;
const looksBlocked = isLoginPage || hasSecurityChallenge || loginOnlyWithoutProduct;
- const onExpectedItemUrl = new RegExp(`item\.jd\.com/${expectedSku}\.html`).test(href);
+ let onExpectedItemUrl = false;
+ try {
+ const parsed = new URL(href);
+ onExpectedItemUrl = parsed.hostname === 'item.jd.com' && parsed.pathname === `/${expectedSku}.html`;
+ } catch { /* An invalid URL cannot identify the expected product. */ }
return {
href,
title,
diff --git a/packages/opencli-vendor/clis/jianyu/search.js b/packages/opencli-vendor/clis/jianyu/search.js
index d5adc84cd2..23aa4002b2 100644
--- a/packages/opencli-vendor/clis/jianyu/search.js
+++ b/packages/opencli-vendor/clis/jianyu/search.js
@@ -326,7 +326,7 @@ function unwrapDuckDuckGoUrl(rawUrl) {
try {
const parsed = new URL(normalized);
const host = parsed.hostname.toLowerCase();
- if (!host.endsWith('duckduckgo.com'))
+ if (host !== 'duckduckgo.com' && !host.endsWith('.duckduckgo.com'))
return normalized;
const uddg = parsed.searchParams.get('uddg');
if (!uddg)
diff --git a/packages/opencli-vendor/clis/linkedin/shared.js b/packages/opencli-vendor/clis/linkedin/shared.js
index 6bfb96013e..4e738a5114 100644
--- a/packages/opencli-vendor/clis/linkedin/shared.js
+++ b/packages/opencli-vendor/clis/linkedin/shared.js
@@ -52,7 +52,7 @@ export function decodeLinkedInSafetyUrl(value) {
if (!url) return '';
try {
const parsed = new URL(url);
- if (parsed.hostname.endsWith('linkedin.com') && parsed.pathname === '/safety/go/') {
+ if ((parsed.hostname === 'linkedin.com' || parsed.hostname.endsWith('.linkedin.com')) && parsed.pathname === '/safety/go/') {
return normalizeHttpUrl(parsed.searchParams.get('url') || '');
}
} catch {}
diff --git a/packages/opencli-vendor/clis/maimai/search-talents.js b/packages/opencli-vendor/clis/maimai/search-talents.js
index 85756b81d1..612cae8b18 100644
--- a/packages/opencli-vendor/clis/maimai/search-talents.js
+++ b/packages/opencli-vendor/clis/maimai/search-talents.js
@@ -4,6 +4,7 @@
*/
import { cli, Strategy } from '@jackwener/opencli/registry';
import { CommandExecutionError, EmptyResultError } from '@jackwener/opencli/errors';
+import { randomBytes } from 'node:crypto';
cli({
site: 'maimai',
@@ -55,8 +56,8 @@ cli({
await page.sleep(5);
// Generate random session IDs
- const sessionid = 'b92d0fb5-f3fd-1f4b-fcdc-' + Math.random().toString(16).slice(2, 14);
- const deletesessionid = 'ae907d75-315c-8db7-2cc7-' + Math.random().toString(16).slice(2, 14);
+ const sessionid = 'b92d0fb5-f3fd-1f4b-fcdc-' + randomBytes(6).toString('hex');
+ const deletesessionid = 'ae907d75-315c-8db7-2cc7-' + randomBytes(6).toString('hex');
const requestBody = {
search: {
diff --git a/packages/opencli-vendor/clis/packagist/utils.js b/packages/opencli-vendor/clis/packagist/utils.js
index 2299b9d268..7ec0c031b1 100644
--- a/packages/opencli-vendor/clis/packagist/utils.js
+++ b/packages/opencli-vendor/clis/packagist/utils.js
@@ -9,7 +9,7 @@ export const PACKAGIST_BASE = 'https://packagist.org';
const UA = 'opencli-packagist-adapter (+https://github.com/jackwener/opencli)';
// Each segment of a Composer package name (`vendor` and `package`).
-const SEGMENT = /^[a-z0-9]([_.-]?[a-z0-9]+)*$/;
+const SEGMENT = /^[a-z0-9]+(?:[_.-][a-z0-9]+)*$/;
export function requireString(value, label) {
const s = String(value ?? '').trim();
diff --git a/packages/opencli-vendor/clis/qwen/utils.js b/packages/opencli-vendor/clis/qwen/utils.js
index 4f6bb744d4..55fedc6863 100644
--- a/packages/opencli-vendor/clis/qwen/utils.js
+++ b/packages/opencli-vendor/clis/qwen/utils.js
@@ -32,7 +32,11 @@ export function normalizeBooleanFlag(value, fallback = false) {
export async function isOnQianwen(page) {
const url = await page.evaluate('window.location.href').catch(() => '');
- return typeof url === 'string' && url.includes('qianwen.com');
+ try {
+ const parsed = new URL(url);
+ return ['http:', 'https:'].includes(parsed.protocol)
+ && (parsed.hostname === 'qianwen.com' || parsed.hostname.endsWith('.qianwen.com'));
+ } catch { return false; }
}
export async function ensureOnQianwen(page) {
diff --git a/packages/opencli-vendor/clis/xiaohongshu/publish.js b/packages/opencli-vendor/clis/xiaohongshu/publish.js
index 95da24503c..1ae4deb9e1 100644
--- a/packages/opencli-vendor/clis/xiaohongshu/publish.js
+++ b/packages/opencli-vendor/clis/xiaohongshu/publish.js
@@ -1217,7 +1217,12 @@ cli({
await page.wait({ time: 3 });
// Verify we landed on the creator site (not redirected to login)
const pageUrl = await page.evaluate('() => location.href');
- if (!pageUrl.includes('creator.xiaohongshu.com')) {
+ let onCreatorSite = false;
+ try {
+ const parsed = new URL(pageUrl);
+ onCreatorSite = parsed.protocol === 'https:' && parsed.hostname === 'creator.xiaohongshu.com';
+ } catch { /* Treat invalid URLs as a failed navigation. */ }
+ if (!onCreatorSite) {
throw new Error('Redirected away from creator center — session may have expired. ' +
'Re-capture browser login via: opencli xiaohongshu creator-profile');
}
diff --git a/packages/opencli-vendor/clis/yollomi/utils.js b/packages/opencli-vendor/clis/yollomi/utils.js
index 50c7aa4d2d..3f6fbb4da2 100644
--- a/packages/opencli-vendor/clis/yollomi/utils.js
+++ b/packages/opencli-vendor/clis/yollomi/utils.js
@@ -19,7 +19,13 @@ export const YOLLOMI_DOMAIN = 'yollomi.com';
*/
export async function ensureOnYollomi(page) {
const currentUrl = await page.evaluate(`(() => location.href)()`);
- if (!currentUrl || !currentUrl.includes('yollomi.com')) {
+ let onSite = false;
+ try {
+ const parsed = new URL(currentUrl);
+ onSite = ['http:', 'https:'].includes(parsed.protocol)
+ && (parsed.hostname === 'yollomi.com' || parsed.hostname.endsWith('.yollomi.com'));
+ } catch { /* Invalid locations must navigate to the real site. */ }
+ if (!onSite) {
await page.goto('https://yollomi.com');
await page.wait(3);
}
diff --git a/packages/opencli-vendor/src/browser/utils.ts b/packages/opencli-vendor/src/browser/utils.ts
index ccf2779a13..1d9049754a 100644
--- a/packages/opencli-vendor/src/browser/utils.ts
+++ b/packages/opencli-vendor/src/browser/utils.ts
@@ -46,11 +46,9 @@ export function wrapForEval(js: string): string {
const code = js.trim();
if (!code) return 'undefined';
- // Already an IIFE: `(async () => { ... })()` or `(function() {...})()`
- if (/^\([\s\S]*\)\s*\(.*\)\s*$/.test(code)) return code;
-
// Arrow function: `() => ...` or `async () => ...`
- if (/^(async\s+)?(\([^)]*\)|[A-Za-z_]\w*)\s*=>/.test(code)) return `(${code})()`;
+ // Exclude nested opening parentheses so an IIFE stays a bare expression.
+ if (/^(async\s+)?(\([^()]*\)|[A-Za-z_]\w*)\s*=>/.test(code)) return `(${code})()`;
// Function declaration: `function ...` or `async function ...`
if (/^(async\s+)?function[\s(]/.test(code)) return `(${code})()`;
diff --git a/packages/opencli-vendor/src/pipeline/template.ts b/packages/opencli-vendor/src/pipeline/template.ts
index 7e1ebfc5da..20e009823d 100644
--- a/packages/opencli-vendor/src/pipeline/template.ts
+++ b/packages/opencli-vendor/src/pipeline/template.ts
@@ -18,18 +18,28 @@ import { log } from '../logger.js';
export function render(template: unknown, ctx: RenderContext): unknown {
if (typeof template !== 'string') return template;
const trimmed = template.trim();
- // Full expression: entire string is a single ${{ ... }}
- // Use [^}] to prevent matching across }} boundaries (e.g. "${{ a }}-${{ b }}")
- const fullMatch = trimmed.match(/^\$\{\{\s*([^}]*(?:\}[^}][^}]*)*)\s*\}\}$/);
- if (fullMatch && !trimmed.includes('}}-') && !trimmed.includes('}}${{')) return evalExpr(fullMatch[1].trim(), ctx);
- // Check if the entire string is a single expression (no other text around it)
- const singleExpr = trimmed.match(/^\$\{\{\s*([\s\S]*?)\s*\}\}$/);
- if (singleExpr) {
- // Verify it's truly a single expression (no other ${{ inside)
- const inner = singleExpr[1];
- if (!inner.includes('${{')) return evalExpr(inner.trim(), ctx);
+ if (trimmed.startsWith('${{') && trimmed.endsWith('}}')) {
+ const inner = trimmed.slice(3, -2);
+ const singleClosingBraces = !inner.includes('}}') && !inner.endsWith('}');
+ if (singleClosingBraces || !inner.includes('${{')) return evalExpr(inner.trim(), ctx);
}
- return template.replace(/\$\{\{\s*(.*?)\s*\}\}/g, (_m, expr) => String(evalExpr(expr.trim(), ctx)));
+ // Scan delimiters once rather than retrying a backtracking regexp at each
+ // opener. Keep malformed/unclosed templates as text, as before.
+ const parts: string[] = [];
+ let cursor = 0;
+ while (cursor < template.length) {
+ const start = template.indexOf('${{', cursor);
+ if (start < 0) break;
+ const end = template.indexOf('}}', start + 3);
+ if (end < 0) break;
+ const expr = template.slice(start + 3, end);
+ parts.push(template.slice(cursor, start));
+ parts.push(/[\r\n\u2028\u2029]/.test(expr)
+ ? template.slice(start, end + 2) : String(evalExpr(expr.trim(), ctx)));
+ cursor = end + 2;
+ }
+ parts.push(template.slice(cursor));
+ return parts.join('');
}
export function evalExpr(expr: string, ctx: RenderContext): unknown {