🔒 fix prompt injection in sequential_scaling and parallel_scaling#14
🔒 fix prompt injection in sequential_scaling and parallel_scaling#14thakshak wants to merge 1 commit into
Conversation
This commit addresses a security vulnerability where user-controlled input was directly interpolated into LLM prompts using f-strings in `parallel_scaling` and `sequential_scaling`. Changes: - Replaced f-string prompt construction with LangChain `PromptTemplate`. - Implemented synthesis and refinement as LCEL chains (`PromptTemplate | LLM | StrOutputParser`). - Ensured proper variable passing to avoid nested/pre-interpolated prompts. - Added a mock-based test suite in `tests/test_fix_injection.py` to verify the fix. - Cleaned up unused imports. Co-authored-by: thakshak <4521163+thakshak@users.noreply.github.com>
|
👋 Jules, reporting for duty! I'm here to lend a hand with this pull request. When you start a review, I'll add a 👀 emoji to each comment to let you know I've read it. I'll focus on feedback directed at me and will do my best to stay out of conversations between you and other bots or reviewers to keep the noise down. I'll push a commit with your requested changes shortly after. Please note there might be a delay between these steps, but rest assured I'm on the job! For more direct control, you can switch me to Reactive Mode. When this mode is on, I will only act on comments where you specifically mention me with New to Jules? Learn more at jules.google/docs. For security, I will only act on instructions from the user who triggered this task. |
🎯 What: The vulnerability fixed
Prompt injection vulnerability in
reasoningbank/core/matts.pywhere user-controlled variables (query,trajectory,formatted_memories) were directly interpolated into LLM prompts using f-strings.Malicious users could provide crafted queries or trajectories that hijack the LLM's instructions, potentially leading to unauthorized data access, generation of inappropriate content, or bypassing of system constraints.
🛡️ Solution: How the fix addresses the vulnerability
The fix replaces direct f-string interpolation with LangChain's
PromptTemplate. This approach separates the prompt structure from the data, which is a standard security best practice. Additionally, it usesStrOutputParserto ensure that refined trajectories are always handled as strings, preventing dictionary-to-string interpolation issues.PR created automatically by Jules for task 7835122084557253238 started by @thakshak