Skip to content

Official Crawl4AI Cloud: a hosted web scraping, extraction, and search API for AI agents. Free API key, 1,000 credits a month, no card. Fully open source: this repo is the Apache-2.0 crawler that powers it, and you can self-host it.

fix(playground): forward the typed params, and clear status when config is empty

ntohidie138aa0f68e5
diff --git a/deploy/docker/static/playground/index.html b/deploy/docker/static/playground/index.html
index f905652f..1b0353b5 100644
--- a/deploy/docker/static/playground/index.html
+++ b/deploy/docker/static/playground/index.html
@@ -568,11 +568,14 @@
}
// Validate the editor's params against /config/dump and return the
- // normalized { type, params } the crawl endpoints expect. Throws with the
- // server's message so the caller can surface the offending field.
+ // { type, params } the crawl endpoints expect. Throws with the server's
+ // message so the caller can surface the offending field.
async function validateConfig() {
const text = cm.getValue().trim();
- if (!text) return {};
+ if (!text) {
+ setCfgStatus('', 'text-secondary'); // no config is not an error
+ return {};
+ }
let params;
try {
@@ -585,7 +588,10 @@
setCfgStatus('✖ expected a JSON object', 'text-red-400');
throw new Error('Advanced Config must be a JSON object of parameters');
}
- if (!Object.keys(params).length) return {};
+ if (!Object.keys(params).length) {
+ setCfgStatus('', 'text-secondary'); // no config is not an error
+ return {};
+ }
const cfgType = document.getElementById('cfg-type').value;
const res = await authFetch('/config/dump', {
@@ -601,7 +607,11 @@
}
setCfgStatus('✓ validated', 'text-green-400');
- return await res.json();
+ // Send back what the user typed, not /config/dump's echo. dump()
+ // fills in server-derived fields -- BrowserConfig gains generated
+ // `headers` -- that the untrusted gate then refuses on /crawl, so
+ // the echo is a validation result, not a re-submittable payload.
+ return { type: cfgType, params };
}
// ================ SERVER COMMUNICATION ================
diff --git a/deploy/docker/tests/test_playground_config_protocol.py b/deploy/docker/tests/test_playground_config_protocol.py
index dcb330e2..926b113d 100644
--- a/deploy/docker/tests/test_playground_config_protocol.py
+++ b/deploy/docker/tests/test_playground_config_protocol.py
@@ -96,10 +96,29 @@ class TestTemplatesSurviveTheUntrustedGate(unittest.TestCase):
def test_stream_reaches_the_shape_should_use_stream_reads(self):
"""runCrawl picks the streaming endpoint off crawler_config.params.stream."""
params = json.loads(read_templates()["CrawlerRunConfig"])
- dumped = CrawlerRunConfig.load(
- {"type": "CrawlerRunConfig", "params": params}, provenance=Provenance.UNTRUSTED
+ self.assertIs(params.get("stream"), True)
+
+ def test_the_validated_params_are_forwarded_not_the_dump_echo(self):
+ """dump() adds server-derived fields the untrusted gate then refuses.
+
+ BrowserConfig picks up generated `headers`, which is not allowlisted, so
+ posting /config/dump's echo to /crawl 400s. The page must forward the
+ params the user typed.
+ """
+ params = json.loads(read_templates()["BrowserConfig"])
+ echo = BrowserConfig.load(
+ {"type": "BrowserConfig", "params": params}, provenance=Provenance.UNTRUSTED
).dump()
- self.assertIs(dumped["params"].get("stream"), True)
+ forbidden = set(echo["params"]) - UNTRUSTED_FIELD_ALLOWLIST["BrowserConfig"]
+ self.assertTrue(
+ forbidden,
+ "if dump() ever became re-submittable this guard can go, but check the page first",
+ )
+ page = read_page()
+ self.assertIn("return { type: cfgType, params };", page,
+ "validateConfig must forward the typed params, not the echo")
+ self.assertNotIn("return await res.json();", page,
+ "the /config/dump echo must not be forwarded to /crawl")
def test_the_old_code_protocol_is_still_refused(self):
"""Guards the reason for this change: {type, code} cannot come back."""