Changed logic behind identification of special template values#928
Changed logic behind identification of special template values#928michelebastione merged 2 commits intomini-software:masterfrom
Conversation
Changed the logic for identifying special values like `@group` from a Contains check performed on the whole row to an exact match check evaluated on each cell's inner text, thus eliminating the possibility of similar values being misidentified when part of larger text
Summary of ChangesHello, 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 enhances the robustness of template processing by refining how special values are recognized within Excel rows. The change addresses a potential issue where partial matches could lead to incorrect template behavior, ensuring that template directives are interpreted accurately based on exact cell content. 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. Changelog
Activity
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.
Code Review
This pull request refactors the logic for identifying special template values like @group and @header, improving precision by checking individual cell content instead of the entire row. However, a high-severity Template Injection vulnerability has been identified: the new logic processes template commands on cells that may contain user-supplied data, potentially allowing attackers to manipulate Excel generation or cause crashes. It is crucial to separate template command identification from the data-filling process by scanning the original template structure first. Additionally, consider improving the readability of the new switch expression by using a more explicit when clause instead of a C# 11 list pattern.
| string specialCellType = ""; | ||
| foreach (XmlNode c in row.GetElementsByTagName("c")) | ||
| { | ||
| specialCellType = c.InnerText switch | ||
| { | ||
| "@group" => "group", | ||
| "@endgroup" => "endgroup", | ||
| "@merge" or "@endmerge" => "merge", | ||
| ['@','h','e','a','d','e','r', ..] => "header", | ||
| _ => "" | ||
| }; | ||
|
|
||
| if (!string.IsNullOrEmpty(specialCellType)) | ||
| break; | ||
| } |
There was a problem hiding this comment.
This code block is responsible for identifying special template commands. The current implementation, however, processes these commands on cell content after user-provided data has been injected. This introduces a high-severity Template Injection vulnerability, as an attacker could provide data matching command strings (e.g., @group) to manipulate the template's execution logic or cause a denial of service. It is critical to identify commands from the original, unmodified template structure before any data replacement occurs. Furthermore, for improved readability, consider replacing the C# 11 list pattern ['@','h','e','a','d','e','r', ..] with a more explicit when clause using StartsWith().
specialCellType = c.InnerText switch
{
"@group" => "group",
"@endgroup" => "endgroup",
"@merge" or "@endmerge" => "merge",
var s when s.StartsWith("@header") => "header",
_ => ""
};There was a problem hiding this comment.
That's incorrect, data replacement already occurs after commands identification
Fixes #833
Changed the logic for identifying special values like
@groupfrom a Contains check performed on the whole row to an exact match check evaluated on each cell's inner text, thus eliminating the possibility of similar values being misidentified when part of larger text.