CAMEL-24607: camel-langchain4j-agent-api - CodeInjectionGuardrail must count distinct injection types - #26065
Merged
Merged
Conversation
…t count distinct injection types
In non-strict mode CodeInjectionGuardrail collected every matched pattern's type
into a list without de-duplication and then blocked when the list had two or more
entries, although the intent (per the inline comment and the sibling
PromptInjectionGuardrail) is to require multiple DIFFERENT types. Because several
patterns share a type (e.g. two TEMPLATE_INJECTION patterns for {{...}} and ${...}),
a single legitimate templating question such as "render {{name}} and ${value}" was
falsely blocked. Only record a type when it is not already present, so the
"multiple types" check counts distinct types.
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Ka4dAcJMpxahMfk3kmG5Ls
Signed-off-by: Andrea Cosentino <ancosen@gmail.com>
Contributor
|
🌟 Thank you for your contribution to the Apache Camel project! 🌟 🐫 Apache Camel Committers, please review the following items:
|
davsclaus
approved these changes
Sep 3, 2026
Contributor
|
🧪 CI tested the following changed modules:
🔬 Scalpel shadow comparison — Scalpel: 10 tested, 27 compile-only — current: 10 all testedMaveniverse Scalpel detected 37 affected modules (current approach: 10).
|
Croway
approved these changes
Sep 3, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Issue
CAMEL-24607
Problem
In non-strict mode
CodeInjectionGuardrail.validate()collects every matched pattern'sInjectionTypeinto a
Listwithout de-duplication, then blocks the input whendetected.size() >= 2. The inlinecomment says the intent is to require "multiple different types", but several patterns share a type
(4 SHELL_COMMAND, 4 SQL_INJECTION, 3 JAVASCRIPT, 2 HTML_XSS, 3 TEMPLATE_INJECTION).
So a single legitimate input matching two patterns of one type is falsely blocked — e.g. a normal
templating question
render {{name}} and ${value}matches both{{...}}and${...}(bothTEMPLATE_INJECTION) and is rejected. The siblingPromptInjectionGuardrailde-duplicates correctly.Fix
Only add a type when it is not already present, so
detected.size() >= 2genuinely means two distincttypes matched.
Testing
testNonStrictModeDoesNotBlockMultipleMatchesOfTheSameTypeasserts the templating example passes;verified it fails against the unpatched code and passes with the fix. All existing
CodeInjectionGuardrailTestcases still pass.mvn -Psourcecheck validategreen.🤖 Generated with Claude Code