pi-cloudflare 0.6.10 → 0.8.0
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/package.json
CHANGED
package/plugin.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"$schema": "https://agent-plugins.org/schemas/1.0.0/plugin.schema.json",
|
|
3
3
|
"name": "pi-cloudflare",
|
|
4
|
-
"version": "0.
|
|
4
|
+
"version": "0.8.0",
|
|
5
5
|
"description": "Cloudflare skills and cf_-prefixed MCP tools, with a native Pi adapter and an Agent Plugins 1.0 portable runtime.",
|
|
6
6
|
"author": {
|
|
7
7
|
"name": "0xPlayerOne",
|
|
@@ -103,6 +103,17 @@ Then check the ruleset phases and add what is missing:
|
|
|
103
103
|
- **`http_request_cache_settings`** — only with a measured reason; see
|
|
104
104
|
[Safety rules](#safety-rules-do-not-blanket-change).
|
|
105
105
|
|
|
106
|
+
And remove what hurts performance. Hardening is not only additive:
|
|
107
|
+
|
|
108
|
+
- **`enable_js` (JavaScript Detections)** — injects
|
|
109
|
+
`/cdn-cgi/challenge-platform/scripts/jsd/main.js` into every HTML response and
|
|
110
|
+
trips Lighthouse Best Practices "Avoid deprecated APIs", costing roughly 40
|
|
111
|
+
Best-Practices points on a fast site. Turn it off; it protects nothing that
|
|
112
|
+
`ai_bots_protection: "block"` does not cover without injecting anything.
|
|
113
|
+
- **`fight_mode` (Bot Fight Mode)** — a genuine tradeoff rather than a free win.
|
|
114
|
+
It adds edge protection but rides on the same injected detection script. Report
|
|
115
|
+
the cost and let the user choose.
|
|
116
|
+
|
|
106
117
|
### 3. Per zone: DNSSEC
|
|
107
118
|
|
|
108
119
|
Read `GET /zones/:id/dnssec`. If `disabled`, it is safe to stage: enabling is
|
|
@@ -66,14 +66,90 @@ Check that field before attempting a write; the PATCH will not tell you.
|
|
|
66
66
|
The AI-bot and fight-mode fields live here, not under `/settings`. Use `PUT` —
|
|
67
67
|
`PATCH` answers `405 10405`.
|
|
68
68
|
|
|
69
|
+
Send **only the fields being changed**. Echoing the whole object back fails with
|
|
70
|
+
`400 Bad Request`, because the write rejects computed and read-only fields
|
|
71
|
+
(`is_robots_txt_managed`, `using_latest_model`, and friends). Every other
|
|
72
|
+
setting is preserved on its own, so a partial body is correct rather than risky.
|
|
73
|
+
|
|
69
74
|
```jsonc
|
|
70
|
-
// read first
|
|
75
|
+
// read first to see what is on
|
|
71
76
|
GET /zones/:zone_id/bot_management
|
|
72
77
|
|
|
73
78
|
PUT /zones/:zone_id/bot_management
|
|
74
79
|
{ "ai_bots_protection": "block" } // disabled | only_on_ad_pages | block
|
|
75
80
|
```
|
|
76
81
|
|
|
82
|
+
### JavaScript Detections and Bot Fight Mode inject a script
|
|
83
|
+
|
|
84
|
+
Two fields on the same object add JavaScript to **every HTML response**:
|
|
85
|
+
|
|
86
|
+
| Field | Dashboard toggle | Effect |
|
|
87
|
+
| --- | --- | --- |
|
|
88
|
+
| `enable_js` | Security → Bots → JavaScript Detections | Injects `/cdn-cgi/challenge-platform/scripts/jsd/main.js` |
|
|
89
|
+
| `fight_mode` | Security → Bots → Bot Fight Mode | Adds edge protection; also drives the injected detection script |
|
|
90
|
+
|
|
91
|
+
The injected script trips Lighthouse Best Practices **"Avoid deprecated APIs"**
|
|
92
|
+
and costs roughly 40 Best-Practices points on a fast site, so treat `enable_js:
|
|
93
|
+
true` as a performance finding rather than a security win. Turning both off is a
|
|
94
|
+
tradeoff, not a free fix — it also removes edge bot protection, so say so in the
|
|
95
|
+
report.
|
|
96
|
+
|
|
97
|
+
```jsonc
|
|
98
|
+
PUT /zones/:zone_id/bot_management
|
|
99
|
+
{ "enable_js": false, "fight_mode": false }
|
|
100
|
+
```
|
|
101
|
+
|
|
102
|
+
`ai_bots_protection: "block"` is the compromise: it blocks AI scrapers at the
|
|
103
|
+
edge, injects no script, and costs nothing. Prefer it when the user wants bot
|
|
104
|
+
protection without the performance hit.
|
|
105
|
+
|
|
106
|
+
## Workers
|
|
107
|
+
|
|
108
|
+
Inventory scripts, then check each one's settings:
|
|
109
|
+
|
|
110
|
+
```bash
|
|
111
|
+
GET /accounts/:account_id/workers/scripts
|
|
112
|
+
GET /accounts/:account_id/workers/scripts/:script/settings
|
|
113
|
+
```
|
|
114
|
+
|
|
115
|
+
Three things to check per script:
|
|
116
|
+
|
|
117
|
+
- **`observability.enabled`** — free, and off by default in some deploy paths.
|
|
118
|
+
Workers with it off produce no logs when something breaks, so treat an estate
|
|
119
|
+
with mixed states as a gap and align it.
|
|
120
|
+
- **`compatibility_date`** — anything more than a few months old is worth
|
|
121
|
+
flagging; stale dates silently gate new runtime behaviour.
|
|
122
|
+
- **`bindings`** — confirm the script has what it needs and nothing orphaned.
|
|
123
|
+
|
|
124
|
+
Two traps on this endpoint:
|
|
125
|
+
|
|
126
|
+
- **`PATCH` requires `multipart/form-data`, not JSON.** A JSON body fails with
|
|
127
|
+
`Content-Type must be one of: multipart/form-data`. Send the settings as a
|
|
128
|
+
`settings` part:
|
|
129
|
+
|
|
130
|
+
```js
|
|
131
|
+
const fd = new FormData()
|
|
132
|
+
fd.append('settings', new Blob([JSON.stringify({
|
|
133
|
+
observability: { enabled: true, head_sampling_rate: 1 },
|
|
134
|
+
})], { type: 'application/json' }))
|
|
135
|
+
fetch(`.../workers/scripts/:script/settings`, { method: 'PATCH', headers, body: fd })
|
|
136
|
+
```
|
|
137
|
+
|
|
138
|
+
- **`GET /accounts/:id/workers/domains` ignores the `worker_name` filter** and
|
|
139
|
+
returns every custom domain on the account. Do not conclude that several
|
|
140
|
+
workers share one hostname from that response — map hostnames by the `service`
|
|
141
|
+
field, or query without a filter and group client-side.
|
|
142
|
+
|
|
143
|
+
Custom-domain mapping (the clean way):
|
|
144
|
+
|
|
145
|
+
```bash
|
|
146
|
+
GET /accounts/:account_id/workers/domains
|
|
147
|
+
# each entry: { hostname, service } — service is the worker name
|
|
148
|
+
```
|
|
149
|
+
|
|
150
|
+
A preview worker should have **no** custom domain; if it does, that is worth
|
|
151
|
+
reporting. Preview URLs should sit behind an Access app.
|
|
152
|
+
|
|
77
153
|
## Free managed WAF ruleset
|
|
78
154
|
|
|
79
155
|
The managed ruleset object **already exists** on every zone but is not applied —
|
|
@@ -121,6 +121,9 @@ const RULESET_PHASES = [
|
|
|
121
121
|
'http_request_firewall_custom',
|
|
122
122
|
]
|
|
123
123
|
|
|
124
|
+
// A compatibility date older than this means new runtime behaviour is gated off.
|
|
125
|
+
const COMPAT_CUTOFF = '2024-06-01'
|
|
126
|
+
|
|
124
127
|
// Headers we expect on a hardened content response. HSTS is handled separately
|
|
125
128
|
// because enabling includeSubDomains needs care and sign-off.
|
|
126
129
|
const EXPECTED_HEADERS = ['x-content-type-options', 'referrer-policy']
|
|
@@ -207,13 +210,31 @@ async function auditZone(zone) {
|
|
|
207
210
|
}
|
|
208
211
|
|
|
209
212
|
// Bot management (AI bots / fight mode live here, not under /settings).
|
|
213
|
+
// enable_js injects a detection script into every HTML response, so it is a
|
|
214
|
+
// performance finding rather than a security gap. fight_mode is a genuine
|
|
215
|
+
// tradeoff and is reported, not flagged.
|
|
210
216
|
const bot = await get(`/zones/${zone.id}/bot_management`)
|
|
211
217
|
if (bot.result) {
|
|
212
|
-
if (bot.result.
|
|
213
|
-
add(
|
|
218
|
+
if (bot.result.enable_js === true) {
|
|
219
|
+
add(
|
|
220
|
+
zone.name,
|
|
221
|
+
'high',
|
|
222
|
+
'javascript detections',
|
|
223
|
+
'injects /cdn-cgi/challenge-platform/scripts/jsd/main.js into every HTML response',
|
|
224
|
+
'turn off (PUT bot_management {enable_js:false}) — it trips Lighthouse Best Practices "deprecated API"'
|
|
225
|
+
)
|
|
214
226
|
}
|
|
215
|
-
if (bot.result.fight_mode ===
|
|
216
|
-
add(
|
|
227
|
+
if (bot.result.fight_mode === true) {
|
|
228
|
+
add(
|
|
229
|
+
zone.name,
|
|
230
|
+
'info',
|
|
231
|
+
'bot fight mode',
|
|
232
|
+
'on — a real tradeoff, not a free win',
|
|
233
|
+
'adds edge protection but costs roughly 40 Lighthouse Best-Practices points via the injected detection script'
|
|
234
|
+
)
|
|
235
|
+
}
|
|
236
|
+
if (bot.result.ai_bots_protection && bot.result.ai_bots_protection !== 'block') {
|
|
237
|
+
add(zone.name, 'info', 'ai_bots_protection', `currently ${bot.result.ai_bots_protection}`, 'consider "block" — enforced at the edge, injects no script')
|
|
217
238
|
}
|
|
218
239
|
}
|
|
219
240
|
|
|
@@ -312,6 +333,62 @@ async function auditAccount(account) {
|
|
|
312
333
|
return summary
|
|
313
334
|
}
|
|
314
335
|
|
|
336
|
+
/**
|
|
337
|
+
* Workers inventory: observability, compatibility date, and custom-domain
|
|
338
|
+
* mapping. Note the domains endpoint ignores worker_name filters, so hostnames
|
|
339
|
+
* are grouped by their `service` field rather than trusted from a per-worker
|
|
340
|
+
* query.
|
|
341
|
+
*/
|
|
342
|
+
async function auditWorkers(account) {
|
|
343
|
+
const accountStart = findings.length
|
|
344
|
+
const summary = { observabilityOff: [], staleCompat: [] }
|
|
345
|
+
|
|
346
|
+
const scripts = await get(`/accounts/${account.id}/workers/scripts`)
|
|
347
|
+
if (scripts.error) {
|
|
348
|
+
add(account.name, 'blocked', 'workers', scripts.error, 'grant Workers Scripts read')
|
|
349
|
+
summary.findings = findings.slice(accountStart)
|
|
350
|
+
return summary
|
|
351
|
+
}
|
|
352
|
+
|
|
353
|
+
const names = (scripts.result ?? []).map((s) => s.id ?? s.name)
|
|
354
|
+
summary.workers = names
|
|
355
|
+
|
|
356
|
+
for (const name of names) {
|
|
357
|
+
const settings = await get(`/accounts/${account.id}/workers/scripts/${name}/settings`)
|
|
358
|
+
if (settings.error) continue
|
|
359
|
+
const r = settings.result ?? {}
|
|
360
|
+
|
|
361
|
+
if (r.observability?.enabled !== true) {
|
|
362
|
+
summary.observabilityOff.push(name)
|
|
363
|
+
add(
|
|
364
|
+
account.name,
|
|
365
|
+
'medium',
|
|
366
|
+
`worker ${name}`,
|
|
367
|
+
'observability is OFF — no logs when it breaks',
|
|
368
|
+
'PATCH settings with observability enabled (multipart/form-data, not JSON)'
|
|
369
|
+
)
|
|
370
|
+
}
|
|
371
|
+
|
|
372
|
+
const compat = r.compatibility_date
|
|
373
|
+
if (compat && compat < COMPAT_CUTOFF) {
|
|
374
|
+
summary.staleCompat.push(`${name} (${compat})`)
|
|
375
|
+
add(account.name, 'info', `worker ${name}`, `compatibility_date ${compat} is stale`, 'update to gate in newer runtime behaviour')
|
|
376
|
+
}
|
|
377
|
+
}
|
|
378
|
+
|
|
379
|
+
const domains = await get(`/accounts/${account.id}/workers/domains`)
|
|
380
|
+
if (Array.isArray(domains.result)) {
|
|
381
|
+
summary.customDomains = domains.result.map((d) => ({ hostname: d.hostname, service: d.service }))
|
|
382
|
+
const previewish = summary.customDomains.filter((d) => /preview|staging|dev\b/i.test(d.hostname))
|
|
383
|
+
if (previewish.length === 0 && names.some((n) => /preview|staging/i.test(n))) {
|
|
384
|
+
add(account.name, 'info', 'preview workers', 'no custom domain attached', 'correct by design; preview URLs should sit behind Access')
|
|
385
|
+
}
|
|
386
|
+
}
|
|
387
|
+
|
|
388
|
+
summary.findings = findings.slice(accountStart)
|
|
389
|
+
return summary
|
|
390
|
+
}
|
|
391
|
+
|
|
315
392
|
// --- main ---
|
|
316
393
|
|
|
317
394
|
const accountsRes = await get('/accounts?per_page=50')
|
|
@@ -339,7 +416,11 @@ const auditedZones = []
|
|
|
339
416
|
for (const zone of zones) auditedZones.push(await auditZone(zone))
|
|
340
417
|
|
|
341
418
|
const auditedAccounts = []
|
|
342
|
-
for (const account of accounts)
|
|
419
|
+
for (const account of accounts) {
|
|
420
|
+
const summary = await auditAccount(account)
|
|
421
|
+
summary.workers = await auditWorkers(account)
|
|
422
|
+
auditedAccounts.push(summary)
|
|
423
|
+
}
|
|
343
424
|
|
|
344
425
|
const report = {
|
|
345
426
|
generatedAt: new Date().toISOString(),
|