@jayyuen66/dsh-scrapling 0.0.1-rc → 0.0.1-rc.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +93 -11
- package/README.zh-CN.md +69 -7
- package/client.js +833 -1
- package/host.js +13 -10
- package/package.json +1 -1
- package/py/adapters.py +56 -9
- package/py/crawl.py +11 -3
- package/py/guard.py +510 -7
package/README.md
CHANGED
|
@@ -151,9 +151,13 @@ displays normally. Use `scrapling_fetch` directly when you need `html` or a CSS
|
|
|
151
151
|
|
|
152
152
|
## Configuration
|
|
153
153
|
|
|
154
|
-
Settings live
|
|
155
|
-
[`host.ts`](./host.ts)
|
|
156
|
-
|
|
154
|
+
Settings live on the **scrapling** card in the plugin detail page (Settings → Plugins →
|
|
155
|
+
expand this bundle). Every field marked user-editable in [`host.ts`](./host.ts) appears
|
|
156
|
+
there, grouped by what it is for and with a one-line "what changes if you edit this";
|
|
157
|
+
deployment-level fields are only settable through the `config:` block in
|
|
158
|
+
[`cordis.patch.yml`](./cordis.patch.yml). Setting a field back to its default saves a
|
|
159
|
+
**clear-override**, not a write of the same value - so when the default changes later,
|
|
160
|
+
that field follows along.
|
|
157
161
|
|
|
158
162
|
Notable switches:
|
|
159
163
|
|
|
@@ -194,14 +198,16 @@ Notable switches:
|
|
|
194
198
|
feeds both layers, so an explicitly allowed intranet target is not rejected by the
|
|
195
199
|
host-side policy before the Python side ever sees it. Pointing it at an intranet
|
|
196
200
|
address means giving up SSRF protection for those targets on purpose.
|
|
197
|
-
- `
|
|
198
|
-
proxy
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
201
|
+
- `syntheticDnsRanges` - manual fallback for synthetic DNS: a comma-separated CIDR list
|
|
202
|
+
of your proxy's fake-IP pool. Detection is the main path and should handle it; this is
|
|
203
|
+
for the case where the resolver mixes synthetic and real answers. Invalid entries are
|
|
204
|
+
dropped rather than refusing to load - this is a fallback, and a broken one degrades to
|
|
205
|
+
"stay strict", not to a crash.
|
|
206
|
+
- `proxyUrl` - where fetches go out, e.g. `http://127.0.0.1:7890` or
|
|
207
|
+
`socks5://127.0.0.1:7890`, optionally with `user:pass@`. **Empty means follow the
|
|
208
|
+
environment.** It is a deployment-level capability and never enters a tool schema. The
|
|
209
|
+
resolution order is spelled out under [Proxies](#proxies).
|
|
210
|
+
- `proxyBypass` - host names that should connect directly, mirroring `NO_PROXY`.
|
|
205
211
|
|
|
206
212
|
**Deployment-grade knobs** (not on the settings card; set them in the `config:` block of
|
|
207
213
|
`cordis.patch.yml`): `requestTimeoutSeconds`, `maxUrlLength`, `browserExecutablePath`,
|
|
@@ -217,6 +223,82 @@ deployment config and are unreachable from model input.
|
|
|
217
223
|
Disabling a tool also removes its system-prompt guidance, so the model is never told
|
|
218
224
|
about a capability that is not registered.
|
|
219
225
|
|
|
226
|
+
## Proxies
|
|
227
|
+
|
|
228
|
+
Where a fetch goes out, resolved in this order - **first hit wins**:
|
|
229
|
+
|
|
230
|
+
1. `proxyBypass` or the environment's `NO_PROXY` matches this host -> direct.
|
|
231
|
+
2. `proxyUrl` on the settings card is non-empty -> use it.
|
|
232
|
+
3. `http_proxy` / `https_proxy` / `all_proxy` in the environment (upper case works too) ->
|
|
233
|
+
use the matching slot.
|
|
234
|
+
4. The operating system's proxy settings (`scutil --proxy` on macOS, Internet Settings on
|
|
235
|
+
Windows) -> use them.
|
|
236
|
+
5. Neither -> direct.
|
|
237
|
+
|
|
238
|
+
Each rung exists because leaving it out loses a class of users. The settings card is
|
|
239
|
+
explicit intent; environment variables cover CI, ssh sessions and `docker exec`, where a
|
|
240
|
+
proxy is only ever `export`ed in the shell; the OS settings are what proxy clients default
|
|
241
|
+
to on macOS and Windows - flip "system proxy" on in Clash Verge or Surge and every browser
|
|
242
|
+
on the machine is proxied, while curl_cffi has no idea system settings exist.
|
|
243
|
+
|
|
244
|
+
An explicit `proxyUrl` makes the last two rungs irrelevant: an explicit setting should
|
|
245
|
+
outrank an implicit source, otherwise "I set 7890 and it still goes through 1080" has
|
|
246
|
+
nowhere to be debugged from. The bypass list cuts across everything above it - a hit
|
|
247
|
+
connects directly no matter where the proxy came from.
|
|
248
|
+
|
|
249
|
+
What that looks like in practice - **with or without a proxy, the tools just work, with no
|
|
250
|
+
setting to fill in**:
|
|
251
|
+
|
|
252
|
+
| Your setup | Static fetching | Render / stealth / XHR |
|
|
253
|
+
| --- | --- | --- |
|
|
254
|
+
| No proxy | direct | direct |
|
|
255
|
+
| TUN mode (system-wide) | direct, forwarded by the TUN | same |
|
|
256
|
+
| `HTTPS_PROXY` exported in the shell | follows it automatically | follows it automatically |
|
|
257
|
+
| macOS / Windows "system proxy" switch | **follows it automatically** | follows it automatically |
|
|
258
|
+
| Intranet targets / internal Git | exclude with `proxyBypass` | exclude with `proxyBypass` |
|
|
259
|
+
| PAC (auto-config script) | not followed; stderr says to set `proxyUrl` | followed natively by the browser |
|
|
260
|
+
|
|
261
|
+
PAC is the one shape that still needs a hand-filled setting: evaluating it means
|
|
262
|
+
downloading a script and running JavaScript, and the dialects differ per platform, so this
|
|
263
|
+
plugin does not guess. When it sees one it says so on stderr instead of quietly connecting
|
|
264
|
+
directly.
|
|
265
|
+
|
|
266
|
+
Details worth knowing:
|
|
267
|
+
|
|
268
|
+
- **A proxy and synthetic DNS are two different problems.** A fake-IP proxy resolves
|
|
269
|
+
**every** domain into `198.18.0.0/15` (TUN clients often land in `100.64.0.0/10`);
|
|
270
|
+
neither is a public unicast range, so the gate rejects every URL and turning a proxy on
|
|
271
|
+
makes the plugin stop working. The plugin **detects** that class of resolver on its
|
|
272
|
+
own: it resolves three control names unrelated to any target - `example.com`,
|
|
273
|
+
`www.iana.org`, `www.wikipedia.org` - and if all of them land in one non-public pool
|
|
274
|
+
while staying distinct, it treats the resolver as fake-IP and **learns that pool's
|
|
275
|
+
boundary from the control answers**, allowing only addresses inside it.
|
|
276
|
+
`syntheticDnsRanges` is the manual fallback for detection failures. When detection does
|
|
277
|
+
not fire, the gate **stays strict**; an IP literal written into the URL is still judged
|
|
278
|
+
strictly, so `http://169.254.169.254/` stays blocked either way.
|
|
279
|
+
- **Through a proxy, a host name this machine cannot resolve is no longer rejected.** The
|
|
280
|
+
request never leaves this machine's network namespace, the proxy resolves the name, and
|
|
281
|
+
a local resolver coming up empty says nothing - while on a network with DNS filtered by
|
|
282
|
+
region, those are exactly the sites that need a proxy to be reachable at all. IP
|
|
283
|
+
literals, private answers the local resolver *can* produce, and single-label host names
|
|
284
|
+
(`intranet`, `router`) stay rejected.
|
|
285
|
+
- **WebRTC leaks are closed when proxied.** Chromium's WebRTC can send UDP around an
|
|
286
|
+
HTTP/SOCKS proxy, so one STUN call in a page is enough to learn the visitor's real exit
|
|
287
|
+
address. patchright gets `block_webrtc`; Playwright has no equivalent switch, so it goes
|
|
288
|
+
in as a Chromium launch flag.
|
|
289
|
+
- **A browser session picks its proxy once, at `session_open`**, and the whole session
|
|
290
|
+
shares it. The bypass list therefore does not apply per URL inside a browser session:
|
|
291
|
+
Playwright's proxy lives on the BrowserContext, and switching it means a new context,
|
|
292
|
+
which throws away the session's cookies and login state - precisely the reason a
|
|
293
|
+
session exists. Static sessions have no such limit and decide per request.
|
|
294
|
+
- **Credentials never reach a log or the capability frame.** The capability report echoes
|
|
295
|
+
`scheme://host:port` only, and its `source` field names which rung answered
|
|
296
|
+
(`settings` / `environment` / `system` / `none`) - that column is the first thing to look
|
|
297
|
+
at when someone reports that fetching does not work.
|
|
298
|
+
- **A malformed proxy address does not stop the plugin from loading.** A scheme outside
|
|
299
|
+
`http` / `https` / `socks4` / `socks5` / `socks5h` is logged to stderr and treated as
|
|
300
|
+
"not configured", rather than thrown out as a load failure.
|
|
301
|
+
|
|
220
302
|
## Security notes
|
|
221
303
|
|
|
222
304
|
- **SSRF.** Scrapling itself has no SSRF protection. This plugin adds a URL policy on
|
package/README.zh-CN.md
CHANGED
|
@@ -133,8 +133,10 @@ Scrapling 的 Markdown 输出报成 `text`,内置渲染路径显示完全正
|
|
|
133
133
|
|
|
134
134
|
## 配置
|
|
135
135
|
|
|
136
|
-
|
|
137
|
-
|
|
136
|
+
设置项在插件详情页的 **scrapling** 卡片下(设置 → 插件 → 展开本包)。[`host.ts`](./host.ts)
|
|
137
|
+
里标了可编辑的字段都会按用途分组出现在卡上,每项带一句「改了会怎样」;部署级字段只能通过
|
|
138
|
+
[`cordis.patch.yml`](./cordis.patch.yml) 的 `config:` 块设置。卡片把值改回默认值时保存的是
|
|
139
|
+
「清除覆盖」而不是写入同一个值——将来默认值变了,你这一项就会跟着变。
|
|
138
140
|
|
|
139
141
|
主要开关:
|
|
140
142
|
|
|
@@ -151,11 +153,13 @@ Scrapling 的 Markdown 输出报成 `text`,内置渲染路径显示完全正
|
|
|
151
153
|
因此**拿到的不是字节级原始 HTML**。
|
|
152
154
|
- `allowedHosts` —— **安全相关的放行名单**,默认空(最严)。指向内网等于主动放弃那些目标
|
|
153
155
|
的 SSRF 防护,抓自建/内网站点时才会需要。它同时喂 Host 闸门与 Python 侧守卫,两边同解。
|
|
154
|
-
- `
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
156
|
+
- `syntheticDnsRanges` —— 合成 DNS 的**手动兜底**:填你那个代理的 fake-IP 段(CIDR,逗号
|
|
157
|
+
分隔)。主路径是自动检测(见下「代理」),这一项留给「解析器把合成地址和真地址混着返回」
|
|
158
|
+
的场合。写错的段直接丢掉而不是让插件起不来——它只是兜底,坏了退化成「维持最严」,不该崩。
|
|
159
|
+
- `proxyUrl` —— 抓取从哪儿出去,形如 `http://127.0.0.1:7890` 或
|
|
160
|
+
`socks5://127.0.0.1:7890`,可带 `user:pass@`。**留空表示跟随环境。** 它是部署级能力,
|
|
161
|
+
绝不进入任何工具 schema。判定顺序见下面的「代理」。
|
|
162
|
+
- `proxyBypass` —— 直连、不走代理的主机名,对应 `NO_PROXY`。
|
|
159
163
|
- `*MaxOutputChars` —— 各工具的输出封顶。宿主侧的封顶只影响进模型上下文的那一段,
|
|
160
164
|
真正的字节上限在 Python 侧(`maxContentChars`)。`crawlMaxItems` 是部署侧给模型可传的
|
|
161
165
|
`maxPages` 封的顶;越界的 `maxPages`(0、负数、NaN)**原样透传**,让 sidecar 报参数错误,
|
|
@@ -183,6 +187,64 @@ Scrapling 的 Markdown 输出报成 `text`,内置渲染路径显示完全正
|
|
|
183
187
|
关掉某个工具时,它的 system prompt 指引段**也一并消失**,
|
|
184
188
|
不会出现「工具没了但提示词还在」的割裂。
|
|
185
189
|
|
|
190
|
+
## 代理
|
|
191
|
+
|
|
192
|
+
抓取从哪儿出去,按这个顺序判定,**先命中先算**:
|
|
193
|
+
|
|
194
|
+
1. `proxyBypass` 或环境里的 `NO_PROXY` 命中这个主机 → 直连。
|
|
195
|
+
2. 设置卡上的 `proxyUrl` 非空 → 用它。
|
|
196
|
+
3. 环境里的 `http_proxy` / `https_proxy` / `all_proxy`(大写同样认)→ 用对应那一栏。
|
|
197
|
+
4. 操作系统的**代理设置**(macOS 的 `scutil --proxy`、Windows 的 Internet Settings)→ 用它。
|
|
198
|
+
5. 都没有 → 直连。
|
|
199
|
+
|
|
200
|
+
四档各自的存在理由,少一档就有一类用户抓不到东西:设置卡是显式意图;环境变量覆盖 CI、
|
|
201
|
+
ssh 会话、docker exec 这类只在 shell 里 export 过的地方;系统代理是 macOS 与 Windows 上
|
|
202
|
+
代理软件的默认形态——Clash Verge、Surge 等把「系统代理」一勾,浏览器立刻就上,而
|
|
203
|
+
curl_cffi 对系统设置一无所知,不补这一档就会发现「浏览器能上、本插件的静态抓取抓不到」。
|
|
204
|
+
|
|
205
|
+
设置卡里显式填了 `proxyUrl`,后面两档整份被忽略:显式设置就该压过隐式来源,否则「我明明
|
|
206
|
+
填了 7890 却还在走 1080」这类问题无从查起。绕过清单横切在最前,命中即直连。
|
|
207
|
+
|
|
208
|
+
各环境下的实际表现 —— **开或不开代理,工具都直接可用,一行设置都不用填**:
|
|
209
|
+
|
|
210
|
+
| 你的环境 | 静态抓取 | 渲染 / 反检测 / XHR |
|
|
211
|
+
| --- | --- | --- |
|
|
212
|
+
| 不开代理 | 直连 | 直连 |
|
|
213
|
+
| TUN 模式(系统层接管) | 直连,由 TUN 转发 | 同左 |
|
|
214
|
+
| 只在 shell 里 export `HTTPS_PROXY` | 自动跟随 | 自动跟随 |
|
|
215
|
+
| macOS / Windows「系统代理」开关 | **自动跟随** | 自动跟随 |
|
|
216
|
+
| 内网站点 / 内网 Git | 用 `proxyBypass` 排除 | 用 `proxyBypass` 排除 |
|
|
217
|
+
| PAC(自动配置脚本) | 不跟随,stderr 会提示填 `proxyUrl` | 浏览器原生跟随 |
|
|
218
|
+
|
|
219
|
+
PAC 是唯一还需要手工填一次的形态:求值 PAC 要下载脚本并跑 JavaScript,各平台格式互不相同,
|
|
220
|
+
本包不猜。见到 PAC 时会在 stderr 指明该填 `proxyUrl`,而不是静默直连。
|
|
221
|
+
|
|
222
|
+
几条容易踩的细节:
|
|
223
|
+
|
|
224
|
+
- **代理与合成 DNS 是两件事。** fake-IP 模式的代理把**每个**域名都解析进 `198.18.0.0/15`
|
|
225
|
+
(TUN 客户端常落在 `100.64.0.0/10`),两段都不是公网 unicast,闸门于是把每个 URL 都判成
|
|
226
|
+
私网——开了代理反而全都抓不了。插件**自动识别**这一类解析器:从 `example.com` /
|
|
227
|
+
`www.iana.org` / `www.wikipedia.org` 三个与用户目标无关的控制域名各解析一次,全部落在同一段
|
|
228
|
+
非公网小池且互不相同,即判为 fake-ip,并**从控制域名的答案里学出那个池子的边界**,只放行
|
|
229
|
+
落在池内的地址。`syntheticDnsRanges` 是识别失灵时的手动兜底。识别不出来时**维持最严**,
|
|
230
|
+
不会误放行;URL 里写死的 IP 字面量照旧严格判定,`http://169.254.169.254/` 始终被拒。
|
|
231
|
+
- **走了代理时,本机解析不出来的主机名不再判否。** 请求不从本机网络命名空间出去,域名由代理
|
|
232
|
+
解析,本机解析器答不上来什么也说明不了——而在 DNS 被按地区过滤的网络里,恰恰是这些站点才
|
|
233
|
+
需要代理才能访问。IP 字面量、本地能解析出来的私网答案、单标签主机名(`intranet`、`router`
|
|
234
|
+
这类)三条**照旧拒**。
|
|
235
|
+
- **走代理时会关掉 WebRTC 泄露。** Chromium 的 WebRTC 能绕过 HTTP/SOCKS 代理直接发 UDP,页面
|
|
236
|
+
里一句 STUN 就能问出访客的真实出口 IP。patchright 用 `block_webrtc`,Playwright 没有对应
|
|
237
|
+
开关,走 Chromium 的启动 flag。
|
|
238
|
+
- **浏览器会话的代理在 `session_open` 时定一次**,之后整个会话共用。绕过清单因此对浏览器会话
|
|
239
|
+
不逐 URL 生效——Playwright 的代理挂在 BrowserContext 上,中途换只能新建 context,而新建就
|
|
240
|
+
等于丢掉这个会话攒下的 cookie 与登录态,那恰恰是会话存在的理由。静态会话没有这个限制,
|
|
241
|
+
每个请求各自判一次。
|
|
242
|
+
- **凭据不会出现在任何日志或能力协商帧里。** 能力上报只回显 `scheme://host:port`,并用 `source`
|
|
243
|
+
标出代理来自 `settings` / `environment` / `system` / `none` 哪一档——用户报「抓不到东西」时,
|
|
244
|
+
这一栏就是第一眼的答案。
|
|
245
|
+
- **填错的代理地址不会让插件起不来。** 协议不在 `http` / `https` / `socks4` / `socks5` /
|
|
246
|
+
`socks5h` 之内时记一行 stderr 并按「未配置」处理,而不是抛出去让插件加载失败。
|
|
247
|
+
|
|
186
248
|
## 安全说明
|
|
187
249
|
|
|
188
250
|
- **SSRF。** Scrapling 自身**没有任何** SSRF 防护。本插件在 Host 侧加一层 URL 策略
|