fix(mapper): escape LIKE wildcards and chunk oversized IN clauses - #208
Open
shihyuho wants to merge 2 commits into
Open
fix(mapper): escape LIKE wildcards and chunk oversized IN clauses#208shihyuho wants to merge 2 commits into
shihyuho wants to merge 2 commits into
Conversation
Values passed to Like, NotLike, StartingWith and EndingWith were concatenated into the LIKE pattern verbatim, so a submitted % or _ kept its wildcard meaning: a bare % through a StartingWith-mapped scoping filter matched every row. Escape the backslash, % and _ via the new LikePattern helper and declare the escape character on the predicate. In/NotIn expanded the whole user collection into a single IN clause; collections larger than In.MAX_CHUNK_SIZE (1000) are now partitioned into OR-combined chunks. Co-authored-by: Claude Opus 4.8 (1M context) <[email protected]>
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.
Closes #194
What changed
SEC-01 — LIKE-family wildcard leakage
Like,NotLike,StartingWithandEndingWithconcatenated the user value straight into theLIKEpattern, so a submitted%or_kept its wildcard meaning. A bare%through aStartingWith-mapped scoping filter (e.g. a tenant/department prefix) producedlike '%%'andmatched every row — a scoping bypass. Values are bound parameters, so this is wildcard-semantics
leakage, not SQL injection.
LikePatternhelper in thedomainpackage: escapes\,%and_in a single pass (theescape character itself is handled first by construction, so no double-escaping), and exposes
LikePattern.ESCAPE_CHAR(\).overloads
builder.like(expr, pattern, '\\')/builder.notLike(expr, pattern, '\\').MAINT-03 — unbounded
INexpansionInexpanded the entire user collection into oneIN (...)list; several RDBMS cap the elementcount (commonly 1000) and huge lists degrade the query plan.
In.MAX_CHUNK_SIZE = 1000(documented, maintainer-tunable per target RDBMS).INpredicates.Collections at or below it take the previous single-predicate path, so the common case and the
empty-collection case are unchanged.
NotIninherits this and negates the OR-combined chunks as a whole, which is the correctDe Morgan equivalent of
NOT IN (all).Release note (behavior change)
Consumers who deliberately passed raw
%or_through LIKE-family fields lose that(undocumented) behavior. From this release, values bound to
Like,NotLike,StartingWithandEndingWithare matched literally — wildcards in the value are escaped. Callers that relied onuser- or code-supplied wildcards reaching the database must now build the pattern with their own
specification.
Verification
SpecMapper.toSpec:LikeTest.wildcardsMatchLiterally— values containing%,_and\each match only theirliteral row.
StartingWithTest.wildcardsMatchLiterally— the reported prefix-scope bypass: a bare%nowmatches only the row that literally starts with
%, not every row.EndingWithTest.wildcardsMatchLiterally,NotLikeTest.wildcardsMatchLiterally.InTest.moreValuesThanChunkSize/NotInTest.moreValuesThanChunkSize— 1001 values (2 chunks)build valid SQL and return the correct rows.
wildcardsMatchLiterallytests fail — they genuinely pin the fix.make testgreen on both modules (JDK 17, the project's declared target).Not done
mapper/src/main/.../domain/andmapper/src/test/— the site docs undersite/content/**that describe the LIKE-family specs are left to the maintainer / release notes.IgnoreCase) siblings exist in this family, so nothing further to escape.default the maintainer may tune, not a new config surface.
🤖 Generated with Claude Code