code review jr: store path traversal...

emit workflow_run_failed

again?
This commit is contained in:
lda
2026-06-03 04:04:24 +07:00 Verified
parent 688dcb69a9
commit 969a5704bb
8 changed files with 200 additions and 13 deletions
@@ -9,6 +9,7 @@ from wf_authoring import NodeSpec
from wf_core import (
NodeUse,
RunState,
RunStatus,
Workflow,
execute_workflow_result_async,
resume_workflow_result_async,
@@ -168,7 +169,9 @@ class WorkflowRuntimeService:
)
self.emit_event(
make_event(
"workflow_run_completed",
"workflow_run_failed"
if run.status == RunStatus.FAILED
else "workflow_run_completed",
workflow_name=plan.name,
payload={"status": run.status.value},
)
+11
View File
@@ -1,11 +1,22 @@
from __future__ import annotations
import re
from dataclasses import dataclass, field
from .models import ConnectionConfig
CONNECTION_ID_PATTERN = r"^[A-Za-z0-9_][A-Za-z0-9_.-]*$"
def parse_connection_id(connection_id: str) -> tuple[str, str]:
# Connection ids are logical source ids, but they also key persisted auth and
# catalog files. Keep this parser conservative so unsafe ids are rejected
# before they reach either registry or store boundaries.
if not re.fullmatch(CONNECTION_ID_PATTERN, connection_id):
raise ValueError(
"connection id must start with alphanumeric or underscore and contain "
"only [A-Za-z0-9_.-]"
)
if "." not in connection_id:
raise ValueError("connection id must look like '<server>.<account>'")
server, account = connection_id.split(".", 1)
+15 -2
View File
@@ -3,6 +3,7 @@ from __future__ import annotations
import json
from pathlib import Path
from ..connections import parse_connection_id
from ..models import (
AuthRecord,
CatalogNodeEntry,
@@ -43,10 +44,22 @@ class FileStore(Store):
return self.root / "catalog"
def _auth_path(self, connection_id: str) -> Path:
return self.auth_dir / f"{connection_id}.json"
return self._connection_path(self.auth_dir, connection_id)
def _catalog_path(self, connection_id: str) -> Path:
return self.catalog_dir / f"{connection_id}.json"
return self._connection_path(self.catalog_dir, connection_id)
@staticmethod
def _connection_path(directory: Path, connection_id: str) -> Path:
"""Map one validated connection id to one file inside a store directory."""
parse_connection_id(connection_id)
root = directory.resolve()
path = (directory / f"{connection_id}.json").resolve()
if path.parent != root:
raise ValueError(
f"connection id escapes store directory: {connection_id!r}"
)
return path
def save_auth(self, record: AuthRecord) -> None:
self._auth_path(record.connection_id).write_text(