Skip to content

Harden Visio comments loading to prevent XML DoS#1927

Merged
PrzemyslawKlys merged 2 commits into
masterfrom
fix-unbounded-xml-parsing-in-visio-comments
Jun 16, 2026
Merged

Harden Visio comments loading to prevent XML DoS#1927
PrzemyslawKlys merged 2 commits into
masterfrom
fix-unbounded-xml-parsing-in-visio-comments

Conversation

@PrzemyslawKlys

Copy link
Copy Markdown
Member

Motivation

  • The new Visio comments loader previously materialized an unbounded visio/comments.xml part via XDocument.Load which could exhaust memory/CPU when fed attacker-controlled large or highly compressed XML.
  • The goal is to prevent DoS by bounding decompressed part size, XML character document size, number of comment entries, and per-comment text length while preserving existing functionality.

Description

  • Added size and parsing limits: MaxCommentsPartBytes, MaxCommentsXmlCharacters, MaxLoadedComments, and MaxCommentTextCharacters and a hardened XmlReaderSettings used for comments parsing.
  • Replace direct XDocument.Load(stream) with LoadCommentsXml which reads through a BoundedReadStream and an XmlReader configured with the secure settings to enforce decompressed-byte and XML-character caps.
  • Add runtime checks that cap the number of loaded CommentEntry elements and validate per-comment text length before constructing VisioComment objects, throwing InvalidDataException when limits are exceeded.
  • Add unit tests to OfficeIMO.Tests/Visio.Comments.cs that exercise oversized comments XML, excessive comment entries, and oversized comment text, plus helpers that replace the visio/comments.xml part in a generated VSDX for the tests.

Testing

  • Ran PATH=/tmp/dotnet:$PATH dotnet build OfficeIMO.Visio/OfficeIMO.Visio.csproj -f net8.0 and the project built successfully.
  • Ran PATH=/tmp/dotnet:$PATH dotnet build OfficeIMO.Visio/OfficeIMO.Visio.csproj -f net10.0 --no-restore and -f netstandard2.0 --no-restore and both builds succeeded.
  • Executed the Visio comment tests with PATH=/tmp/dotnet:$PATH dotnet test OfficeIMO.Tests/OfficeIMO.Tests.csproj -f net8.0 --filter FullyQualifiedName~VisioCommentTests and the filtered tests passed (Passed: 7).
  • Also performed a dotnet build of the test project for net10.0 and it completed with no errors (warnings only).

Codex Task

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 48e94a2623

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread OfficeIMO.Visio/VisioDocument.LoadCore.Comments.cs
Comment thread OfficeIMO.Visio/VisioDocument.LoadCore.Comments.cs
Comment thread OfficeIMO.Visio/VisioDocument.LoadCore.Comments.cs
@codecov

codecov Bot commented Jun 16, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 70.00000% with 18 lines in your changes missing coverage. Please review.
✅ Project coverage is 73.33%. Comparing base (0d248cc) to head (7f4b605).
⚠️ Report is 154 commits behind head on master.

Files with missing lines Patch % Lines
OfficeIMO.Visio/VisioDocument.LoadCore.Comments.cs 68.18% 11 Missing and 3 partials ⚠️
OfficeIMO.Visio/VisioDocument.SaveCore.Comments.cs 75.00% 1 Missing and 3 partials ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##           master    #1927      +/-   ##
==========================================
+ Coverage   72.30%   73.33%   +1.03%     
==========================================
  Files        1956     2521     +565     
  Lines      225358   283242   +57884     
  Branches    48654    60594   +11940     
==========================================
+ Hits       162943   207716   +44773     
- Misses      40161    47886    +7725     
- Partials    22254    27640    +5386     

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@PrzemyslawKlys PrzemyslawKlys merged commit e562ded into master Jun 16, 2026
16 checks passed
@PrzemyslawKlys PrzemyslawKlys deleted the fix-unbounded-xml-parsing-in-visio-comments branch June 16, 2026 16:28
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant