Repository navigation
fix(filters): return 412 for filter values with invalid UTF-8 or emoji #646
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
romanetar
wants to merge
5
commits into
main
Choose a base branch
from
fix/filter-parser-invalid-utf8
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+351
−90
Open
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
627d8fe
test(filters): add FilterParser encoding regression tests and run the…
romanetar 062093a
test(filters): cover invalid UTF-8 and emoji filters on members, atte…
romanetar f51fe65
fix(filters): reject invalid UTF-8 and non-BMP characters in FilterPa…
romanetar 4a7ca6c
fix(attendees): parse the filter inside processRequest so filter erro…
romanetar d088ab8
fix(filters): validate the raw filter as UTF-8 before the and()/or() …
romanetar File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
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
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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,105 @@ | ||
| <?php namespace Tests; | ||
| /** | ||
| * Copyright 2026 OpenStack Foundation | ||
| * Licensed under the Apache License, Version 2.0 (the "License"); | ||
| * you may not use this file except in compliance with the License. | ||
| * You may obtain a copy of the License at | ||
| * http://www.apache.org/licenses/LICENSE-2.0 | ||
| * Unless required by applicable law or agreed to in writing, software | ||
| * distributed under the License is distributed on an "AS IS" BASIS, | ||
| * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| * See the License for the specific language governing permissions and | ||
| * limitations under the License. | ||
| **/ | ||
|
|
||
| use utils\FilterParser; | ||
| use utils\FilterParserException; | ||
|
|
||
| /** | ||
| * Class FilterParserEncodingTest | ||
| * | ||
| * FilterParser urldecodes each value a second time on purpose (a literal + travels as %2B, | ||
| * which the HTTP client encodes again as %252B). The expressions below are written the way | ||
| * PHP hands them over after its own decode of the query string: title=@%25DA on the wire | ||
| * arrives as title=@%DA, and filter=%DA==x arrives as the raw byte 0xDA followed by ==x. | ||
| * Input that is not valid UTF-8, or that has characters outside the BMP, can never be compared | ||
| * against our utf8mb3/latin1 columns (MySQL 1267), so it must be rejected before any query runs. | ||
| */ | ||
| final class FilterParserEncodingTest extends TestCase | ||
| { | ||
| private const RULES = [ | ||
| 'title' => ['=@', '=='], | ||
| 'first_name' => ['=@', '=='], | ||
| ]; | ||
|
|
||
| private static function parseValue(string $expression): string | ||
| { | ||
| $filter = FilterParser::parse($expression, self::RULES); | ||
| $elements = $filter->getFilter('title'); | ||
| return $elements[0]->getValue(); | ||
| } | ||
|
|
||
| public function testEncodedPlusIsKept(): void | ||
| { | ||
| $this->assertSame('C++', self::parseValue('title==C%2B%2B')); | ||
| } | ||
|
|
||
| public function testNonAsciiBmpTextIsKept(): void | ||
| { | ||
| $this->assertSame('José', self::parseValue('title==Jos%C3%A9')); | ||
| $this->assertSame('€', self::parseValue('title==%E2%82%AC')); | ||
| $this->assertSame('日本', self::parseValue('title==%E6%97%A5%E6%9C%AC')); | ||
| } | ||
|
|
||
| public function testInvalidUtf8ValueIsRejected(): void | ||
| { | ||
| $this->expectException(FilterParserException::class); | ||
| FilterParser::parse('title=@%DA', self::RULES); | ||
| } | ||
|
|
||
| public function testInvalidUtf8ValueIsRejectedWithEqualOperator(): void | ||
| { | ||
| $this->expectException(FilterParserException::class); | ||
| FilterParser::parse('title==%CA', self::RULES); | ||
| } | ||
|
|
||
| public function testEmojiValueIsRejected(): void | ||
| { | ||
| $this->expectException(FilterParserException::class); | ||
| FilterParser::parse('title=@' . "\u{1F600}", self::RULES); | ||
| } | ||
|
|
||
| public function testEncodedEmojiValueIsRejected(): void | ||
| { | ||
| $this->expectException(FilterParserException::class); | ||
| FilterParser::parse('title=@%F0%9F%98%80', self::RULES); | ||
| } | ||
|
|
||
| public function testInvalidUtf8FieldIsRejectedWithSafeMessage(): void | ||
| { | ||
| try { | ||
| FilterParser::parse("\xDA==x", self::RULES); | ||
| $this->fail('FilterParserException expected'); | ||
| } catch (FilterParserException $ex) { | ||
| $this->assertNotFalse(json_encode(['message' => $ex->getMessage()])); | ||
| } | ||
| } | ||
|
|
||
| public function testInvalidUtf8ExpressionWithoutOperatorIsRejectedWithSafeMessage(): void | ||
| { | ||
| try { | ||
| FilterParser::parse("\xDA", self::RULES); | ||
| $this->fail('FilterParserException expected'); | ||
| } catch (FilterParserException $ex) { | ||
| $this->assertNotFalse(json_encode(['message' => $ex->getMessage()])); | ||
| } | ||
| } | ||
|
|
||
| public function testInvalidUtf8OutsideMainOperatorWrapperIsRejected(): void | ||
| { | ||
| // the and(...) wrapper regex is not end-anchored, so the trailing byte is not part of | ||
| // the expression that filterExpresion validates | ||
| $this->expectException(FilterParserException::class); | ||
| FilterParser::parse("and(title==ok)\xDA", self::RULES); | ||
| } | ||
| } |
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
Oops, something went wrong.
Oops, something went wrong.
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.
Uh oh!
There was an error while loading. Please reload this page.