Skip to content

Automate browser based workflows with AI

Redact signed/presigned artifact URL params from webhook delivery logs (SKY-12624) (#7505)

Aaron Perez21f67b200113
diff --git a/skyvern/forge/sdk/core/security.py b/skyvern/forge/sdk/core/security.py
index 9b5e21c6a..b0cd5bb91 100644
--- a/skyvern/forge/sdk/core/security.py
+++ b/skyvern/forge/sdk/core/security.py
@@ -1,9 +1,11 @@
import hashlib
import hmac
import json
+import re
from dataclasses import dataclass
from datetime import datetime, timedelta
from typing import Any, Union
+from urllib.parse import parse_qsl, urlsplit, urlunsplit
import jwt
@@ -61,6 +63,40 @@ def generate_skyvern_signature(
MAX_WEBHOOK_PAYLOAD_LOG_SIZE = 8000 # ~8KB – keeps Datadog log entries manageable
+# Any absolute http(s) URL token, up to the next whitespace/quote/angle bracket
+# (a JSON string can't contain a raw " or \), so an embedded URL is matched too,
+# not only a whole-value URL. Case-insensitive to catch uppercase schemes.
+_URL_TOKEN_RE = re.compile(r"https?://[^\s\"\\<>]+", re.IGNORECASE)
+# Query-param names whose presence marks a URL as credentialed: Skyvern HMAC
+# signing (sig), and storage presigns (S3 X-Amz-Signature/Credential/Security-Token,
+# GCS X-Goog-Signature, Azure SAS sig). Any match strips the whole query.
+_URL_SIGNATURE_PARAMS = frozenset(
+ {"sig", "x-amz-signature", "x-amz-credential", "x-amz-security-token", "x-goog-signature"}
+)
+
+
+def _strip_credentialed_url_query(match: "re.Match[str]") -> str:
+ url = match.group(0)
+ try:
+ parsed = urlsplit(url)
+ except ValueError:
+ # Fail closed: an unparseable URL keeps only its pre-query/fragment prefix.
+ return re.split(r"[?#]", url, maxsplit=1)[0]
+ query_keys = {key.lower() for key, _ in parse_qsl(parsed.query, keep_blank_values=True)}
+ if not query_keys & _URL_SIGNATURE_PARAMS:
+ return url
+ netloc = parsed.netloc.rsplit("@", 1)[-1] # drop any basic-auth userinfo
+ return urlunsplit((parsed.scheme, netloc, parsed.path, "", ""))
+
+
+def redact_credentialed_urls(text: str) -> str:
+ """Strip signing/presign query params from any credentialed URL in a string.
+
+ Covers Skyvern signed content URLs and S3/Azure/GCS presigns, including URLs embedded in a
+ larger value; non-credentialed URLs and surrounding text are untouched. For log-only copies.
+ """
+ return _URL_TOKEN_RE.sub(_strip_credentialed_url_query, text)
+
@dataclass
class WebhookSignature:
@@ -68,7 +104,7 @@ class WebhookSignature:
signature: str
signed_payload: str
headers: dict[str, str]
- # Truncated version of signed_payload safe for logging
+ # URL-credential-redacted, truncated copy of the payload — safe for logging.
payload_for_log: str
@@ -76,12 +112,16 @@ def generate_skyvern_webhook_signature(payload: dict, api_key: str) -> WebhookSi
payload_str = _normalize_json_dumps(payload)
signature = generate_skyvern_signature(payload=payload_str, api_key=api_key)
timestamp = str(int(datetime.utcnow().timestamp()))
- if len(payload_str) > MAX_WEBHOOK_PAYLOAD_LOG_SIZE:
+ # Redact signed/presigned URL params before truncating so the log copy never
+ # carries replayable credentials. signed_payload stays raw so delivery and the
+ # HMAC signature above are unaffected.
+ log_payload = redact_credentialed_urls(payload_str)
+ if len(log_payload) > MAX_WEBHOOK_PAYLOAD_LOG_SIZE:
payload_for_log = (
- payload_str[:MAX_WEBHOOK_PAYLOAD_LOG_SIZE] + f"... (truncated, original size: {len(payload_str)})"
+ log_payload[:MAX_WEBHOOK_PAYLOAD_LOG_SIZE] + f"... (truncated, original size: {len(payload_str)})"
)
else:
- payload_for_log = payload_str
+ payload_for_log = log_payload
return WebhookSignature(
timestamp=timestamp,
signature=signature,
diff --git a/tests/unit/test_security.py b/tests/unit/test_security.py
index fdc571b9d..dce77964b 100644
--- a/tests/unit/test_security.py
+++ b/tests/unit/test_security.py
@@ -1,7 +1,21 @@
import pytest
from freezegun import freeze_time
-from skyvern.forge.sdk.core.security import create_access_token, generate_skyvern_webhook_signature
+from skyvern.forge.sdk.core.security import (
+ MAX_WEBHOOK_PAYLOAD_LOG_SIZE,
+ create_access_token,
+ generate_skyvern_webhook_signature,
+ redact_credentialed_urls,
+)
+
+_SIGNED = "https://api.skyvern.com/v1/artifacts/art_1/content?expiry=1800000600&kid=k1&sig=SIGNED_SECRET"
+_S3 = (
+ "https://bucket.s3.amazonaws.com/org/art_2.png"
+ "?X-Amz-Algorithm=AWS4-HMAC-SHA256&X-Amz-Credential=AKIA%2F20260716&X-Amz-Expires=900&X-Amz-Signature=S3_SECRET"
+)
+_AZURE = "https://acct.blob.core.windows.net/c/art_3.webm?sv=2021-08-06&se=2026-07-16T00%3A00%3A00Z&sig=AZURE_SECRET"
+_GCS = "https://storage.googleapis.com/bucket/art_4.png?X-Goog-Algorithm=GOOG4-RSA-SHA256&X-Goog-Signature=GCS_SECRET"
+_PLAIN = "https://consumer.example.com/callback?run_id=r_1&status=done"
@pytest.mark.skip(reason="Skipping test_generate_skyvern_signature")
@@ -11,3 +25,89 @@ def test_generate_skyvern_signature() -> None:
payload = {"task_id": "t_12345", "float": 1.0}
signed_data = generate_skyvern_webhook_signature(payload, api_key)
assert signed_data.signature == "1fac4204e1abc7cb0bdf1a42eb17d27f6f1feba065d5726777d5eb77581298c1"
+
+
+class TestRedactCredentialedUrls:
+ def test_strips_skyvern_signed_content_url(self) -> None:
+ assert redact_credentialed_urls(_SIGNED) == "https://api.skyvern.com/v1/artifacts/art_1/content"
+
+ def test_strips_s3_presigned(self) -> None:
+ out = redact_credentialed_urls(_S3)
+ assert "S3_SECRET" not in out
+ assert out == "https://bucket.s3.amazonaws.com/org/art_2.png"
+
+ def test_strips_azure_sas(self) -> None:
+ out = redact_credentialed_urls(_AZURE)
+ assert "AZURE_SECRET" not in out
+ assert out == "https://acct.blob.core.windows.net/c/art_3.webm"
+
+ def test_strips_gcs_presigned(self) -> None:
+ out = redact_credentialed_urls(_GCS)
+ assert "GCS_SECRET" not in out
+ assert out == "https://storage.googleapis.com/bucket/art_4.png"
+
+ def test_preserves_non_credentialed_url(self) -> None:
+ assert redact_credentialed_urls(_PLAIN) == _PLAIN
+
+ def test_strips_signed_url_embedded_in_text(self) -> None:
+ out = redact_credentialed_urls(f"failed to fetch {_SIGNED} after 3 retries")
+ assert "SIGNED_SECRET" not in out
+ assert out == "failed to fetch https://api.skyvern.com/v1/artifacts/art_1/content after 3 retries"
+
+ def test_leaves_plain_text_untouched(self) -> None:
+ assert redact_credentialed_urls("no urls here, just text") == "no urls here, just text"
+
+ def test_strips_uppercase_scheme(self) -> None:
+ url = "HTTPS://api.skyvern.com/v1/artifacts/art_5/content?expiry=1&kid=k&sig=UPPER_SECRET"
+ assert "UPPER_SECRET" not in redact_credentialed_urls(url)
+
+ def test_strips_presigned_url_with_apostrophe_in_path(self) -> None:
+ url = "https://bucket.s3.amazonaws.com/o'brien.pdf?X-Amz-Signature=APOS_SECRET"
+ out = redact_credentialed_urls(url)
+ assert "APOS_SECRET" not in out
+ assert out == "https://bucket.s3.amazonaws.com/o'brien.pdf"
+
+ def test_strips_basic_auth_userinfo_on_credentialed_url(self) -> None:
+ url = "https://user:[email protected]/v1/artifacts/art_6/content?sig=X"
+ out = redact_credentialed_urls(url)
+ assert "PASSWORD" not in out
+ assert out == "https://api.skyvern.com/v1/artifacts/art_6/content"
+
+ def test_fails_closed_on_unparseable_url(self) -> None:
+ # An invalid IPv6 host makes urlsplit raise ValueError — must not leak the sig.
+ url = "https://[bad_ipv6/path?sig=UNPARSEABLE_SECRET"
+ out = redact_credentialed_urls(url)
+ assert "UNPARSEABLE_SECRET" not in out
+
+
+class TestWebhookPayloadForLog:
+ def test_payload_for_log_redacts_urls_but_signed_payload_stays_raw(self) -> None:
+ api_key = "test-api-key"
+ payload = {
+ "task_id": "t_1",
+ "screenshot_url": _SIGNED,
+ "recording_url": _S3,
+ "webhook_callback_url": _PLAIN,
+ "notes": f"artifact at {_SIGNED}",
+ }
+ signed = generate_skyvern_webhook_signature(payload, api_key)
+
+ # log copy is scrubbed of every signature/presign secret, incl. the embedded one
+ for secret in ("SIGNED_SECRET", "S3_SECRET"):
+ assert secret not in signed.payload_for_log
+ # non-credentialed callback URL is preserved in the log
+ assert "run_id=r_1" in signed.payload_for_log
+ # delivered payload + signature are untouched (raw, still carry the secrets)
+ assert "SIGNED_SECRET" in signed.signed_payload
+ assert "S3_SECRET" in signed.signed_payload
+ assert signed.signature == generate_skyvern_webhook_signature(payload, api_key).signature
+
+ def test_oversized_payload_is_redacted_and_truncated(self) -> None:
+ api_key = "test-api-key"
+ filler = "x" * MAX_WEBHOOK_PAYLOAD_LOG_SIZE
+ payload = {"screenshot_url": _SIGNED, "filler": filler}
+ signed = generate_skyvern_webhook_signature(payload, api_key)
+
+ assert "SIGNED_SECRET" not in signed.payload_for_log
+ assert "truncated" in signed.payload_for_log
+ assert signed.payload_for_log.endswith(")")