Back to skill

Security audit

friend-skill

Security checks for vulnerabilities and agentic risk

Overview

This is a local friend-persona builder, but it needs review because crafted names can make it write files outside its intended folder.

Review before installing or running. Use only chat logs and relationship details you are authorized to process, avoid importing group or third-party private conversations, and do not run the builder with untrusted names or JSON files until filename sanitization is fixed.

Vulnerability Patterns
  • 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
  • Embedded Malicious CodeShips malicious scripts inside the skill and executes them locally
Findings (1)

T09 · Insecure Skill Coding Practices

Warning
Location
README.md:398
Finding

Path Traversal Allows File Writes Outside the Intended Friends Directory

Content
View full analysis

Vulnerability Details

File Location: README.md:280-288, README.md:398-400, and README.md:443-463
Vulnerability Type: Path traversal leading to an arbitrary-location file write
Risk Level: Medium

Vulnerable Code

The save method creates parent directories and writes to the supplied path:

js
// 保存到文件
save(filePath) {
  const dir = path.dirname(filePath);
  if (!fs.existsSync(dir)) {
    fs.mkdirSync(dir, { recursive: true });
  }
  fs.writeFileSync(filePath, this.toJSON(), 'utf-8');
  console.log(`✅ 朋友分身已保存到: ${filePath}`);
  return this;
}

In interactive mode, the user-controlled friend name is inserted directly into the output path:

js
const outputDir = path.join(__dirname, '..', 'friends');
const outputFile = path.join(outputDir, `${name}-friend.json`);
persona.save(outputFile);

The JSON build mode similarly inserts data.name into the output path without validation:

js
} else if (args[0] === '--build' && args[1]) {
  try {
    const data = JSON.parse(fs.readFileSync(args[1], 'utf-8'));
    const persona = new FriendPersona(data.name || '朋友');
    
    if (data.records) {
      persona.analyzeChatRecords(data.records);
    }
    if (data.personality) {
      Object.assign(persona.friend.personality, data.personality);
    }
    if (data.relationship) {
      Object.assign(persona.friend.relationship, data.relationship);
    }
    if (data.interests) {
      Object.assign(persona.friend.interests, data.interests);
    }
    if (data.voice) {
      Object.assign(persona.friend.voice, data.voice);
    }

    const outputFile = path.join(__dirname, '..', 'friends', `${data.name || 'friend'}-friend.json`);
    persona.save(outputFile);
  } catch (e) {
    console.error('❌ 构建失败:', e.message);
  }
}

Technical Analysis

Both the interactive name value and JSON-controlled data.name value are use ...[truncated 2399 chars]

Remediation
View remediation

Remediation Suggestions

  1. Treat friend names exclusively as display data and generate storage filenames independently, such as with a UUID.

  2. If names must be used in filenames, enforce a strict allowlist that rejects /, \, .., null bytes, control characters, and platform-specific reserved characters.

  3. Resolve and validate the destination before writing:

    js
    function safeOutputPath(name) {
      const baseDir = path.resolve(__dirname, '..', 'friends');
      const safeName = name.replace(/[^a-zA-Z0-9_-]/g, '_');
      const outputPath = path.resolve(baseDir, `${safeName}-friend.json`);
    
      if (!outputPath.startsWith(baseDir + path.sep)) {
        throw new Error('Invalid output filename');
      }
    
      return outputPath;
    }
    
  4. Apply the same validation to both interactive input and --build JSON input.

  5. Avoid silently overwriting existing files. Use an exclusive creation mode such as flag: 'wx', or require explicit user confirmation before replacement.

  6. Create only the known friends directory rather than recursively creating directories derived from an untrusted destination path.

  7. Add tests covering traversal values such as ../name, ../../target, mixed separators, encoded separators, and platform-specific absolute path forms.

Vulnerability Patterns
  • MCP Tool PoisoningHidden Instructions, Unicode Deception, Parameter Description Injection
  • Prompt InjectionInstruction Override, Hidden Instructions, Exfiltration Commands
  • Data ExfiltrationExternal Transmission, Env Variable Harvesting, File System Enumeration
  • Privilege EscalationExcessive Permissions, Sudo/Root Execution, Credential Access
  • Supply ChainUnpinned Dependencies, External Script Fetching, Obfuscated Code
Findings (5)

Missing User Warnings

Medium
Category
Not specified by scanner
Confidence
90% confidence
Finding

The tool explicitly collects sensitive interpersonal data, including names, relationship details, shared memories, and imported chat logs, but only provides a broad 'local processing' privacy statement rather than an explicit warning about sensitivity, third-party consent, or safe handling of another person's communications. This creates privacy and consent risk because users may ingest highly personal data about friends without understanding the implications of storing, analyzing, and reproducing it in a generated persona file.

Content

No source excerpt is available for this finding.

Natural-Language Policy Violations

Medium
Category
Not specified by scanner
Confidence
90% confidence
Finding

The file presents all user-facing instructions and descriptions exclusively in Chinese, which can amount to forcing a specific language without user opt-in. The policy allows locale constraints when they are justified or optional, but no such opt-in or justification is provided here.

Content

No source excerpt is available for this finding.

Intent-Code Divergence

Medium
Category
Not specified by scanner
Confidence
92% confidence
Finding

The header says this file is a usable 'Friend Chat Demo' invoked as a standalone chat script, but at L011 it requires './friend-builder' from within friend-builder.js itself. That contradicts the documented intent of being an operational demo, because the implementation shown is wired inconsistently with the file identity and would not match the documented entrypoint behavior.

Content

No source excerpt is available for this finding.

Natural-Language Policy Violations

Medium
Category
Not specified by scanner
Confidence
96% confidence
Finding

The header comments and usage examples are written only in Chinese, and the interactive UI messages throughout the script are likewise Chinese-only. For a general-purpose chat demo, this imposes a specific language/locale on users without opt-in or an explained regional limitation, which matches the language-policy violation criteria.

Content

No source excerpt is available for this finding.

Natural-Language Policy Violations

Low
Category
Not specified by scanner
Confidence
88% confidence
Finding

The user-facing instructions, prompts, and generated interaction text are all in Chinese, and the logic is tailored to Chinese-language chat analysis. There is no indication that users can opt into another language or that the locale restriction is explicitly documented as a justified regional constraint.

Content

No source excerpt is available for this finding.