Skip to content

Reject raw URI delimiters in OPC part names - #1069

Merged
dtivel merged 5 commits into
mainfrom
dtivel-reject-invalid-opc-delimiters
Sep 14, 2026
Merged

dtivel merged 5 commits into
mainfrom
dtivel-reject-invalid-opc-delimiters

Conversation

@dtivel

@dtivel dtivel commented Sep 13, 2026

Copy link
Copy Markdown
Collaborator

Fixes #998.

Summary

Reject raw # and ? characters in OPC part names before a ZIP entry name is interpreted as a relative package URI. Without this validation, System.Uri treats these characters as fragment and query delimiters, so the signature can reference a different path than the entry whose content was digested.

This change:

  • validates names derived from ZipArchiveEntry.FullName before constructing an OpcPart URI;
  • validates newly created part paths before modifying content types or archive entries;
  • reports the offending part name and delimiter through localized resources;
  • updates the original Reject fragment delimiters in OPC part names #1047 tests from Moq to NSubstitute;
  • creates focused OPC/VSIX ZIP packages dynamically in tests instead of adding binary fixtures;
  • verifies root and nested raw #/? names are rejected, no signature is produced, and package entries remain unchanged;
  • verifies ordinary names still sign successfully; and
  • verifies the limited validator does not mistake percent-encoded %23/%3F text for raw delimiters.

Scope

This is deliberately limited validation, not complete syntactic or semantic OPC part-name validation.

The change follows the rejection approach contributed in #1047 and preserves the original contributor's commits and authorship.

Testing

All discovered solution tests pass: 769 passed, 1 skipped, 0 failed.

This change adds 4 test methods covering 12 test cases.

Guflly and others added 5 commits September 13, 2026 12:50
Reject raw fragment and query delimiters in ZIP entry names before signing while preserving percent-encoded forms in package paths and signature references. Add dynamic OPC package coverage and verify rejected packages remain unchanged.

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Restore the existing URI helper behavior and remove encoded-reference signing assertions so this branch remains limited to rejecting raw OPC URI delimiters. Retain validator-level coverage that percent-encoded delimiters are not rejected.

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Reject decoded raw URI delimiters before CreatePart updates content types or archive entries, preserving package state when validation fails.

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
@dtivel
dtivel requested a review from a team as a code owner September 13, 2026 19:56
@dtivel
dtivel requested a balanced review from Copilot September 13, 2026 19:56

Copilot AI 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.

Copilot review overview

🟢 Approval recommended

The validation occurs before URI interpretation or package mutation and is covered by focused regression tests.

Review tier: Balanced
Findings: None

What changed in this PR

Adds focused validation to prevent malformed OPC signatures caused by raw URI delimiters in ZIP entry names.

Changes:

  • Rejects raw # and ? before constructing or creating OPC parts.
  • Adds localized diagnostics identifying the offending name and delimiter.
  • Adds signing, package-integrity, valid-name, and percent-encoding tests.
File Description
test/​Sign.Core.Test/​Tools/​VSIXSignTool/​OpcPackageTests.cs Tests safe rejection during part creation.
test/​Sign.Core.Test/​Tools/​VSIXSignTool/​OpcPackageSigningTests.cs Tests signing behavior and archive integrity.
src/​Sign.Core/​Tools/​VsixSignTool/​OpcPartNameValidator.cs Implements delimiter validation.
src/​Sign.Core/​Tools/​VsixSignTool/​OpcPart.cs Validates ZIP entry names before URI construction.
src/​Sign.Core/​Tools/​VsixSignTool/​OpcPackage.cs Validates newly created part paths.
src/​Sign.Core/​Resources.resx Adds the validation error resource.
src/​Sign.Core/​Resources.Designer.cs Exposes the generated resource property.
src/​Sign.Core/​xlf/​Resources.cs.xlf Adds Czech localization metadata.
src/​Sign.Core/​xlf/​Resources.de.xlf Adds German localization metadata.
src/​Sign.Core/​xlf/​Resources.es.xlf Adds Spanish localization metadata.
src/​Sign.Core/​xlf/​Resources.fr.xlf Adds French localization metadata.
src/​Sign.Core/​xlf/​Resources.it.xlf Adds Italian localization metadata.
src/​Sign.Core/​xlf/​Resources.ja.xlf Adds Japanese localization metadata.
src/​Sign.Core/​xlf/​Resources.ko.xlf Adds Korean localization metadata.
src/​Sign.Core/​xlf/​Resources.pl.xlf Adds Polish localization metadata.
src/​Sign.Core/​xlf/​Resources.pt-BR.xlf Adds Brazilian Portuguese localization metadata.
src/​Sign.Core/​xlf/​Resources.ru.xlf Adds Russian localization metadata.
src/​Sign.Core/​xlf/​Resources.tr.xlf Adds Turkish localization metadata.
src/​Sign.Core/​xlf/​Resources.zh-Hans.xlf Adds Simplified Chinese localization metadata.
src/​Sign.Core/​xlf/​Resources.zh-Hant.xlf Adds Traditional Chinese localization metadata.
Files not reviewed (1)
  • src/Sign.Core/Resources.Designer.cs: Generated file

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Octothorpe symbol (#) in OPC part names is not handled properly

4 participants