cmdbox.app.features.cli.agent package

Submodules

cmdbox.app.features.cli.agent.agant_base module

class cmdbox.app.features.cli.agent.agant_base.AgentBase(appcls, ver, language: str = None)[source]

Bases: ResultEdgeFeature

apply_prompt_param(text: str, prompt_param: Dict[str, Any]) → str[source]

テキスト中のプレースホルダーを prompt_param の値で置換します

Parameters:
  • text (str) -- 置換対象のテキスト

  • prompt_param (Dict[str, Any]) -- プレースホルダーに対応するパラメータ

Returns:

置換後のテキスト

Return type:

str

async create_agent_session(*, session_service: Any, runner_name: str, user_name: str, session_id: str = None) → Any[source]

セッションを作成します

Parameters:
  • session_service (BaseSessionService) -- セッションサービス

  • runner_name (str) -- ランナー名

  • user_name (str) -- ユーザー名

  • session_id (str) -- セッションID

Returns:

セッション

Return type:

Any

create_session_service(*, logger: Logger, data_dir: Path, ds_conf: Dict[str, Any]) → Any[source]

セッションサービスを作成します

Parameters:
  • logger (logging.Logger) -- ロガー

  • data_dir (Path) -- データディレクトリ

  • ds_conf (Dict[str, Any]) -- データソースの設定

Returns:

セッションサービス

Return type:

BaseSessionService

gen_msg(event: Any) → Tuple[str, bool, bool, bool, int][source]
get_ui_widgets(event: Any) → Any[source]
load_conf(runner_name: str, data_dir: Path, logger: Logger)[source]

cmdbox.app.features.cli.agent.dangerous_sequence module

危険な文字シーケンス検知プラグイン

SQL コメント、ヌルバイト、16進数エスケープなどの危険な文字パターンを検知します。

class cmdbox.app.features.cli.agent.dangerous_sequence.DangerousSequencePlugin(*args: Any, **kwargs: Any)[source]

Bases: BasePlugin

危険な文字シーケンスを検知して無害化するプラグイン

PATTERNS = [('(?i)(--\\s+|#\\s+|;)', <function DangerousSequencePlugin.<lambda>>), ('(\\x00|\\x1a)', <function DangerousSequencePlugin.<lambda>>), ('(\\\\x[0-9a-f]{2})', <function DangerousSequencePlugin.<lambda>>)]
async on_event_callback(*, invocation_context: google.adk.agents.invocation_context.InvocationContext, event: google.adk.events.Event) → google.adk.events.Event | None[source]

イベントをチェックして危険な文字シーケンスを無害化

async on_user_message_callback(*, invocation_context, user_message)[source]

ユーザーメッセージをチェックして危険な文字シーケンスを無害化

sanitize_text(text: str) → str[source]

指定されたテキストを危険な文字シーケンスから無害化

cmdbox.app.features.cli.agent.detection_malicious_keyword module

悪意のあるキーワード検知プラグイン

危険なキーワードやコマンドのパターンを検知します。

class cmdbox.app.features.cli.agent.detection_malicious_keyword.MaliciousKeywordDetectionPlugin(*args: Any, **kwargs: Any)[source]

Bases: BasePlugin

悪意のあるキーワードを検知するプラグイン

PATTERNS = ['(?i)\\b(drop\\s+database|truncate\\s+table|exec\\s+xp_|sp_oacreate)', '(?i)(\\bignore\\b|\\bby\\s+pass\\b|\\badmin\\b.*?\\bpassword\\b)', '(?i)(union\\s+all\\s+select)']
async on_event_callback(*, invocation_context: google.adk.agents.invocation_context.InvocationContext, event: google.adk.events.Event) → google.adk.events.Event | None[source]

イベントをチェックして悪意のあるキーワードを検知

async on_user_message_callback(*, invocation_context, user_message)[source]

ユーザーメッセージをチェックして悪意のあるキーワードを検知

cmdbox.app.features.cli.agent.detection_sql_injection module

SQL インジェクション検知プラグイン

SQL インジェクション攻撃パターンを検知し、PromptInjectionException を発生させます。

class cmdbox.app.features.cli.agent.detection_sql_injection.SQLInjectionDetectionPlugin(*args: Any, **kwargs: Any)[source]

Bases: BasePlugin

SQL インジェクション攻撃を検知するプラグイン

PATTERNS = ['(?i)\\b(union|select|insert|update|delete|drop|create|alter|exec|execute)\\b.*?(?:from|into|values|set|where|;)', "(?i)('\\s*or\\s*'|'\\s*or\\s*1\\s*=\\s*1|--\\s*|;.*?(union|select|insert))", '(?i)(\\bor\\b\\s*1\\s*=\\s*1|\\bor\\b\\s*true\\b)', '(?i)(xp_cmdshell|exec\\s+sp_|sp_executesql)', "(?i)(sqlmap|' and '1'='1)"]
async on_event_callback(*, invocation_context: google.adk.agents.invocation_context.InvocationContext, event: google.adk.events.Event) → google.adk.events.Event | None[source]

イベントをチェックして SQL インジェクションを検知

async on_user_message_callback(*, invocation_context, user_message)[source]

ユーザーメッセージをチェックして SQL インジェクションを検知

cmdbox.app.features.cli.agent.detection_template_injection module

Jinja2 テンプレートインジェクション検知プラグイン

Jinja2 テンプレートエンジンを対象とした SSTI(Server-Side Template Injection)パターンを検知します。

class cmdbox.app.features.cli.agent.detection_template_injection.TemplateInjectionDetectionPlugin(*args: Any, **kwargs: Any)[source]

Bases: BasePlugin

Jinja2/テンプレートインジェクション攻撃を検知するプラグイン

PATTERNS = ['\\{\\{.*?__.*?\\}\\}', '\\{\\{.*?self\\._TemplateModule__dict__.*?\\}\\}', '\\{%.*?import.*?%\\}', '\\{\\{.*?config\\.items\\(\\).*?\\}\\}', '\\{\\{.*?request\\.environ.*?\\}\\}', '{{.*?popen.*?}}', '{{.*?system.*?}}']
async on_event_callback(*, invocation_context: google.adk.agents.invocation_context.InvocationContext, event: google.adk.events.Event) → google.adk.events.Event | None[source]

イベントをチェックして Jinja2 テンプレートインジェクションを検知

async on_user_message_callback(*, invocation_context, user_message)[source]

ユーザーメッセージをチェックして Jinja2 テンプレートインジェクションを検知

cmdbox.app.features.cli.agent.javascript_injection module

JavaScript/HTML インジェクション無害化プラグイン

XSS(クロスサイトスクリプティング)および HTML インジェクション攻撃パターンを無害化します。

class cmdbox.app.features.cli.agent.javascript_injection.JavaScriptInjectionPlugin(*args: Any, **kwargs: Any)[source]

Bases: BasePlugin

JavaScript/HTML インジェクション攻撃を無害化するプラグイン

JS_PATTERNS = [('javascript:', re.IGNORECASE), ('on\\w+\\s*=\\s*[\\"\']?.*?[\\"\']', re.IGNORECASE), ('eval\\s*\\(', re.IGNORECASE), ('new\\s+Function\\s*\\(', re.IGNORECASE)]
async on_event_callback(*, invocation_context: google.adk.agents.invocation_context.InvocationContext, event: google.adk.events.Event) → google.adk.events.Event | None[source]

イベントをチェックして JavaScript/HTML インジェクションを無害化

async on_user_message_callback(*, invocation_context, user_message)[source]

ユーザーメッセージをチェックして JavaScript インジェクションを無害化

sanitize_text(text: str) → str[source]

指定されたテキストを JavaScript/HTML インジェクションから無害化

cmdbox.app.features.cli.agent.prompt_injection_common module

exception cmdbox.app.features.cli.agent.prompt_injection_common.PromptInjectionException(message: str, pattern_type: str | None = None, matched_content: str | None = None)[source]

Bases: Exception

プロンプトインジェクション検知時の例外

to_dict() → Dict[str, Any][source]

例外情報を辞書形式で取得

Module contents

プロンプトインジェクション検知パッケージ

複数の検知プラグインとユーティリティクラスを提供します。

class cmdbox.app.features.cli.agent.DangerousSequencePlugin(*args: Any, **kwargs: Any)[source]

Bases: BasePlugin

危険な文字シーケンスを検知して無害化するプラグイン

PATTERNS = [('(?i)(--\\s+|#\\s+|;)', <function DangerousSequencePlugin.<lambda>>), ('(\\x00|\\x1a)', <function DangerousSequencePlugin.<lambda>>), ('(\\\\x[0-9a-f]{2})', <function DangerousSequencePlugin.<lambda>>)]
async on_event_callback(*, invocation_context: google.adk.agents.invocation_context.InvocationContext, event: google.adk.events.Event) → google.adk.events.Event | None[source]

イベントをチェックして危険な文字シーケンスを無害化

async on_user_message_callback(*, invocation_context, user_message)[source]

ユーザーメッセージをチェックして危険な文字シーケンスを無害化

sanitize_text(text: str) → str[source]

指定されたテキストを危険な文字シーケンスから無害化

class cmdbox.app.features.cli.agent.JavaScriptInjectionPlugin(*args: Any, **kwargs: Any)[source]

Bases: BasePlugin

JavaScript/HTML インジェクション攻撃を無害化するプラグイン

JS_PATTERNS = [('javascript:', re.IGNORECASE), ('on\\w+\\s*=\\s*[\\"\']?.*?[\\"\']', re.IGNORECASE), ('eval\\s*\\(', re.IGNORECASE), ('new\\s+Function\\s*\\(', re.IGNORECASE)]
async on_event_callback(*, invocation_context: google.adk.agents.invocation_context.InvocationContext, event: google.adk.events.Event) → google.adk.events.Event | None[source]

イベントをチェックして JavaScript/HTML インジェクションを無害化

async on_user_message_callback(*, invocation_context, user_message)[source]

ユーザーメッセージをチェックして JavaScript インジェクションを無害化

sanitize_text(text: str) → str[source]

指定されたテキストを JavaScript/HTML インジェクションから無害化

class cmdbox.app.features.cli.agent.MaliciousKeywordDetectionPlugin(*args: Any, **kwargs: Any)[source]

Bases: BasePlugin

悪意のあるキーワードを検知するプラグイン

PATTERNS = ['(?i)\\b(drop\\s+database|truncate\\s+table|exec\\s+xp_|sp_oacreate)', '(?i)(\\bignore\\b|\\bby\\s+pass\\b|\\badmin\\b.*?\\bpassword\\b)', '(?i)(union\\s+all\\s+select)']
async on_event_callback(*, invocation_context: google.adk.agents.invocation_context.InvocationContext, event: google.adk.events.Event) → google.adk.events.Event | None[source]

イベントをチェックして悪意のあるキーワードを検知

async on_user_message_callback(*, invocation_context, user_message)[source]

ユーザーメッセージをチェックして悪意のあるキーワードを検知

exception cmdbox.app.features.cli.agent.PromptInjectionException(message: str, pattern_type: str | None = None, matched_content: str | None = None)[source]

Bases: Exception

プロンプトインジェクション検知時の例外

to_dict() → Dict[str, Any][source]

例外情報を辞書形式で取得

class cmdbox.app.features.cli.agent.SQLInjectionDetectionPlugin(*args: Any, **kwargs: Any)[source]

Bases: BasePlugin

SQL インジェクション攻撃を検知するプラグイン

PATTERNS = ['(?i)\\b(union|select|insert|update|delete|drop|create|alter|exec|execute)\\b.*?(?:from|into|values|set|where|;)', "(?i)('\\s*or\\s*'|'\\s*or\\s*1\\s*=\\s*1|--\\s*|;.*?(union|select|insert))", '(?i)(\\bor\\b\\s*1\\s*=\\s*1|\\bor\\b\\s*true\\b)', '(?i)(xp_cmdshell|exec\\s+sp_|sp_executesql)', "(?i)(sqlmap|' and '1'='1)"]
async on_event_callback(*, invocation_context: google.adk.agents.invocation_context.InvocationContext, event: google.adk.events.Event) → google.adk.events.Event | None[source]

イベントをチェックして SQL インジェクションを検知

async on_user_message_callback(*, invocation_context, user_message)[source]

ユーザーメッセージをチェックして SQL インジェクションを検知

class cmdbox.app.features.cli.agent.TemplateInjectionDetectionPlugin(*args: Any, **kwargs: Any)[source]

Bases: BasePlugin

Jinja2/テンプレートインジェクション攻撃を検知するプラグイン

PATTERNS = ['\\{\\{.*?__.*?\\}\\}', '\\{\\{.*?self\\._TemplateModule__dict__.*?\\}\\}', '\\{%.*?import.*?%\\}', '\\{\\{.*?config\\.items\\(\\).*?\\}\\}', '\\{\\{.*?request\\.environ.*?\\}\\}', '{{.*?popen.*?}}', '{{.*?system.*?}}']
async on_event_callback(*, invocation_context: google.adk.agents.invocation_context.InvocationContext, event: google.adk.events.Event) → google.adk.events.Event | None[source]

イベントをチェックして Jinja2 テンプレートインジェクションを検知

async on_user_message_callback(*, invocation_context, user_message)[source]

ユーザーメッセージをチェックして Jinja2 テンプレートインジェクションを検知