Repository navigation
Reject non-ASCII characters in GraphQL name validation - #10389
Merged
Merged
Conversation
Contributor
There was a problem hiding this comment.
🟢 Approval recommended
No unresolved blocking issues were identified.
Pull request overview
Tightens GraphQL name validation to reject non-ASCII characters previously accepted due to unchecked char-to-byte conversion.
Changes:
- Adds direct ASCII validation checks.
- Adds regression tests for validation and sanitization.
File summaries
| File | Description |
|---|---|
src/HotChocolate/Primitives/test/Primitives.Tests/NameUtilsTests.cs |
Adds non-ASCII validation and sanitization tests. |
src/HotChocolate/Primitives/src/Primitives/Utilities/NameUtils.cs |
Corrects GraphQL name validation predicates. |
Review details
- Files reviewed: 2/2 changed files
- Comments generated: 0
- Review effort level: Lite
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
Contributor
Patch coverage100.0% of changed lines covered (2/2)
Project coverage: 57.9% (288295/497915 lines) |
glen-84
added a commit
that referenced
this pull request
Sep 23, 2026
This was referenced Sep 26, 2026
Merged
This was referenced Oct 3, 2026
Open
This was referenced Oct 7, 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.
Summary
NameUtilscompared characters by castingchartobyte. The cast is unchecked, so any code point above U+00FF was truncated to its low byte, and a character whose low byte happens to be an ASCII letter or digit passed as one. U+0141 truncates toA, U+0157 toW, and U+0130 to0.Three public members inherited the hole:
IsValidGraphQLNamereturnedtruefor a name the parser rejects,MakeValidGraphQLNamereturned such a name unchanged, andEnsureGraphQLNameaccepted it instead of throwing.The two
charoverloads now compare the ASCII ranges directly instead of delegating to thebyteoverloads, which are correct as they stand and are what the UTF-8 reader paths use.This is a tightening, so it is worth knowing where it lands.
EnsureGraphQLNameis the validation behind most Fusion and Mutable type definitions and now throws where it used to accept.MakeValidGraphQLNameis whatDefaultNamingConventionsandNameFormattingHelpersuse to derive a GraphQL name from a CLR type or member name, so a CLR identifier carrying such a character previously produced a schema the parser would reject and now sanitizes it to an underscore.Test plan
NameUtilsTestsgains three code points on the existing invalid-name theory, covering a counterfeit letter in the leading position (U+0141), a counterfeit letter mid-name (U+0157), and a counterfeit digit mid-name (U+0130), plus a new theory forMakeValidGraphQLName. All six cases fail before the change.dotnet test src/HotChocolate/Primitives/test/Primitives.Testspasses, 22 tests.EnsureGraphQLNameorMakeValidGraphQLNamepasses: Mutable 123, ApolloFederation 130, Data 1102, and Core 8020.char.IsAsciiLetterOrDigitinstead measured consistently slower, around 15.1 ns.