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
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]
イベントをチェックして危険な文字シーケンスを無害化
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)']
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:
BasePluginSQL インジェクション攻撃を検知するプラグイン
- 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)"]
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:
BasePluginJinja2/テンプレートインジェクション攻撃を検知するプラグイン
- PATTERNS = ['\\{\\{.*?__.*?\\}\\}', '\\{\\{.*?self\\._TemplateModule__dict__.*?\\}\\}', '\\{%.*?import.*?%\\}', '\\{\\{.*?config\\.items\\(\\).*?\\}\\}', '\\{\\{.*?request\\.environ.*?\\}\\}', '{{.*?popen.*?}}', '{{.*?system.*?}}']
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:
BasePluginJavaScript/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 インジェクションを無害化
cmdbox.app.features.cli.agent.prompt_injection_common module
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]
イベントをチェックして危険な文字シーケンスを無害化
- class cmdbox.app.features.cli.agent.JavaScriptInjectionPlugin(*args: Any, **kwargs: Any)[source]
Bases:
BasePluginJavaScript/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 インジェクションを無害化
- 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)']
- exception cmdbox.app.features.cli.agent.PromptInjectionException(message: str, pattern_type: str | None = None, matched_content: str | None = None)[source]
Bases:
Exceptionプロンプトインジェクション検知時の例外
- class cmdbox.app.features.cli.agent.SQLInjectionDetectionPlugin(*args: Any, **kwargs: Any)[source]
Bases:
BasePluginSQL インジェクション攻撃を検知するプラグイン
- 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)"]
- class cmdbox.app.features.cli.agent.TemplateInjectionDetectionPlugin(*args: Any, **kwargs: Any)[source]
Bases:
BasePluginJinja2/テンプレートインジェクション攻撃を検知するプラグイン
- PATTERNS = ['\\{\\{.*?__.*?\\}\\}', '\\{\\{.*?self\\._TemplateModule__dict__.*?\\}\\}', '\\{%.*?import.*?%\\}', '\\{\\{.*?config\\.items\\(\\).*?\\}\\}', '\\{\\{.*?request\\.environ.*?\\}\\}', '{{.*?popen.*?}}', '{{.*?system.*?}}']