Class: RuboCop::Cop::Prompt::SystemInjection
- Inherits:
-
Base
- Object
- Base
- RuboCop::Cop::Prompt::SystemInjection
- Defined in:
- lib/rubocop/cop/prompt/system_injection.rb
Overview
Checks for dynamic variable interpolation in SYSTEM heredocs.
This cop identifies code in classes, modules, or methods with “prompt” in their names and ensures that SYSTEM heredocs do not contain dynamic variable interpolations like #user_msg. Dynamic interpolation in system prompts can lead to prompt injection vulnerabilities.
Constant Summary collapse
- MSG =
"Avoid dynamic interpolation in SYSTEM heredocs to prevent prompt injection vulnerabilities"
Instance Method Summary collapse
Instance Method Details
#on_dstr(node) ⇒ Object
38 39 40 41 42 43 44 |
# File 'lib/rubocop/cop/prompt/system_injection.rb', line 38 def on_dstr(node) return unless in_prompt_context?(node) return unless system_heredoc?(node) return unless has_interpolation?(node) add_offense(node) end |