Skip to content

OpenAI's Codex Security CLI and TypeScript SDK for finding, validating, and fixing security vulnerabilities. npm: https://www.npmjs.com/package/@openai/codex-security

refactor(workbench): share safe source path validation (#396)

mldangelo-oai662b0ebbffc9
diff --git a/sdk/typescript/_bundled_plugin/scripts/workbench_db.py b/sdk/typescript/_bundled_plugin/scripts/workbench_db.py
index c672442d2..732fb5b88 100644
--- a/sdk/typescript/_bundled_plugin/scripts/workbench_db.py
+++ b/sdk/typescript/_bundled_plugin/scripts/workbench_db.py
@@ -97,7 +97,7 @@ from workbench_schema import (
from workbench_schema import (
sql_statements as sql_statements,
)
-from workbench_source_excerpt import finding_source_excerpt
+from workbench_source_excerpt import finding_source_excerpt, safe_source_path
from workbench_target import (
clean_worktree_content_digest,
copy_directory_excluding,
@@ -3462,20 +3462,6 @@ def patch_artifact_preview(
}
-def safe_source_path(target: Path, relative_path: str) -> Path | None:
- if "\\" in relative_path:
- return None
- parsed = PurePosixPath(relative_path)
- if parsed.is_absolute() or ".." in parsed.parts:
- return None
- try:
- path = (target / parsed.as_posix()).resolve()
- path.relative_to(target)
- except (OSError, RuntimeError, ValueError):
- return None
- return path
-
-
def available_artifact_path(scan_dir: Path, candidate: Path) -> Path | None:
try:
resolved_scan_dir = require_canonical_scan_directory(scan_dir)