File tree Expand file tree Collapse file tree
extensions/agent-context/scripts
src/specify_cli/integrations Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -99,11 +99,19 @@ if [[ -z "$CONTEXT_FILE" ]]; then
9999 exit 0
100100fi
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
102+ # Reject absolute paths and '..' path segments in context_file
103+ if [[ " $CONTEXT_FILE " == /* ]]; then
104+ echo " agent-context: context_file must be a project-relative path; got '$CONTEXT_FILE '." >&2
105105 exit 1
106106fi
107+ IFS=' /' read -ra _cf_parts <<< " $CONTEXT_FILE"
108+ for _seg in " ${_cf_parts[@]} " ; do
109+ if [[ " $_seg " == " .." ]]; then
110+ echo " agent-context: context_file must not contain '..' path segments; got '$CONTEXT_FILE '." >&2
111+ exit 1
112+ fi
113+ done
114+ unset _cf_parts _seg
107115
108116[[ -z " $MARKER_START " ]] && MARKER_START=" $DEFAULT_START "
109117[[ -z " $MARKER_END " ]] && MARKER_END=" $DEFAULT_END "
Original file line number Diff line number Diff line change @@ -140,9 +140,14 @@ 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 '."
143+ # Reject absolute paths and '..' path segments in context_file
144+ if ([System.IO.Path ]::IsPathRooted($ContextFile )) {
145+ Write-Warning " agent-context: context_file must be a project-relative path; got '$ContextFile '."
146+ exit 1
147+ }
148+ $cfSegments = $ContextFile -split ' [/\\]'
149+ if ($cfSegments -contains ' ..' ) {
150+ Write-Warning " agent-context: context_file must not contain '..' path segments; got '$ContextFile '."
146151 exit 1
147152}
148153
Original file line number Diff line number Diff line change @@ -584,7 +584,7 @@ def _agent_context_extension_enabled(project_root: Path) -> bool:
584584 entry = extensions .get ("agent-context" )
585585 if not isinstance (entry , dict ):
586586 return True
587- return bool ( entry .get ("enabled" , True ))
587+ return entry .get ("enabled" , True ) is not False
588588
589589 def _resolve_context_markers (self , project_root : Path ) -> tuple [str , str ]:
590590 """Return the (start, end) context markers to use for *project_root*.
@@ -651,7 +651,8 @@ def upsert_context_section(
651651 when present, falling back to the class-level constants.
652652
653653 Returns the path to the context file, or ``None`` when
654- ``context_file`` is not set.
654+ ``context_file`` is not set or the ``agent-context`` extension is
655+ disabled.
655656 """
656657 if not self .context_file :
657658 return None
You can’t perform that action at this time.
0 commit comments