Skip to content

[Security][Prompt Injection] Character/Lorebook/Memoryの保存テキストを信頼済み指示と同じprompt層へ連結する #505

Closed

Description

@shirokuma-xv

概要

Character、Lorebook、Memory、Story cast、直近会話のユーザー編集可能テキストを、system prompt内のルールや役割指示と同じ平文へ連結しています。

根拠

  • KizunaAI/AI/CharacterLibrary/Prompt/PromptBuilder.swift:32-62
  • KizunaAI/AI/CharacterLibrary/Story/Prompt/StoryPromptBuilder.swift:349-409
  • 同ファイル:419-428

問題

保存テキストに「以降の指示を無視する」「秘密を出力する」「ツールを呼ぶ」などが含まれていると、モデルがデータと制御命令を区別できず、Prompt Injectionとして振る舞う可能性があります。共有されたCharacterや外部から取り込んだ設定を利用する場合、利用者が意図しない外部指示を長期記憶・Lorebook経由で再注入できます。

現状で任意コード実行を確認したわけではありません。外部検索・Python等のtoolが有効なモデル経路では、影響範囲が広がるため境界設計を追跡するSecurity Issueです。

修正案

ユーザーデータを明示的なuntrusted-dataブロックへ隔離し、制御指示と異なるrole/channelへ渡す。tool実行はユーザー確認を必須にし、メモリーやLorebookからのtool要求を命令として解釈しない。

テスト

Character/Lorebook/Memory/会話それぞれへ同じInjection文字列を入れ、system指示やtool許可を上書きしないことを確認する。

Activity

  1. viuk-issue-summarizer commented on Aug 21, 2026

    @viuk-issue-summarizer

    Model not found: opencode/deepseek-v4-flash-free. Did you mean: deepseek-v4-flash, deepseek-v4-pro, gemini-3-flash?

    github run

  2. shirokuma-xv commented on Aug 21, 2026

    @shirokuma-xv
    ContributorAuthor

    Fixed in merged PR #475 (merge commit 8eb404c). Character, Lorebook, Memory, profile, recent conversation, user input, and Story context are wrapped as explicit untrusted_data reference blocks, with prompt rules stating that their contents cannot change roles, instructions, or tool permissions. The full macOS XCTest and CI passed. The original PR used a combined Fixes #504/#505 reference, so this issue was not auto-closed.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions