-
Notifications
You must be signed in to change notification settings - Fork 462
Fixes for LocalizedString issues #695
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
base: master
Are you sure you want to change the base?
Conversation
Summary of ChangesHello @sven-n, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed! This pull request significantly enhances the project's stability and maintainability by enforcing non-nullable Highlights
🧠 New Feature in Public Preview: You can now enable Memory to help Gemini Code Assist learn from your team's feedback. This makes future code reviews more consistent and personalized to your project's style. Click here to enable Memory in your admin console. Using Gemini Code AssistThe full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips. Invoking Gemini You can request assistance from Gemini at any point by creating a comment using either
Customization To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a Limitations & Feedback Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here. You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension. Footnotes
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Code Review
This pull request introduces several significant changes, including fixing JSON serialization for LocalizedString, making LocalizedString properties non-nullable across various models, and upgrading source generators to use incremental generators due to a Microsoft.CodeAnalysis.CSharp update. A critical finding is a translation injection vulnerability identified in the LocalizedStringField.razor component, where invalid input containing the language separator is applied to the model despite failing validation. Furthermore, the change from nullable to non-nullable LocalizedString and its modified GetTranslation method behavior introduces subtle bugs or inconsistencies, specifically requiring updates to the null-coalescing logic for default messages to handle empty strings and an opportunity to use more robust translation methods.
|
/gemini review |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Code Review
This pull request refactors LocalizedString to be non-nullable and its GetTranslation method to return a nullable string, modernizes source generators to use the incremental generator API, fixes JSON serialization for plugin configurations, and includes database migration. However, a critical security issue was identified in the LocalizedStringField component: validation for the internal separator string is performed but not enforced, allowing for 'Localization Injection' where a user can unauthorizedly modify translations for other languages by crafting a malicious input string. Additionally, minor issues were found where the new nullable return type of GetTranslation could lead to runtime exceptions.
| } | ||
|
|
||
| var message = (configuration.Message?.ToString() ?? PlugInResources.BaseInvasionPlugIn_DefaultStartMessage).Replace("{mapName}", mapName.GetTranslation(player.Culture), StringComparison.InvariantCulture); | ||
| var message = (configuration.Message.GetTranslation(player.Culture) ?? PlugInResources.BaseInvasionPlugIn_DefaultStartMessage).Replace("{mapName}", mapName.GetTranslation(player.Culture), StringComparison.InvariantCulture); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The call to mapName.GetTranslation(player.Culture) can return null after the changes to LocalizedString. This would cause an ArgumentNullException in string.Replace because the second argument cannot be null. You should handle the possible null value, for example by using the null-coalescing operator.
var message = (configuration.Message.GetTranslation(player.Culture) ?? PlugInResources.BaseInvasionPlugIn_DefaultStartMessage).Replace("{mapName}", mapName.GetTranslation(player.Culture) ?? string.Empty, StringComparison.InvariantCulture);|
|
||
| await this.ForEachPlayerAsync(player => player.InvokeViewPlugInAsync<IShowMessagePlugIn>(p => | ||
| message.GetTranslation(player.Culture) is { Length: > 0 } translation | ||
| ? p.ShowMessageAsync(string.Format(translation, args), MessageType.GoldenCenter) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Calling string.Format with an empty args array will throw a FormatException if the translation string contains any format specifiers (e.g., {0}). Some call sites of ShowGoldenMessageAsync pass an empty args array. To make this more robust, you could check if args has any elements before calling string.Format.
? p.ShowMessageAsync(args.Length > 0 ? string.Format(translation, args) : translation, MessageType.GoldenCenter)|
Validation prevents injection of additional localizations. Additionally, the "user" is an admin. |
LocalizedString?toLocalizedStringand adapted all code usagesMicrosoft.CodeAnalysis.CSharpwhich doesn't support the old generators anymore. Otherwise, no new migrations could've been added to the project due to the requirement of a newer version ofMicrosoft.CodeAnalysis.CSharp.Replaces the PR of #694