Skip to content

Automate browser based workflows with AI

SKY-18462 Add signed event trigger receiver (#8936)

Aaron Perez0dfbd6cc8184
diff --git a/skyvern/forge/log_redaction.py b/skyvern/forge/log_redaction.py
index e102c0381..ae73c8cee 100644
--- a/skyvern/forge/log_redaction.py
+++ b/skyvern/forge/log_redaction.py
@@ -42,6 +42,7 @@ SENSITIVE_HEADERS = {
"x-marketplace-api-key",
"x-posthog-attribution",
"x-copilot-credential-recovery-token",
+ "x-skyvern-signature",
"stripe-signature",
}
diff --git a/skyvern/forge/request_logging.py b/skyvern/forge/request_logging.py
index fc5a53431..43630f057 100644
--- a/skyvern/forge/request_logging.py
+++ b/skyvern/forge/request_logging.py
@@ -63,6 +63,7 @@ _SENSITIVE_ENDPOINTS = {
# Payment-provider events carry customer billing details (name, email, address, card metadata).
"POST /api/v1/stripe_webhook",
}
+_SIGNED_TRIGGER_RECEIVER_ENDPOINT = re.compile(r"^POST /(?:api/)?v1/triggers/[^/]+/events$")
_SENSITIVE_ENDPOINT_PATTERNS = (
re.compile(r"^(?:POST|PUT) /(?:api/)?v1/credentials(?:/.*)?$"),
# Twilio credentials and inbound SMS codes must stay opaque even with malformed bodies.
@@ -73,6 +74,8 @@ _SENSITIVE_ENDPOINT_PATTERNS = (
re.compile(r"^POST /oauth/(?:token|consent|callback)$"),
# Marketplace service routes return freshly minted client secrets.
re.compile(r"^POST /(?:api/)?v1/marketplace(?:/.*)?$"),
+ # Signed trigger events contain arbitrary caller-provided payloads.
+ _SIGNED_TRIGGER_RECEIVER_ENDPOINT,
# Skyplane authority calls carry runtime capabilities, tool arguments, agent feedback text and delivered files.
re.compile(r"^[^ ]+ /api/v1/skyplane(?:/.*)?$"),
)
@@ -392,6 +395,7 @@ async def log_raw_request_middleware(request: Request, call_next: Callable[[Requ
return await call_next(request)
start_time = time.monotonic()
+ body_buffered = True
try:
if _is_fixture_endpoint(request):
bounded = bytearray()
@@ -401,6 +405,10 @@ async def log_raw_request_middleware(request: Request, call_next: Callable[[Requ
return Response(status_code=413)
bounded.extend(chunk)
body_bytes = bytes(bounded)
+ elif _SIGNED_TRIGGER_RECEIVER_ENDPOINT.fullmatch(f"{request.method.upper()} {request.url.path.rstrip('/')}"):
+ # The receiver's route-level size limit must see the unconsumed request stream.
+ body_bytes = b""
+ body_buffered = False
else:
body_bytes = await request.body()
except TimeoutError:
@@ -413,10 +421,11 @@ async def log_raw_request_middleware(request: Request, call_next: Callable[[Requ
LOG.info("api.client_disconnect", method=request.method, path=request.url.path)
return Response(status_code=499)
# ensure downstream handlers can access body again
- try:
- request._body = body_bytes # type: ignore[attr-defined]
- except Exception:
- pass
+ if body_buffered:
+ try:
+ request._body = body_bytes # type: ignore[attr-defined]
+ except Exception:
+ pass
url_path = request.url.path
http_method = request.method
diff --git a/skyvern/forge/taskv3/tools.py b/skyvern/forge/taskv3/tools.py
index c72c14049..dcc72fad8 100644
--- a/skyvern/forge/taskv3/tools.py
+++ b/skyvern/forge/taskv3/tools.py
@@ -4993,6 +4993,21 @@ _OWN_LABEL_HIT_JS = (
"""
)
+# The probe's target lookup and readonly rule, shared with the type tool's readonly re-read so the two cannot
+# disagree. Needs `_q`, `arg` and `_NATIVE_LABEL_JS` in scope; defines `el`, `ctl` and `readOnly`.
+_TARGET_READONLY_JS = r"""
+ // A host-anchored selector's two halves straddle a shadow boundary, so no single root can match it
+ // and a per-root lookup finds nothing -- which would read as "no field here" and skip the check on
+ // exactly the controls that addressing made reachable. The executor resolves it; take its element.
+ const el = _q.find(arg.sel) || (arg.el && arg.el.isConnected ? arg.el : null);
+ if (!el) return { exists: false };
+ // A LABEL's own disabled/readOnly/type attributes mean nothing; its genuinely associated control's do.
+ let ctl = el;
+ try { if (_isLabel(el)) ctl = nativeControlOf(el) || el; } catch (e) { ctl = el; }
+ let readOnly = false;
+ try { readOnly = !!ctl.readOnly; } catch (e) { /* best-effort */ }
+"""
+
_TYPE_TARGET_PROBE_JS = (
r"""(arg) => {
const _q = """
@@ -5006,20 +5021,11 @@ _TYPE_TARGET_PROBE_JS = (
try { _q.all('[data-tv3-cover]').forEach((n) => n.removeAttribute('data-tv3-cover')); } catch (e) { /* best-effort */ }
try { _q.all('[data-tv3-catcher]').forEach((n) => n.removeAttribute('data-tv3-catcher')); } catch (e) { /* best-effort */ }
try { _q.all('[data-tv3-close]').forEach((n) => n.removeAttribute('data-tv3-close')); } catch (e) { /* best-effort */ }
-
- // A host-anchored selector's two halves straddle a shadow boundary, so no single root can match it
- // and a per-root lookup finds nothing -- which would read as "no field here" and skip the check on
- // exactly the controls that addressing made reachable. The executor resolves it; take its element.
- const el = _q.find(arg.sel) || (arg.el && arg.el.isConnected ? arg.el : null);
- if (!el) return { exists: false };
- const RETEST_SCROLLABLE_CLIP = false;
- // A LABEL's own disabled/readOnly/type attributes mean nothing; its genuinely associated control's do.
- let ctl = el;
- try { if (_isLabel(el)) ctl = nativeControlOf(el) || el; } catch (e) { ctl = el; }
+"""
+ + _TARGET_READONLY_JS
+ + r""" const RETEST_SCROLLABLE_CLIP = false;
let disabled = false;
try { disabled = !!(ctl.disabled || (ctl.matches && ctl.matches(':disabled'))); } catch (e) { /* best-effort */ }
- let readOnly = false;
- try { readOnly = !!ctl.readOnly; } catch (e) { /* best-effort */ }
const out = { exists: true, disabled, readOnly };
try {
if (_isToggle(ctl)) {
@@ -5897,6 +5903,20 @@ _TYPING_REACH_PROBE_JS = _TYPE_TARGET_PROBE_JS.replace(
"const RETEST_SCROLLABLE_CLIP = false;", "const RETEST_SCROLLABLE_CLIP = true;"
)
+# The probe's readonly reading alone. Unlike the probe it scrolls nothing and re-mints no cover markers, so it can
+# be repeated without invalidating the markers the probe's verdict names.
+_TYPING_READONLY_JS = (
+ r"""(arg) => {
+ const _q = """
+ + _ROOT_QUERY_JS
+ + r""";
+"""
+ + _NATIVE_LABEL_JS
+ + _TARGET_READONLY_JS
+ + r""" return { exists: true, readOnly };
+}"""
+)
+
_ACTIVE_IS_JS = (
r"""(arg) => {
const _q = """
@@ -15545,6 +15565,17 @@ def build_browser_tools(
except Exception:
LOG.debug("taskv3 could not enumerate frames under the covering layer", exc_info=True)
+ async def _readonly_now(page: Any, selector: str) -> bool:
+ # Resolved afresh on every read: a control the page replaces leaves a cached handle disconnected.
+ arg = await _probe_arg(page, selector)
+ try:
+ read = await _probe_evaluate(page, _TYPING_READONLY_JS, selector, arg)
+ finally:
+ if arg["el"] is not None:
+ with contextlib.suppress(Exception):
+ await arg["el"].dispose()
+ return isinstance(read, dict) and bool(read.get("exists")) and bool(read.get("readOnly"))
+
async def _reachable_for_typing(page: Any, selector: str) -> tuple[bool, bool, dict[str, Any] | None]:
"""(reachable, occluded, occluder). Raises when the field cannot accept typed text at all. Shared
by both typing paths: fill() does no hit-testing, so without this a covered password or email
@@ -15569,21 +15600,26 @@ def build_browser_tools(
# the driver is asked for the rest of its rule -- see the click gate. Held for that gate's
# grace rather than refused outright, because fill()'s own wait used to cover a field the
# page releases a moment later.
- enable_deadline = time.monotonic() + _DISABLED_CLICK_GRACE_SECONDS
- while not await _engine_enabled(page, selector):
- if time.monotonic() >= enable_deadline:
- raise _FieldNotEditable(selector, False)
+ deadline = time.monotonic() + _DISABLED_CLICK_GRACE_SECONDS
+ released = False
+ enabled = await _engine_enabled(page, selector)
+ read_only = False # not read for a field answered enabled here: fill() waits out its lock itself
+ while not enabled or read_only:
+ if time.monotonic() >= deadline:
+ raise _FieldNotEditable(selector, read_only)
await asyncio.sleep(0.1)
+ enabled = await _engine_enabled(page, selector)
# Re-read rather than only polling the driver: a page that answers the grace by making
# the field readonly has made it un-typable for a different reason, and the accurate
# message is the one the caller renders.
- held: Any = None
+ read_only = False
with contextlib.suppress(Exception):
- held = await _probe_evaluate(
- page, _TYPING_REACH_PROBE_JS, selector, await _probe_arg(page, selector)
- )
- if isinstance(held, dict) and held.get("exists") and held.get("readOnly"):
- raise _FieldNotEditable(selector, True)
+ read_only = await _readonly_now(page, selector)
+ if enabled and not released:
+ # From here fill() would have waited, so a lock gets fill()'s budget rather than the
+ # disabled grace; a lock still held at its end is refused instead of timing fill() out.
+ released = True
+ deadline = time.monotonic() + _ACTION_TIMEOUT_MS / 1000
occluded = bool(isinstance(probe, dict) and probe.get("occluded"))
occluder = probe.get("occluder") if isinstance(probe, dict) else None
if occluded and not probe.get("skinned"):
diff --git a/tests/unit/test_taskv3_tools.py b/tests/unit/test_taskv3_tools.py
index ae80e0500..779537b79 100644
--- a/tests/unit/test_taskv3_tools.py
+++ b/tests/unit/test_taskv3_tools.py
@@ -16245,6 +16245,7 @@ async def test_type_waits_out_an_aria_disabled_field_the_page_releases() -> None
assert await page.eval_on_selector("#soon", "el => el.value") == "Iowa City"
[email protected]("short_action_timeout")
@_skip_no_browser
@pytest.mark.asyncio
async def test_type_reports_readonly_when_the_page_locks_the_field_during_the_grace() -> None: