fix(drizzle): allow unicode characters in JSON query values#3
Merged
Conversation
The SAFE_STRING_REGEX was using \w which only matches ASCII characters,
blocking any non-ASCII characters (CJK, accented Latin, emoji, etc.) in
JSON field queries.
Changed to use \p{L} (Unicode letter) and \p{N} (Unicode number) with
the /u flag, which allows international text while still blocking SQL
metacharacters (' , ; -- ( ) = / \ etc.).
Fixes: payloadcms#16401
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.
Description
The SAFE_STRING_REGEX was using \w which only matches ASCII characters ([A-Za-z0-9_]), blocking any non-ASCII characters (CJK, accented Latin, emoji, etc.) in JSON field queries.
Fix
Changed to use \p{L} (Unicode letter) and \p{N} (Unicode number) with the /u flag, which allows international text while still blocking SQL metacharacters (' , ; -- ( ) = / \ etc.).
Testing
This fix allows JSON field queries with:
While still blocking SQL injection attempts.
Fixes: payloadcms#16401
Summary by cubic
Fix JSON field queries to accept Unicode text by updating the safe string regex in
drizzle, while keeping SQL injection protections intact. Fixes payloadcms#16401./^[\p{L}\p{N}\s @.\-+:_]*$/u(replacing\w) to allow CJK, accents, and emoji while blocking SQL metacharacters.Written for commit 83e8c42. Summary will update on new commits. Review in cubic