Skip to content

Automate browser based workflows with AI

fix(SKY-12715): accept template variables in HTTP Request block URL validation (#7569)

Suchintane331d179b910
diff --git a/skyvern-frontend/src/routes/workflows/editor/nodes/HttpRequestNode/httpValidation.test.ts b/skyvern-frontend/src/routes/workflows/editor/nodes/HttpRequestNode/httpValidation.test.ts
index ba76a7475..7259e954d 100644
--- a/skyvern-frontend/src/routes/workflows/editor/nodes/HttpRequestNode/httpValidation.test.ts
+++ b/skyvern-frontend/src/routes/workflows/editor/nodes/HttpRequestNode/httpValidation.test.ts
@@ -114,12 +114,73 @@ describe("validateUrl", () => {
expect(result.valid).toBe(true);
});
+ test("template-only URL is valid", () => {
+ const result = validateUrl("{{login_complete_url}}");
+ expect(result.valid).toBe(true);
+ });
+
+ test("template-only URL with inner spaces is valid", () => {
+ const result = validateUrl("{{ login_complete_url }}");
+ expect(result.valid).toBe(true);
+ });
+
+ test("template URL with a path is valid", () => {
+ const result = validateUrl("{{base_url}}/api/callback");
+ expect(result.valid).toBe(true);
+ });
+
+ test("https URL with a template host is valid", () => {
+ const result = validateUrl("https://{{host}}/path");
+ expect(result.valid).toBe(true);
+ });
+
+ test("template control expression URL is valid", () => {
+ const result = validateUrl("{% if use_prod %}https://a.com{% endif %}");
+ expect(result.valid).toBe(true);
+ });
+
test("non-http protocol is invalid", () => {
const result = validateUrl("ftp://example.com");
expect(result.valid).toBe(false);
expect(result.message).toBe("URL must use HTTP or HTTPS protocol");
});
+ test("non-http protocol with a template host is invalid", () => {
+ const result = validateUrl("ftp://{{host}}");
+ expect(result.valid).toBe(false);
+ expect(result.message).toBe("URL must use HTTP or HTTPS protocol");
+ });
+
+ test("javascript scheme with a template payload is invalid", () => {
+ const result = validateUrl("javascript:{{payload}}");
+ expect(result.valid).toBe(false);
+ expect(result.message).toBe("URL must use HTTP or HTTPS protocol");
+ });
+
+ test("space-spliced javascript scheme with a template payload is invalid", () => {
+ const result = validateUrl("java script:{{payload}}");
+ expect(result.valid).toBe(false);
+ expect(result.message).toBe("URL must use HTTP or HTTPS protocol");
+ });
+
+ test("tab-spliced javascript scheme with a template payload is invalid", () => {
+ const result = validateUrl("java\tscript:{{payload}}");
+ expect(result.valid).toBe(false);
+ expect(result.message).toBe("URL must use HTTP or HTTPS protocol");
+ });
+
+ test("mailto scheme with a template address is invalid", () => {
+ const result = validateUrl("mailto:{{address}}");
+ expect(result.valid).toBe(false);
+ expect(result.message).toBe("URL must use HTTP or HTTPS protocol");
+ });
+
+ test("scheme-relative URL with a template host is invalid", () => {
+ const result = validateUrl("//{{host}}/evil.js");
+ expect(result.valid).toBe(false);
+ expect(result.message).toBe("Invalid URL format");
+ });
+
test("malformed URL is invalid", () => {
const result = validateUrl("not a url");
expect(result.valid).toBe(false);
diff --git a/skyvern-frontend/src/routes/workflows/editor/nodes/HttpRequestNode/httpValidation.ts b/skyvern-frontend/src/routes/workflows/editor/nodes/HttpRequestNode/httpValidation.ts
index d1919560b..9a922aa31 100644
--- a/skyvern-frontend/src/routes/workflows/editor/nodes/HttpRequestNode/httpValidation.ts
+++ b/skyvern-frontend/src/routes/workflows/editor/nodes/HttpRequestNode/httpValidation.ts
@@ -1,5 +1,8 @@
import { TSON } from "@/util/tson";
import { getInvalidJsonMessage } from "@/util/jsonParseError";
+import { isTemplateExpression } from "@/util/googleSheetsUrl";
+
+const HTTP_SCHEME_REQUIRED_MESSAGE = "URL must use HTTP or HTTPS protocol";
// URL Validation Helper
export function validateUrl(url: string): { valid: boolean; message: string } {
@@ -8,10 +11,26 @@ export function validateUrl(url: string): { valid: boolean; message: string } {
return { valid: false, message: "URL is required" };
}
+ const schemeProbe = trimmed.replace(/\s/g, "");
+ const explicitScheme = schemeProbe
+ .match(/^([a-zA-Z][a-zA-Z0-9+.-]*):/)?.[1]
+ ?.toLowerCase();
+ if (explicitScheme && !["http", "https"].includes(explicitScheme)) {
+ return { valid: false, message: HTTP_SCHEME_REQUIRED_MESSAGE };
+ }
+
+ if (schemeProbe.startsWith("//")) {
+ return { valid: false, message: "Invalid URL format" };
+ }
+
+ if (isTemplateExpression(trimmed)) {
+ return { valid: true, message: "Valid URL" };
+ }
+
try {
const parsed = new URL(trimmed);
if (!["http:", "https:"].includes(parsed.protocol)) {
- return { valid: false, message: "URL must use HTTP or HTTPS protocol" };
+ return { valid: false, message: HTTP_SCHEME_REQUIRED_MESSAGE };
}
return { valid: true, message: "Valid URL" };
} catch {
diff --git a/skyvern/forge/sdk/copilot/code_block_synthesis.py b/skyvern/forge/sdk/copilot/code_block_synthesis.py
index c8561a731..c31386d2b 100644
--- a/skyvern/forge/sdk/copilot/code_block_synthesis.py
+++ b/skyvern/forge/sdk/copilot/code_block_synthesis.py
@@ -37,7 +37,7 @@ from skyvern.forge.sdk.copilot.output_extraction_plan import (
output_path_segments,
)
from skyvern.forge.sdk.copilot.reached_download_target import ReachedDownloadTarget
-from skyvern.forge.sdk.copilot.runtime import ScoutedFieldParameterBinding, ScoutedInputCorrespondence
+from skyvern.forge.sdk.copilot.runtime import ScoutedInputCorrespondence
from skyvern.utils.strings import escape_code_fences
LOG = structlog.get_logger()
@@ -329,30 +329,6 @@ def grounded_parameter_key_is_safe(parameter_key: str) -> bool:
)
-def grounded_submit_rung_binding_fingerprint(
- *,
- repeated_structural_key: str,
- source_url: str,
- submit_selector: str,
- submit_trajectory_index: int,
- field_bindings: Sequence[ScoutedFieldParameterBinding],
-) -> str:
- payload = {
- "repeated_structural_key": repeated_structural_key,
- "source_url": source_url,
- "submit_selector": submit_selector,
- "submit_trajectory_index": submit_trajectory_index,
- "field_bindings": [
- {
- "parameter_key": binding["parameter_key"],
- "field_selector": binding["field_selector"],
- }
- for binding in field_bindings
- ],
- }
- return hashlib.sha256(json.dumps(payload, sort_keys=True, separators=(",", ":")).encode()).hexdigest()
-
-
def _binding_source_origin(source_url: str) -> str:
parsed = urlsplit(source_url)
return f"{parsed.scheme}://{parsed.netloc}" if parsed.scheme and parsed.netloc else ""
@@ -447,53 +423,6 @@ def _validated_authoring_parameter_binding_snapshot(
return _ValidatedSnapshotBindings(fill_by_index, select_option_by_index)
-def _validated_submit_rung_binding(
- interaction: Mapping[str, Any], trajectory_index: int
-) -> tuple[str, tuple[tuple[str, str], ...]] | None:
- raw = interaction.get("submit_rung_binding")
- if not isinstance(raw, Mapping) or str(interaction.get("tool_name") or "") != "click":
- return None
- repeated_structural_key = str(raw.get("repeated_structural_key") or "").strip()
- fingerprint = str(raw.get("fingerprint") or "").strip()
- raw_fields = raw.get("field_bindings")
- if not repeated_structural_key or not fingerprint or not isinstance(raw_fields, list) or not raw_fields:
- return None
- fields: list[ScoutedFieldParameterBinding] = []
- parameter_keys: set[str] = set()
- field_selectors: set[str] = set()
- for raw_field in raw_fields:
- if not isinstance(raw_field, Mapping):
- return None
- parameter_key = str(raw_field.get("parameter_key") or "").strip()
- field_selector = str(raw_field.get("field_selector") or "").strip()
- if (
- not grounded_parameter_key_is_safe(parameter_key)
- or not field_selector
- or parameter_key in parameter_keys
- or field_selector in field_selectors
- ):
- return None
- parameter_keys.add(parameter_key)
- field_selectors.add(field_selector)
- fields.append({"parameter_key": parameter_key, "field_selector": field_selector})
- if [field["parameter_key"] for field in fields] != sorted(parameter_keys):
- return None
- submit_selector = str(interaction.get("selector") or "").strip()
- source_url = str(interaction.get("source_url") or "").strip()
- if not submit_selector or not source_url:
- return None
- expected = grounded_submit_rung_binding_fingerprint(
- repeated_structural_key=repeated_structural_key,
- source_url=source_url,
- submit_selector=submit_selector,
- submit_trajectory_index=trajectory_index,
- field_bindings=fields,
- )
- if fingerprint != expected:
- return None
- return fingerprint, tuple((field["parameter_key"], field["field_selector"]) for field in fields)
-
-
@dataclass(frozen=True, slots=True)
class SynthesizedExtractionSuffix:
code: str
@@ -1443,9 +1372,6 @@ def synthesize_code_block(
typed_param_keys: dict[tuple[str, str, str, str], str] = {}
credential_param_keys: dict[str, str] = {}
used_download_vars: set[str] = set()
- grounded_binding_count = sum(1 for interaction in trajectory if "submit_rung_binding" in interaction)
- if grounded_binding_count > 1 or (grounded_binding_count and parameter_binding_snapshot is not None):
- return None
validated_snapshot_bindings = (
_validated_authoring_parameter_binding_snapshot(parameter_binding_snapshot, trajectory)
if parameter_binding_snapshot is not None
@@ -1479,8 +1405,6 @@ def synthesize_code_block(
anchor=reached_download_target.trajectory_anchor,
dropped_trailing_count=dropped_trailing,
)
- if grounded_binding_count != sum(1 for interaction in trajectory if "submit_rung_binding" in interaction):
- return None
diagnostics.retained_trajectory_indices = list(range(len(trajectory)))
input_templated_keys, input_templated_needs_month = _prescan_input_templating(trajectory)
@@ -1838,23 +1762,6 @@ def synthesize_code_block(
line_start = len(lines) + 1
if tool_name == "click":
emit_snapshot_recovery(trajectory_index, action_indent)
- captured_index = interaction.get("trajectory_index")
- submit_trajectory_index = (
- captured_index if isinstance(captured_index, int) and captured_index >= 0 else trajectory_index
- )
- if "submit_rung_binding" in interaction:
- grounded_binding = _validated_submit_rung_binding(interaction, submit_trajectory_index)
- if grounded_binding is None:
- return None
- binding_fingerprint, field_bindings = grounded_binding
- for parameter_key, field_selector in field_bindings:
- if parameter_key not in used_param_keys:
- used_param_keys.add(parameter_key)
- parameters.append({"key": parameter_key})
- lines.append(
- f"{action_indent}await page.locator({_py_str(field_selector)}).fill(str({parameter_key}))"
- )
- diagnostics.grounded_submit_binding_fingerprints.append(binding_fingerprint)
reclassify_terminal_required = (
trajectory_index == terminal_action_index
and _is_anonymous_structural_dismissal_click(interaction)
@@ -2087,7 +1994,7 @@ def synthesize_code_block(
if not lines:
return None
- expected_binding_fingerprint_count = grounded_binding_count + (1 if parameter_binding_snapshot is not None else 0)
+ expected_binding_fingerprint_count = 1 if parameter_binding_snapshot is not None else 0
if len(diagnostics.grounded_submit_binding_fingerprints) != expected_binding_fingerprint_count:
return None
emitted_code = "\n".join(lines)
diff --git a/skyvern/forge/sdk/copilot/runtime.py b/skyvern/forge/sdk/copilot/runtime.py
index 9bdaf1037..39a3d2207 100644
--- a/skyvern/forge/sdk/copilot/runtime.py
+++ b/skyvern/forge/sdk/copilot/runtime.py
@@ -211,17 +211,6 @@ class ScoutedInputCorrespondence(TypedDict):
position: int
-class ScoutedFieldParameterBinding(TypedDict):
- parameter_key: str
- field_selector: str
-
-
-class ScoutedSubmitRungBinding(TypedDict):
- repeated_structural_key: str
- fingerprint: str
- field_bindings: list[ScoutedFieldParameterBinding]
-
-
class ScoutedInteraction(TypedDict):
tool_name: str
selector: NotRequired[str]
@@ -247,9 +236,6 @@ class ScoutedInteraction(TypedDict):
# Set when a live scout-time count()==1 probe found the captured selector matching >1 element on its
# source page; synthesis re-anchors or drops it rather than emitting a selector that strict-mode-fails.
ambiguous: NotRequired[bool]
- # Value-free, current-page binding attached only to the exact captured submit rung on a derived trajectory.
- # The source trajectory remains unchanged; synthesis consumes the fingerprint all-or-nothing.
- submit_rung_binding: NotRequired[ScoutedSubmitRungBinding]
# Credential fills carry references and metadata only — never secret values.
credential_id: NotRequired[str]
credential_field: NotRequired[str]
diff --git a/tests/unit/test_copilot_code_block_synthesis.py b/tests/unit/test_copilot_code_block_synthesis.py
index ed5c1df7a..96c192680 100644
--- a/tests/unit/test_copilot_code_block_synthesis.py
+++ b/tests/unit/test_copilot_code_block_synthesis.py
@@ -7,7 +7,6 @@ from __future__ import annotations
import ast
import asyncio
-import hashlib
import json
import keyword
import sys
@@ -56,7 +55,6 @@ from skyvern.forge.sdk.copilot.code_block_synthesis import (
build_synthesized_artifact_metadata,
code_contains_credential_fill,
credential_scout_gap,
- grounded_submit_rung_binding_fingerprint,
input_correspondences_for_interaction,
is_optional_dismissal_only_trajectory,
obligation_finding_reason_code,
@@ -109,110 +107,6 @@ def _interaction(tool_name: str, **fields: Any) -> dict[str, Any]:
return {"tool_name": tool_name, **fields}
-def _submit_rung_binding(
- interaction: dict[str, Any],
- *,
- trajectory_index: int,
- fields: list[dict[str, str]],
-) -> dict[str, Any]:
- repeated_structural_key = "recorded-p5-key"
- return {
- "repeated_structural_key": repeated_structural_key,
- "field_bindings": fields,
- "fingerprint": grounded_submit_rung_binding_fingerprint(
- repeated_structural_key=repeated_structural_key,
- source_url=str(interaction["source_url"]),
- submit_selector=str(interaction["selector"]),
- submit_trajectory_index=trajectory_index,
- field_bindings=fields,
- ),
- }
-
-
-def test_grounded_submit_rung_binding_changes_candidate_and_preserves_trajectory() -> None:
- trajectory = [
- _interaction("click", selector="#open", source_url="https://example.com/form", trajectory_index=0),
- _interaction("click", selector="#submit", source_url="https://example.com/form", trajectory_index=1),
- ]
- plain = synthesize_code_block(trajectory, strict_selectors=True)
- fields = [
- {"parameter_key": "company_name", "field_selector": "#company"},
- {"parameter_key": "contact_email", "field_selector": "#email"},
- ]
- trajectory[1]["submit_rung_binding"] = _submit_rung_binding(trajectory[1], trajectory_index=1, fields=fields)
- original = [dict(interaction) for interaction in trajectory]
-
- result = synthesize_code_block(trajectory, strict_selectors=True)
-
- assert plain is not None
- assert result is not None
- assert trajectory == original
- assert hashlib.sha256(plain.code.encode()).hexdigest() == (
- "9703bf1b2b7a0a9a2e8145f89055e20c312a3cf2d6b0dc9a34d4d325bba6361f"
- )
- assert result.code != plain.code
- assert result.code.index('page.locator("#company").fill(str(company_name))') < result.code.index(
- 'page.locator("#submit").click()'
- )
- assert result.code.index('page.locator("#email").fill(str(contact_email))') < result.code.index(
- 'page.locator("#submit").click()'
- )
- assert {parameter["key"] for parameter in result.parameters} == {"company_name", "contact_email"}
- assert result.diagnostics.grounded_submit_binding_fingerprints == [
- trajectory[1]["submit_rung_binding"]["fingerprint"]
- ]
- assert [record["trajectory_index"] for record in result.diagnostics.emitted_interactions] == [0, 1]
-
-
-def test_grounded_submit_rung_binding_targets_exact_submit_trajectory_index() -> None:
- trajectory = [
- _interaction("click", selector="#submit", source_url="https://example.com/landing", trajectory_index=0),
- _interaction("click", selector="#open", source_url="https://example.com/form", trajectory_index=1),
- _interaction("click", selector="#submit", source_url="https://example.com/form", trajectory_index=2),
- ]
- fields = [{"parameter_key": "company_name", "field_selector": "#company"}]
- trajectory[2]["submit_rung_binding"] = _submit_rung_binding(trajectory[2], trajectory_index=2, fields=fields)
-
- result = synthesize_code_block(trajectory, strict_selectors=True)
-
- assert result is not None
- first_submit = result.code.index('page.locator("#submit").click()')
- fill = result.code.index('page.locator("#company").fill(str(company_name))')
- second_submit = result.code.rindex('page.locator("#submit").click()')
- assert first_submit < fill < second_submit
-
-
[email protected]("mutation", ["incomplete", "leftover", "fingerprint"])
-def test_grounded_submit_rung_binding_fails_closed_on_invalid_bundle(mutation: str) -> None:
- interaction = _interaction("click", selector="#submit", source_url="https://example.com/form", trajectory_index=0)
- fields = [{"parameter_key": "company_name", "field_selector": "#company"}]
- interaction["submit_rung_binding"] = _submit_rung_binding(interaction, trajectory_index=0, fields=fields)
- trajectory = [interaction]
- if mutation == "incomplete":
- interaction["submit_rung_binding"]["field_bindings"] = []
- elif mutation == "leftover":
- trajectory.append(
- _interaction(
- "click",
- selector="#second-submit",
- source_url="https://example.com/form",
- trajectory_index=1,
- submit_rung_binding=_submit_rung_binding(
- {
- "selector": "#second-submit",
- "source_url": "https://example.com/form",
- },
- trajectory_index=1,
- fields=[{"parameter_key": "contact_email", "field_selector": "#email"}],
- ),
- )
- )
- else:
- interaction["submit_rung_binding"]["fingerprint"] = "stale"
-
- assert synthesize_code_block(trajectory, strict_selectors=True) is None
-
-
def test_authoring_parameter_snapshot_rebinds_captured_fill_without_duplicate() -> None:
trajectory = [
_interaction("type_text", selector="#location", source_url="https://example.com/form", trajectory_index=7),