Skip to content

Changed logic behind identification of special template values#928

Merged
michelebastione merged 2 commits intomini-software:masterfrom
michelebastione:issue-833
Feb 26, 2026
Merged

Changed logic behind identification of special template values#928
michelebastione merged 2 commits intomini-software:masterfrom
michelebastione:issue-833

Conversation

@michelebastione
Copy link
Contributor

Fixes #833

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.

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
@gemini-code-assist
Copy link
Contributor

Summary of Changes

Hello, 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

  • Template Special Value Identification: Refactored the logic for identifying special template values (e.g., "@group", "@Header") from a broad "Contains" check on the entire row's inner text to a precise "switch" expression that examines the "InnerText" of individual cells.
  • Eliminated False Positives: Ensured that special values are now identified only when they are exact matches within a cell, preventing misidentification when similar text is part of a larger string.

🧠 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
  • src/MiniExcel.OpenXml/Templates/OpenXmlTemplate.Impl.cs
    • Updated the method for identifying special template values by iterating through individual cells instead of checking the entire row's inner text.
    • Replaced "Contains" checks with a "switch" expression for exact matching of "@group", "@endgroup", "@merge", and "@Header" directives.
    • Corrected a minor formatting inconsistency in the "cellIEnumerableValues" assignment.
Activity
  • No human activity (comments, reviews, etc.) has been recorded for this pull request yet.
Using Gemini Code Assist

The 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 /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

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 .gemini/ folder in the base of the repository. Detailed instructions can be found here.

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

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

Copy link
Contributor

@gemini-code-assist gemini-code-assist bot left a 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 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.

Comment on lines +380 to +394
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;
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

security-high high

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",
                    _ => ""
                };

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's incorrect, data replacement already occurs after commands identification

@michelebastione michelebastione merged commit 802c08b into mini-software:master Feb 26, 2026
3 checks passed
@michelebastione michelebastione deleted the issue-833 branch February 26, 2026 23:11
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

1 participant