Skip to content

Commit 5d9cc7c

Browse files
committed
Address review: strict enabled check, docstring, segment-level path traversal
- Use 'is not False' for enabled check so only literal False disables - Update upsert_context_section docstring to mention disabled-extension return - Fix path traversal guards to check actual path segments, not substrings (allows filenames like 'notes..md' while rejecting '../' traversal)
1 parent 7624efe commit 5d9cc7c

3 files changed

Lines changed: 22 additions & 8 deletions

File tree

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

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -99,11 +99,19 @@ 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
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
106106
fi
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"

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

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff 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

src/specify_cli/integrations/base.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff 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

0 commit comments

Comments
 (0)