Skip to content

Automate browser based workflows with AI

Fix CodeQL polynomial ReDoS in MCP feedback report redaction (#SKY-18789) (#9000)

Aaron Perezc1489cb8bd8e
diff --git a/skyvern/config.py b/skyvern/config.py
index 3766b09d8..75a9016d3 100644
--- a/skyvern/config.py
+++ b/skyvern/config.py
@@ -311,7 +311,7 @@ class Settings(BaseSettings):
# The caller-supplied header is not an authorization: on a shared deployment only API
# credentials belonging to these explicitly configured eval organizations may seed an entry point.
WORKFLOW_COPILOT_ODYSSEYS_EVAL_ORGANIZATION_IDS: list[str] = []
- WORKFLOW_COPILOT_EVAL_LLM_OVERRIDES_ENABLED: bool = False
+ # Request-scoped model overrides require an authenticated organization in this allowlist.
WORKFLOW_COPILOT_EVAL_LLM_OVERRIDES_ORGANIZATION_IDS: list[str] = []
WORKFLOW_COPILOT_EVAL_COST_ENABLED: bool = False
WORKFLOW_COPILOT_EVAL_COST_ORGANIZATION_IDS: list[str] = []
diff --git a/skyvern/forge/sdk/copilot/eval_llm_overrides.py b/skyvern/forge/sdk/copilot/eval_llm_overrides.py
index b18f063b8..45eca8003 100644
--- a/skyvern/forge/sdk/copilot/eval_llm_overrides.py
+++ b/skyvern/forge/sdk/copilot/eval_llm_overrides.py
@@ -65,11 +65,11 @@ def admit_eval_llm_overrides(raw: str | None, organization_id: str) -> EvalLLMOv
raise HTTPException(status_code=400, detail="Invalid Copilot eval model overrides") from exc
if not parsed:
return None
- if (
- not settings.WORKFLOW_COPILOT_EVAL_LLM_OVERRIDES_ENABLED
- or organization_id not in settings.WORKFLOW_COPILOT_EVAL_LLM_OVERRIDES_ORGANIZATION_IDS
- ):
- raise HTTPException(status_code=403, detail="Copilot eval model overrides are disabled")
+ if organization_id not in settings.WORKFLOW_COPILOT_EVAL_LLM_OVERRIDES_ORGANIZATION_IDS:
+ raise HTTPException(
+ status_code=403,
+ detail="Copilot eval model overrides require an allowlisted Evaluation organization",
+ )
keys: dict[str, str] = dict(sorted(parsed.items()))
handlers: dict[str, LLMAPIHandler] = {}
try:
diff --git a/tests/unit/test_feedback_route.py b/tests/unit/test_feedback_route.py
index c527e8e9f..aecf62c1e 100644
--- a/tests/unit/test_feedback_route.py
+++ b/tests/unit/test_feedback_route.py
@@ -1,4 +1,5 @@
from datetime import UTC, datetime
+from time import perf_counter
from types import SimpleNamespace
from unittest.mock import AsyncMock
@@ -18,6 +19,34 @@ ORG = Organization(
)
+def test_report_redaction_still_masks_url_credentials_and_aws_secret_assignments() -> None:
+ assert feedback_routes._redact_report_text("Open https://reporter:[email protected]/path", ()) == (
+ "Open https://[REDACTED_SECRET]@example.invalid/path"
+ )
+ assert feedback_routes._redact_report_text("prefixhttps://user:pw@host 3+https://user:pw@host", ()) == (
+ "prefixhttps://[REDACTED_SECRET]@host 3+https://[REDACTED_SECRET]@host"
+ )
+ assert feedback_routes._redact_report_text("https://not-a-userinfo and https://user:pw@host", ()) == (
+ "https://not-a-userinfo and https://[REDACTED_SECRET]@host"
+ )
+ assert feedback_routes._redact_report_text("AWS_SECRET_ACCESS_KEY=synthetic-secret", ()) == (
+ "AWS_SECRET_ACCESS_KEY=[REDACTED_SECRET]"
+ )
+ assert feedback_routes._redact_report_text("my_secret_access_key=synthetic-secret", ()) == (
+ "my_secret_access_key=[REDACTED_SECRET]"
+ )
+ assert feedback_routes._redact_report_text('"x.secret_access_key": "synthetic-secret"', ()) == (
+ '"x.secret_access_key": [REDACTED_SECRET]'
+ )
+
+
[email protected]("text", ["A" * 80_000, "A" * 80_000 + "://", "a_" * 40_000])
+def test_report_redaction_completes_quickly_on_long_inputs(text: str) -> None:
+ started = perf_counter()
+ assert feedback_routes._redact_report_text(text, ()) == text
+ assert perf_counter() - started < 1.0
+
+
def _stored(rating: str = "up") -> RunFeedback:
now = datetime(2026, 1, 1, tzinfo=UTC)
return RunFeedback(
diff --git a/tests/unit/test_workflow_copilot_llm_config.py b/tests/unit/test_workflow_copilot_llm_config.py
index 40a6b8fbb..9dd1a1ba5 100644
--- a/tests/unit/test_workflow_copilot_llm_config.py
+++ b/tests/unit/test_workflow_copilot_llm_config.py
@@ -270,7 +270,6 @@ async def test_composition_visual_handler_uses_fast_copilot_lane(
@pytest.fixture
def eval_llm_registry(monkeypatch: pytest.MonkeyPatch) -> None:
- monkeypatch.setattr(settings, "WORKFLOW_COPILOT_EVAL_LLM_OVERRIDES_ENABLED", True)
monkeypatch.setattr(settings, "WORKFLOW_COPILOT_EVAL_LLM_OVERRIDES_ORGANIZATION_IDS", ["org_eval"])
monkeypatch.setattr(
LLMConfigRegistry,
@@ -343,19 +342,20 @@ def test_eval_overrides_reject_invalid_or_unavailable_configuration(raw: str, ev
assert error.value.status_code == 400
-def test_eval_overrides_require_server_and_org_authorization(
- eval_llm_registry: None, monkeypatch: pytest.MonkeyPatch
+ ("allowed_organizations", "organization_id"),
+ [([], "org_eval"), (["org_eval"], "org_other")],
+)
+def test_eval_overrides_require_allowlisted_evaluation_org(
+ allowed_organizations: list[str], organization_id: str, eval_llm_registry: None, monkeypatch: pytest.MonkeyPatch
) -> None:
+ monkeypatch.setattr(settings, "WORKFLOW_COPILOT_EVAL_LLM_OVERRIDES_ORGANIZATION_IDS", allowed_organizations)
raw = '{"workflow-copilot":"EVAL_ACTOR"}'
with pytest.raises(HTTPException) as error:
- admit_eval_llm_overrides(raw, "org_other")
- assert error.value.status_code == 403
- monkeypatch.setattr(settings, "WORKFLOW_COPILOT_EVAL_LLM_OVERRIDES_ENABLED", False)
- with pytest.raises(HTTPException) as error:
- admit_eval_llm_overrides(raw, "org_eval")
+ admit_eval_llm_overrides(raw, organization_id)
assert error.value.status_code == 403
- assert admit_eval_llm_overrides(None, "org_other") is None
- assert admit_eval_llm_overrides("{}", "org_other") is None
+ assert admit_eval_llm_overrides(None, organization_id) is None
+ assert admit_eval_llm_overrides("{}", organization_id) is None
@pytest.mark.asyncio