Skip to content

Commit 7624efe

Browse files
committed
Address review: path traversal guards and docstring fix
- Reject absolute paths and '..' segments in context_file in both bash and PowerShell scripts to prevent writes outside the project root - Fix docstring in _update_init_options_for_integration to accurately describe marker preservation behavior
1 parent 38e03e2 commit 7624efe

3 files changed

Lines changed: 15 additions & 2 deletions

File tree

extensions/agent-context/scripts/bash/update-agent-context.sh

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,12 @@ if [[ -z "$CONTEXT_FILE" ]]; then
9999
exit 0
100100
fi
101101

102+
# Reject absolute paths and path traversal in context_file
103+
if [[ "$CONTEXT_FILE" == /* ]] || [[ "$CONTEXT_FILE" == *..* ]]; then
104+
echo "agent-context: context_file must be a project-relative path without '..' segments; got '$CONTEXT_FILE'." >&2
105+
exit 1
106+
fi
107+
102108
[[ -z "$MARKER_START" ]] && MARKER_START="$DEFAULT_START"
103109
[[ -z "$MARKER_END" ]] && MARKER_END="$DEFAULT_END"
104110

extensions/agent-context/scripts/powershell/update-agent-context.ps1

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -140,6 +140,12 @@ if (-not $ContextFile) {
140140
exit 0
141141
}
142142

143+
# Reject absolute paths and path traversal in context_file
144+
if ([System.IO.Path]::IsPathRooted($ContextFile) -or $ContextFile.Contains('..')) {
145+
Write-Warning "agent-context: context_file must be a project-relative path without '..' segments; got '$ContextFile'."
146+
exit 1
147+
}
148+
143149
$MarkerStart = $DefaultStart
144150
$MarkerEnd = $DefaultEnd
145151
$cm = Get-ConfigValue -Object $Options -Key 'context_markers'

src/specify_cli/__init__.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1190,8 +1190,9 @@ def _update_init_options_for_integration(
11901190
``context_file`` and ``context_markers`` are stored in the agent-context
11911191
extension config (``.specify/extensions/agent-context/agent-context-config.yml``),
11921192
not in ``init-options.json``. Existing user-customised markers are
1193-
preserved; the start/end values are only seeded from defaults when they
1194-
are absent or invalid.
1193+
always preserved when the config already exists; invalid marker values
1194+
are silently ignored at runtime by ``_resolve_context_markers()`` which
1195+
falls back to the class-level defaults.
11951196
"""
11961197
from .integrations.base import SkillsIntegration
11971198
opts = load_init_options(project_root)

0 commit comments

Comments
 (0)