T09 · Insecure Skill Coding Practices
- Location
scripts/get.sh:12- Finding
Path Traversal Through an Unvalidated Contact Identifier
- Content
View full analysis
Vulnerability Details
File Location:
scripts/get.sh:12-13
Related Unsafe Guidance:SKILL.md:101
Vulnerability Type: Path traversal and unauthorized file disclosure
Risk Level: MediumVulnerable Code
bash if [ -f "$CONTACTS_DIR/$1.yaml" ]; then cat "$CONTACTS_DIR/$1.yaml"Technical Analysis
The script directly incorporates the first command-line argument into a filesystem path. Although the variable is quoted, quoting only prevents shell word splitting and command injection; it does not prevent directory traversal.
An identifier containing
../components can cause the resolved path to escapememory/contacts/contacts.d/. The.yamlsuffix limits targets to paths ending in that extension, while the-fcheck limits disclosure to existing regular files, but neither control ensures that the target remains inside the intended contacts directory.The contact-creation workflow documented at
SKILL.md:101also instructs the Agent to use the contact identifier as a filename without specifying validation. If implemented literally, the same identifier weakness could permit creation or replacement of YAML files outside the contacts directory.Attack Path
-
An attacker supplies a crafted contact identifier containing parent-directory components, such as
../../../../target. -
The Agent or user invokes:
bash scripts/get.sh '../../../../target' -
The script constructs a path equivalent to:
text memory/contacts/contacts.d/../../../../target.yaml -
The operating system resolves the parent-directory components, causing the path to escape the intended contacts directory.
-
If the resulting YAML file exists and is readable by the Agent process, the script outputs its complete contents.
-
If the same malicious identifier is accepted during the documented contact-creation process, an Agent implementation may create or overwrite a ...[truncated 632 chars]
-
- Remediation
View remediation
Remediation Suggestions
-
Enforce a strict allowlist for contact identifiers before constructing any path. For example:
bash contact_id="${1:-}" case "$contact_id" in ""|*[!A-Za-z0-9_-]*) echo "Invalid contact ID" >&2 exit 1 ;; esac -
Canonicalize the contacts directory and candidate file, then verify that the candidate remains beneath the intended directory before reading it.
-
Apply identical identifier validation to every contact-creation or update workflow. Do not permit path separators,
.., control characters, or empty identifiers. -
For contact creation, use exclusive file creation to avoid unintended overwrites and set restrictive permissions, such as owner-only read and write access.
-
Add automated tests covering identifiers with absolute paths, repeated
../components, backslashes, whitespace, control characters, and valid boundary-length identifiers. -
Update
SKILL.mdandmemory/contacts/schema.mdto define the permitted contact identifier format explicitly, such as^[A-Za-z0-9_-]+$.
-
