Back to skill

Security audit

rag-knowledge-assistant

Security checks for vulnerabilities and agentic risk

Overview

The skill is mostly a local RAG knowledge-base helper, but it includes unsafe rebuild deletion behavior and insecure credential-handling guidance that users should review before installing.

Install only in an isolated environment, keep `--knowledge-dir` limited to documents you are allowed to index, and keep `--output-dir` set to a dedicated vector-store directory. Do not use `--rebuild` with any valuable or broad path. Avoid the PAT-in-URL push instructions; use Git Credential Manager, GitHub CLI, or SSH instead. Treat `./vectorstore` and any Ollama embedding service as containing sensitive derivatives of your documents.

Vulnerability Patterns
  • Insecure DependenciesIntroduces malicious components through unsafe dependency sources
  • Insecure Skill Coding PracticesFinds exploitable flaws such as hardcoded secrets or command injection
  • Skill Instruction HijackingAlters the agent's session goals or safety constraints when the skill loads
  • Agent Memory PoisoningWrites attacker-controlled rules into memory that affect later sessions
  • Remote Payload Retrieval and ExecutionFetches external code whose behavior can change after review
Findings (3)

T09 · Insecure Skill Coding Practices

Error
Location
scripts/index_knowledge.py:218
Finding

Arbitrary Recursive Directory Deletion Through Unvalidated Output Path

Content
View full analysis

Vulnerability Details

File Location: scripts/index_knowledge.py:218-225 and scripts/index_knowledge_ollama.py:273-280
Vulnerability Type: Unrestricted recursive directory deletion
Risk Level: High

Vulnerable Code

scripts/index_knowledge.py:218-225:

python
# Check whether a forced rebuild was requested
output_path = Path(args.output_dir)
if output_path.exists() and args.rebuild:
    print(f"\n⚠️  Existing vector store detected; deleting it...")
    import shutil
    shutil.rmtree(output_path)
    print("✓ Old data removed")

The Ollama implementation contains the equivalent behavior at scripts/index_knowledge_ollama.py:273-280:

python
# Check whether a forced rebuild was requested
output_path = Path(args.output_dir)
if output_path.exists() and args.rebuild:
    print(f"\n⚠️  Existing vector store detected; deleting it...")
    import shutil
    shutil.rmtree(output_path)
    print("✓ Old data removed")

Technical Analysis

The user-controlled --output-dir argument is converted directly into a Path. When --rebuild is supplied, the application recursively deletes that path using shutil.rmtree().

The code does not:

  • Resolve and validate the canonical destination.
  • Restrict deletion to a designated workspace or vector-store directory.
  • Verify that the destination contains a valid application-generated vector store.
  • Reject dangerous targets such as a home directory, project directory, mounted data directory, or a path reached through a symbolic link.
  • Require explicit confirmation before destructive deletion.

As a result, any existing directory writable by the current process can be selected for recursive deletion. The same flaw exists in both indexing variants.

Attack Path

  1. An attacker persuades a user or agent to invoke an indexing script with a malicious --output-dir value.
  2. The attacker also causes the --rebuild op ...[truncated 1031 chars]
Remediation
View remediation

Remediation Suggestions

  1. Resolve the destination with Path.resolve() before performing any operation.
  2. Restrict output directories to an explicitly approved workspace root and verify containment with Path.is_relative_to() or an equivalent robust check.
  3. Reject dangerous targets, including the file-system root, user home, project root, workspace root, and shallow parent directories.
  4. Create a unique marker file when initializing a vector store and permit rebuilding only when that marker exists and has the expected contents.
  5. Detect and reject symbolic-link destinations and unexpected path components.
  6. Require interactive confirmation showing the canonical path unless a separately protected noninteractive option is used.
  7. Prefer deleting only known Chroma artifacts rather than recursively deleting the entire selected directory.
  8. Apply the same validation helper to both indexing implementations and add tests covering traversal, symbolic links, root paths, home paths, and unrelated directories.

T08 · Insecure Dependencies

Warning
Location
scripts/requirements.txt:4
Finding

Unpinned and Unverified Third-Party Dependencies

Content
View full analysis

Vulnerability Details

File Location: scripts/requirements.txt:4-20
Related Installation Instructions: SKILL.md:24-27 and README.md:18-21
Vulnerability Type: Unbounded dependency resolution without integrity verification
Risk Level: Medium

Vulnerable Code

text
# LangChain core
langchain>=0.1.0
langchain-community>=0.0.10

# Vector database
chromadb>=0.4.0

# Embedding model
sentence-transformers>=2.2.0

# Document loaders
pypdf>=3.0.0
unstructured>=0.10.0
python-docx>=0.8.11
openpyxl>=3.1.0  # Excel support

# Optional enhanced PDF processing
pdfplumber>=0.9.0

The documented installation command is:

bash
cd scripts
pip install -r requirements.txt

Technical Analysis

Every active dependency uses an open-ended minimum-version constraint. There are no exact version pins, lock files, package hashes, or index restrictions.

Consequently, each installation resolves against the package repository state at installation time. The installed dependency graph may therefore differ significantly from the versions reviewed with this Skill. A compromised future release, malicious transitive dependency, or newly introduced vulnerable version could be selected automatically.

Python package installation can execute package build logic, and imported dependencies run with the permissions of the invoking account. The broad packages in this dependency set also introduce a substantial transitive dependency tree, increasing supply-chain exposure.

Attack Path

  1. The user follows the documented installation procedure.
  2. pip resolves each open-ended requirement and its transitive dependencies from the configured package index.
  3. A compromised, malicious, or vulnerable version satisfying the minimum constraint is selected.
  4. Malicious behavior may execute during package build, installation, import, model initialization, or document processing.
  5. The packa ...[truncated 755 chars]
Remediation
View remediation

Remediation Suggestions

  1. Pin all direct dependencies to reviewed exact versions.
  2. Generate and commit a lock file that includes the complete transitive dependency graph.
  3. Use hash verification, such as pip install --require-hashes, with trusted package hashes.
  4. Configure installation to use an approved package index and disable unintended extra indexes.
  5. Install dependencies inside an isolated virtual environment or container using a nonprivileged account.
  6. Run automated dependency vulnerability and license scanning on every update.
  7. Review dependency update changes before regenerating the lock file.
  8. Separate optional dependencies into explicit extras so unnecessary packages are not installed by default.

T09 · Insecure Skill Coding Practices

Warning
Location
PUSH_GUIDE.md:15
Finding

GitHub Personal Access Token Exposed Through Command-Line URL

Content
View full analysis

Vulnerability Details

File Location: PUSH_GUIDE.md:15-31 and PUSH_GUIDE.md:94-100
Vulnerability Type: Insecure credential handling in operational instructions
Risk Level: Medium

Vulnerable Code

markdown
### Method 1: Use a Personal Access Token (recommended)

#### 1. Create a Token

Visit: https://github.com/settings/tokens

- Click "Generate new token (classic)"
- Select the `repo` permission for full control
- Generate and copy the token

#### 2. Push the code

```bash
cd <skill-directory>

# Push using the token
git push https://YOUR_TOKEN@github.com/AIxbinge/rag-skill.git main
text

The guide repeats the pattern in its quick command section:

```bash
git push https://ghp_YOUR_TOKEN_HERE@github.com/AIxbinge/rag-skill.git main

Technical Analysis

The publishing guide recommends a classic GitHub personal access token with broad repo permissions and instructs the user to place it directly in a command-line URL.

A real token substituted into this command may be exposed through:

  • Persistent shell history.
  • Terminal transcripts and automation logs.
  • Process command-line inspection while the command runs.
  • Debug output, diagnostics, or support bundles.
  • Accidental sharing of copied commands.
  • Git configuration or credential-related error output in some workflows.

Broad classic repo scope magnifies the impact because the credential may authorize access to more repositories than the single target repository.

Attack Path

  1. The user creates a classic PAT with full repo scope as directed.
  2. The user substitutes the real secret into the documented git push command.
  3. The full command is retained in shell history, logs, or another observable command-line channel.
  4. An attacker with access to that artifact extracts the token.
  5. The attacker authenticates to GitHub using the stolen PAT.
  6. The attacker accesses or modifies ev ...[truncated 576 chars]
Remediation
View remediation

Remediation Suggestions

  1. Remove all examples that embed credentials directly in command-line URLs.
  2. Prefer Git Credential Manager, gh auth login, or SSH authentication.
  3. If a PAT is unavoidable, use a fine-grained token restricted to the single repository and only the required permissions.
  4. Configure a short expiration period and rotate or revoke tokens immediately if exposure is suspected.
  5. Use a credential helper that supplies the secret outside the command argument.
  6. Make secure credential-manager authentication the recommended method rather than the secondary method.
  7. Add an explicit warning that secrets must not be placed in shell commands, repository remotes, scripts, logs, or documentation.
  8. Advise users who followed the existing instructions to remove affected shell-history entries and revoke the exposed token.
Vulnerability Patterns
  • Data ExfiltrationExternal Transmission, Env Variable Harvesting, File System Enumeration
  • Privilege EscalationExcessive Permissions, Sudo/Root Execution, Credential Access
  • MCP Least PrivilegeUnderdeclared Capability, Wildcard Permission, Missing Permission Declaration
  • MCP Tool PoisoningHidden Instructions, Unicode Deception, Parameter Description Injection
  • Prompt InjectionInstruction Override, Hidden Instructions, Exfiltration Commands
Findings (48)

Credential Access

High
Category
Privilege Escalation
Confidence
70% confidence
Finding

Code accesses credential files (SSH keys, AWS credentials, etc.). This could indicate credential theft attempts.

Content

Scanner excerpt · PUSH_GUIDE.md (reported line 15)May include surrounding context.

md
---

### 方法 1: 使用 Personal Access Token (推荐)

#### 1. 创建 Token

Credential Access

High
Category
Privilege Escalation
Confidence
90% confidence
Finding

Code accesses credential files (SSH keys, AWS credentials, etc.). This could indicate credential theft attempts.

Content

Scanner excerpt · PUSH_GUIDE.md (reported line 56)May include surrounding context.

ssh-keygen -t ed25519 -C "your_email@example.com"

查看公钥

cat ~/.ssh/id_ed25519.pub

将公钥添加到 GitHub: https://github.com/settings/keys

text

Tp4

High
Category
MCP Tool Poisoning
Confidence
98% confidence
Finding

The declared description presents a knowledge-base assistant centered on vector search and document Q&A with Chroma and BGE-M3. The supplied code chunk does none of that: it simply converts PDF pages into PNG images and saves them locally. While PDF handling could conceivably be a preprocessing step in a larger system, this specific chunk's primary behavior is materially different from the declared skill purpose and lacks the key claimed capabilities (retrieval, embeddings, vector DB, Q&A).

Content

No source excerpt is available for this finding.

Tp4

High
Category
MCP Tool Poisoning
Confidence
97% confidence
Finding

该代码块的核心功能是“索引构建”,而不是声明中的“知识库助手”或“RAG 查询”执行器。它确实使用了 Chroma 和 HuggingFaceEmbeddings(BAAI/bge-m3),并支持 PDF、Markdown、TXT、DOCX 的加载与分块,但没有实现用户查询入口、相似度检索、LLM 生成回答或任何问答流程。另一个明显不一致点是声明提到支持 Excel,而代码虽然扫描 .xlsx 文件数量,却没有对应的加载器或处理逻辑,因此 Excel 支持并未真正实现。综合来看,声明显著夸大了实际能力,属于描述与行为不匹配。

Content

No source excerpt is available for this finding.

Tp4

High
Category
MCP Tool Poisoning
Confidence
96% confidence
Finding

存在实质性描述与行为不一致。首先,核心模型不符:描述写明使用 BGE-M3 Embedding,但代码通过 http://localhost:11434/api/embeddings 调用 Ollama,并默认使用 nomic-embed-text-v2-moe。其次,描述强调 RAG 助手、语义检索和智能问答,而该代码块仅负责索引阶段:加载文档、分块、生成向量并存入 Chroma,没有任何查询、召回、生成回答或交互逻辑。最后,描述称支持 Excel,但代码虽然统计了 .xlsx 文件数量,却没有相应 loader,实际不处理 Excel 内容。因此该代码块不能准确代表所声明的完整技能描述。

Content

No source excerpt is available for this finding.

Tp4

High
Category
MCP Tool Poisoning
Confidence
95% confidence
Finding

该代码与“知识库检索”这一大方向相关,确实使用了 Chroma 向量库并进行语义相似度搜索,因此并非完全无关。但声明包含若干关键能力和实现细节,代码并未体现:1) 嵌入模型不一致,声明是 BGE-M3,实际是 Ollama 的 nomic-embed-text-v2-moe;2) 没有多格式文档处理能力,只有对已建索引的查询;3) 没有完整 RAG 问答生成,只返回检索片段;4) 实际资源是本地持久化 vectorstore 和本地 Ollama 服务,而不是直接对 knowledge 目录进行检索。由于这些差异涉及主要能力和实现方式,应判定为描述与行为不匹配。

Content

No source excerpt is available for this finding.

Ae1

High
Category
analysis-evasion
Confidence
100% confidence
Finding

Referenced artifact was not completely inspected

Content

Scanner excerpt · SKILL.md (reported line 401)May include surrounding context.

md
- `scripts/requirements.txt` - Python 依赖

Missing User Warnings

Medium
Category
Not specified by scanner
Confidence
97% confidence
Finding

The guide explicitly recommends embedding a GitHub Personal Access Token directly in the git push URL. This is dangerous because tokens can be exposed through shell history, process listings, logs, screenshots, copied commands, or accidentally committed documentation, leading to unauthorized repository access. In this skill context, the risk is higher because the document is a push guide intended for direct copy/paste by users.

Content

No source excerpt is available for this finding.

Missing User Warnings

Medium
Category
Not specified by scanner
Confidence
95% confidence
Finding

README 指导用户执行索引构建并将 knowledge 目录内容写入 ./vectorstore,但没有明确提醒该过程会提取、向量化并持久化用户文档内容。对于可能包含内部制度、产品文档或敏感资料的知识库,这种缺乏披露会导致用户在不了解数据落盘、保留范围和后续访问面的情况下处理敏感信息。

Content

No source excerpt is available for this finding.

Undeclared Tool Scope

Medium
Category
MCP Least Privilege
Confidence
88% confidence
Finding

The skill documentation instructs users to run scripts that read from the knowledge directory, write a persistent vector store and logs, and install dependencies, but it declares no explicit tool scope or permission boundaries. This makes file and network access implicit rather than user-auditable, increasing the chance of overbroad execution or unintended data exposure when the skill is invoked.

Content

No source excerpt is available for this finding.

Missing User Warnings

Medium
Category
Not specified by scanner
Confidence
90% confidence
Finding

The skill encourages indexing local documents into a persistent vector store and writing logs, but it does not warn users that sensitive document contents and metadata may be retained outside the original files. In a knowledge-base context, this is more dangerous because the indexed corpus may include internal HR, product, or security documents, creating secondary storage that can be queried or leaked later.

Content

No source excerpt is available for this finding.

Natural-Language Policy Violations

Medium
Category
Not specified by scanner
Confidence
91% confidence
Finding

The document title and instructional content are entirely in Chinese, and there is no indication that the user can choose another language or that the skill is intentionally limited to a Chinese-only regional context. The policy explicitly calls for flagging language or locale constraints when they are imposed without opt-in or justification.

Content

No source excerpt is available for this finding.

Natural-Language Policy Violations

Medium
Category
Not specified by scanner
Confidence
93% confidence
Finding

The entire document is written in Chinese and does not provide any indication that language selection is optional or that the skill is intentionally restricted to a Chinese-speaking context. Under the policy, forcing a specific language without user opt-in is a natural-language policy violation.

Content

No source excerpt is available for this finding.

Natural-Language Policy Violations

Medium
Category
Not specified by scanner
Confidence
88% confidence
Finding

该技能文档从标题开始即完全以中文呈现,未说明这是面向特定中文用户群体的区域性工具,也未提供语言选择或其他语言版本指引。根据规则,强制特定语言而无用户选择或明确、合理的约束说明,属于自然语言层面的语言/locale 政策问题。

Content

No source excerpt is available for this finding.

Missing User Warnings

Medium
Category
Not specified by scanner
Confidence
93% confidence
Finding

The document includes concrete examples for decrypting password-protected PDFs with pypdf and qpdf, but omits an authorization warning limiting use to files the operator is permitted to access. In a knowledge-assistant skill that helps users process arbitrary uploaded or local documents, this can normalize or facilitate unauthorized access to protected content, especially because the examples are immediately actionable.

Content

No source excerpt is available for this finding.

Description-Behavior Mismatch

Medium
Category
Not specified by scanner
Confidence
96% confidence
Finding

The manifest describes a knowledge assistant for semantic retrieval and question answering over documents in a knowledge directory using a vector database and embeddings. This script instead performs standalone PDF page rasterization and writes PNG files to disk, which is a document-conversion capability not mentioned in the manifest's stated behavior.

Content

No source excerpt is available for this finding.

Description-Behavior Mismatch

Medium
Category
Not specified by scanner
Confidence
97% confidence
Finding

The manifest and module description state support for Excel/多格式文档 including Excel, and the code even counts .xlsx files during scanning. However, there is no loader branch that reads .xlsx content into documents, so Excel files are never indexed despite being advertised as supported.

Content

No source excerpt is available for this finding.

Natural-Language Policy Violations

Medium
Category
Not specified by scanner
Confidence
98% confidence
Finding

The module docstring and usage text are written only in Chinese, and the rest of the script continues that pattern for all user-facing messages. Because this is a general-purpose indexing tool rather than a clearly region-specific compliance workflow, hard-coding a single language without user choice is a natural-language policy violation under the locale/language rule.

Content

No source excerpt is available for this finding.

Intent-Code Divergence

Medium
Category
Not specified by scanner
Confidence
88% confidence
Finding

The failure message lists supported formats as excluding .xlsx, while elsewhere the script counts .xlsx files and the surrounding skill description advertises Excel support. This creates contradictory documentation/signaling about actual supported file types and obscures that Excel files are not indexed at all.

Content

No source excerpt is available for this finding.

External Transmission

Medium
Category
Data Exfiltration
Confidence
80% confidence
Finding

The script sends full document text chunks to the Ollama HTTP API for embedding generation. Even though the destination is hardcoded to localhost, this still transmits potentially sensitive knowledge-base content over an unauthenticated local service boundary; if Ollama is exposed, proxied, container-redirected, or maliciously replaced, confidential data could be disclosed.

Content

Scanner excerpt · scripts/index_knowledge_ollama.py (reported line 49)May include surrounding context.

python
}
    
    try:
        response = requests.post(url, json=payload, timeout=60)
        response.raise_for_status()
        result = response.json()
        return result["embedding"]

Description-Behavior Mismatch

Medium
Category
Not specified by scanner
Confidence
97% confidence
Finding

The skill manifest advertises support for multi-format documents including Excel, and this script also counts .xlsx files in its scan statistics. However, the actual loading logic only processes PDF, Markdown, TXT, and DOCX files; there is no loader branch for .xlsx before returning the document set. This creates a clear behavior mismatch where Excel support is claimed but not implemented.

Content

No source excerpt is available for this finding.

Internal Network Request

Medium
Category
Server-Side Request Forgery
Confidence
70% confidence
Finding

Code issues a request to a loopback, link-local, or private-range host. This can reach internal services not meant to be exposed and is a common SSRF pivot.

Content

Scanner excerpt · scripts/index_knowledge_ollama.py (reported line 264)May include surrounding context.

python
# 检查 Ollama 连接
    print("\n检查 Ollama 服务...")
    try:
        response = requests.get("http://localhost:11434/api/tags", timeout=5)
        if response.status_code == 200:
            print("✓ Ollama 服务正常运行")
        else:

External Transmission

Medium
Category
Data Exfiltration
Confidence
80% confidence
Finding

Data is being sent to an external URL. This could be legitimate telemetry or data exfiltration. Manual review is recommended.

Content

Scanner excerpt · scripts/rag_query_ollama.py (reported line 42)May include surrounding context.

python
}
    
    try:
        response = requests.post(url, json=payload, timeout=60)
        response.raise_for_status()
        result = response.json()
        return result["embedding"]

Intent-Code Divergence

Medium
Category
Not specified by scanner
Confidence
91% confidence
Finding

代码前面明确说明 Chroma 返回的是 L2 距离,且“距离越小越相似”,但 JSON 输出中却把该距离直接转换为 1 - score 并命名为 similarity。对于距离可能远大于 1 的场景,这会产生负值或无意义的“相似度”,属于文档/字段语义与实际数据含义相冲突。

Content

No source excerpt is available for this finding.

Natural-Language Policy Violations

Low
Category
Not specified by scanner
Confidence
78% confidence
Finding

文档整体以中文编写,并在最佳实践中明确推荐“使用中文 Embedding 模型”,示例触发语也全部为中文,但没有说明这是可选偏好还是仅适用于特定中文场景。根据语言/locale 政策,若技能实际上倾向或要求特定语言,应提供用户选择或清楚说明适用范围。

Content

No source excerpt is available for this finding.