id hardening fix, from coderabbit report

This commit is contained in:
lda
2026-05-26 12:30:50 +07:00 Verified
parent ba8fd2b614
commit 38fadc9f10
2 changed files with 14 additions and 4 deletions
+4 -3
View File
@@ -10,14 +10,15 @@ from wf_core import PersistedRunState
from ..models import DependencyDiagnostic, WorkflowArtifact, WorkflowDeployment
RUN_ID_PATTERN = r"^[A-Za-z0-9_.-]+$"
RUN_ID_PATTERN = r"^[A-Za-z0-9_][A-Za-z0-9_.-]*$"
def ensure_run_id(run_id: str) -> str:
"""Reject ids that cannot safely identify one local run directory."""
if not re.fullmatch(RUN_ID_PATTERN, run_id):
raise ValueError(
"run_id must match [A-Za-z0-9_.-]+; path separators are not allowed"
"run_id must start with alphanumeric or underscore and contain only "
"[A-Za-z0-9_.-]"
)
return run_id
@@ -65,7 +66,7 @@ class WorkflowRunRecord(BaseModel):
status: StoredRunStatus
resume_readiness: ResumeReadiness
environment: PinnedRunEnvironment
latest_checkpoint_id: str
latest_checkpoint_id: str = Field(pattern=RUN_ID_PATTERN)
diagnostics: list[DependencyDiagnostic] = Field(default_factory=list)
created_at: datetime
updated_at: datetime