Skip to content

Commit 13a46dd

Browse files
committed
Applying review recommendations
1 parent 1a0f8b1 commit 13a46dd

1 file changed

Lines changed: 13 additions & 0 deletions

File tree

src/specify_cli/presets.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -139,6 +139,15 @@ def _validate(self):
139139
f"must be one of {sorted(VALID_PRESET_TEMPLATE_TYPES)}"
140140
)
141141

142+
# Validate file path safety: must be relative, no parent traversal
143+
file_path = tmpl["file"]
144+
normalized = os.path.normpath(file_path)
145+
if os.path.isabs(normalized) or normalized.startswith(".."):
146+
raise PresetValidationError(
147+
f"Invalid template file path '{file_path}': "
148+
"must be a relative path within the preset directory"
149+
)
150+
142151
# Validate template name format
143152
if tmpl["type"] == "command":
144153
# Commands use dot notation (e.g. speckit.specify)
@@ -921,6 +930,10 @@ def _load_catalog_config(self, config_path: Path) -> Optional[List[PresetCatalog
921930
raise PresetValidationError(
922931
f"Failed to read catalog config {config_path}: {e}"
923932
)
933+
if not isinstance(data, dict):
934+
raise PresetValidationError(
935+
f"Invalid catalog config {config_path}: expected a mapping at root, got {type(data).__name__}"
936+
)
924937
catalogs_data = data.get("catalogs", [])
925938
if not catalogs_data:
926939
return None

0 commit comments

Comments
 (0)