Skip to content

Fix potential issues in WPF Native Code - #12033

Merged
himgoyalmicro merged 6 commits into
mainfrom
user/himgoyal/fixing_code
Oct 14, 2026
Merged

himgoyalmicro merged 6 commits into
mainfrom
user/himgoyal/fixing_code

Conversation

@himgoyalmicro

@himgoyalmicro himgoyalmicro commented Oct 14, 2026 •

Copy link
Copy Markdown
Contributor

Fixes #12016
Fixes #12017
Fixes #12018
Fixes #12019
Fixes #12020
Fixes #12021
Fixes #12022
Fixes #12023
Fixes #12024
Fixes #12025
Fixes #12026

Description

Fix potential issues in WPF Native Code

Microsoft Reviewers: Open in CodeFlow

himgoyalmicro and others added 6 commits October 14, 2026 10:21
…erlink navigation security fixes

- **Restrictive XAML:** block untrusted URI fetches and unsafe navigation targets in RestrictiveXamlXmlReader, WpfXamlLoader, XamlReader (new RestrictiveXamlContext helper for IsUnsafe taint tracking).
- **Hyperlink navigation:** propagate IsUnsafe taint through NavigationService to prevent bypass of restrictive XAML checks via hyperlink navigation.
- **XPS package integrity:** enforce full element/prefix coverage and cryptographic Signature@Id binding in XpsDigitalSignature, XpsFixedDocumentReaderWriter, XpsFixedDocumentSequenceReaderWriter (new ReachAppContextSwitches for compat opt-outs).
- **TrueType subsetter:** add font security protection switch (g_fFontSecurityProtectionEnabled) honored in truetype.h.
- **XamlPullParser:** add a nesting-depth guard to prevent unbounded recursion.
- **DefaultCredentialsZonePolicy:** stop caching positive DNS resolution decisions.
- **New AppContext compatibility switches** (default off = secure):
  Switch.System.Windows.Markup.OptOutOfRestrictiveXamlUriBlock,
  Switch.System.Windows.Markup.OptOutOfNavigationTypeRestrictiveXamlBlock,
  Switch.System.Windows.Xps.OptOutOfPageSignatureCoverageEnforcement,
  Switch.System.Windows.Xps.OptOutOfSignatureIdBindingVerification,
  Switch.MS.Internal.TtfDelta.DisableFontSecurityProtection.

----
Security hardening release addressing multiple vulnerabilities in XAML/XPS processing, hyperlink navigation, credential leakage via DNS rebinding, and font parsing.

This PR implements comprehensive security fixes for WPF 9.0, addressing critical vulnerabilities in restrictive XAML loading, XPS digital signature validation, hyperlink navigation security, DNS rebinding attacks, and font subsetting buffer overflows.

- `DefaultCredentialsZonePolicy.cs`: Implements fail-closed DNS result caching (negative results only) with TTL expiration to prevent credential leakage from DNS rebinding attacks
- `NavigationService.cs`: Expands restrictive XAML reader enforcement to all XPS-originated navigation and navigation from restrictively-loaded content via logical tree traversal
- `XpsDigitalSignature.cs`: Adds cryptographic binding verification for Signature@Id to prevent signature spoofing attacks, with new opt-out switch
- `RestrictiveXamlXmlReader.cs`: Blocks non-pack absolute URIs and UNC paths on Uri/ImageSource properties to prevent external resource fetching from untrusted XAML
- `modcmap.cpp` and `mtxcalc.cpp`: Fixes heap buffer over-read vulnerabilities in TrueType cmap Format 6 processing and composite glyph parsing with bounds validation
<!-- GitOpsUserAgent=GitOps.Apps.Server.pullrequestcopilot -->
…Trans::Initialize

Backport of the .NET 8.0 pixel-shader memory-safety fix (PR 63617, MSRC 127649 + MSRC 130198) to release/9.0. Guards pass-1/pass-2 disagreement in DEF/DEFI/DEFB and DCL handling and bounds the parameter-token skip loop in CPSTrans::Initialize, all gated behind WpfGfxSwitches::IsWpfGfxBoundsCheckProtectionDisabled().

----
#### AI description  (iteration 1)
#### PR Classification
Security bug fix to prevent out-of-bounds (OOB) read and write vulnerabilities in the pixel shader translation code.

#### PR Summary
This PR addresses security vulnerabilities (MSRC 127649, MSRC 130198) by adding bounds checking throughout the pixel shader bytecode parsing in `CPSTrans::Initialize` to prevent buffer overruns during instruction array construction and token stream processing.

- Added bounds checks in the second pass to prevent instruction array overruns and ensure room for the END record
- Fixed parameter token loop to validate against bytecode buffer end, preventing OOB reads when token stream lacks D3DPS_END terminator
- Fixed `D3DSIO_DCL` instruction handling to always consume register tokens, ensuring first and second pass synchronization
- Added default cases for constant definition instructions (`D3DSIO_DEF`, `D3DSIO_DEFI`, `D3DSIO_DEFB`) to advance token pointer consistently between passes, preventing allocation mismatches
<!-- GitOpsUserAgent=GitOps.Apps.Server.pullrequestcopilot -->
…CD3DGlyphBank::RectFillAlpha (MSRC 31000000667690)

Fix destination-side integer overflow in CD3DGlyphBank::RectFillAlpha (MSRC 31000000667690)

The hardware glyph-bank copy computed its destination row pointers using 32-bit `lockedRect.Pitch * coordinate` products. Attacker-controlled XPS Glyphs coordinates can drive `srcRect.top` / `y` into the millions, so the product exceeds INT32 range and wraps; after sign extension the destination pointer lands ~4 GiB away from the locked temporary surface. The following memset/memcpy then writes out of bounds, terminating the WPF renderer process with 0xC0000005 (denial of service).

PR #11642 previously widened only the source-side products to INT64 and left the destination-side products at 32-bit. This change widens every destination `lockedRect.Pitch` product to INT64 - the `pDst00` base plus all four row loops (top edge, real data, degenerate, bottom edge) - gated behind the same WpfGfxSwitches::IsWpfGfxBoundsCheckProtectionDisabled() kill-switch used for the source side, so both halves revert together when
the mitigation is disabled.

Co-authored-by: Copilot

----
#### AI description  (iteration 1)
#### PR Classification
Security bug fix addressing an integer overflow vulnerability in glyph rendering code that could lead to out-of-bounds memory writes.

#### PR Summary
This PR fixes a critical integer overflow vulnerability in the CD3DGlyphBank::RectFillAlpha function where attacker-controlled glyph coordinates could cause pointer arithmetic to wrap past INT32 range, resulting in out-of-bounds memory writes.

- `d3dglyphbank.cpp`: Added bounds checking validation to verify the destination byte range stays within the locked temporary surface before writing
- `d3dglyphbank.cpp`: Converted pointer arithmetic from 32-bit to 64-bit integers (INT64) for all `lockedRect.Pitch * y` calculations to prevent overflow when computing destination row pointers
- `d3dglyphbank.cpp`: Implemented configurable protection via `WpfGfxSwitches::IsWpfGfxBoundsCheckProtectionDisabled()` to allow disabling the fix if needed while preserving legacy behavior
<!-- GitOpsUserAgent=GitOps.Apps.Server.pullrequestcopilot -->
…k:// package identities

## Summary
Fixes a regression introduced by the August 2026 XPS same-package boundary enforcement (#11835). Unchanged WPF apps that register an in-memory XPS package in `PackageStore`/`XpsDocument` using a `pack://` scheme identity crash when reading the document - same-package images and fonts are wrongly rejected as "outside the current XPS package".

## Root cause
`XpsLoadingContext.IsSamePackageUri` normalizes the origin package identity via `PackUriHelper.GetPackageUri(packageOrigin)`. That method's behavior depends on the identity's scheme:

- Non-`pack` schemes (e.g. `xpspack://`) -> throws `ArgumentException` ("URI must contain pack:// scheme"), which the inner `catch` handled by falling back to comparing the identity as-is.
- The `pack://` scheme -> `GetPackageUri` reaches `new Uri(...)` on the unescaped authority (`memorystream.xps`), and the underlying `System.Uri` constructor throws **`UriFormatException`**, which was **not** caught.

The uncaught `UriFormatException` escaped to the method's outer catch, which returns `false` (fail-closed). Every same-package resource then threw `FileFormatException(Resource_XpsPackageBoundaryViolation)`, terminating the process with an unhandled exception.

## Fix
Broaden the origin-normalization fallback to also catch `UriFormatException` and `InvalidOperationException`, matching the exception set the method's outer catch already anticipates. A `pack://` identity now falls back to identity comparison exactly like the working `xpspack://` path.

Security is unchanged: the widened handling applies only to parsing the **origin** (the trusted package the host app opened). The **resource** URI path is untouched - scheme must be `pack`, `application:`/`siteoforigin:` authorities are rejected, and the resource's package must still `.Equals` the origin package. External (`http`/`https`/`file`/UNC) and cross-package references remain blocked.

## Testing
Verified end-to-end on locally built WPF bits using the DTS repro (in-memory XPS with one image), before/after the change:

| Build | Result |
|-------|--------|
| Unpatched | Crash `0xE0434352`, `FileFormatException` (boundary violation) |
| Patched   | `Completed successfully. Pages: 1`, exit 0 |

Also confirmed the boundary still holds after the fix:
- same-package `pack://` -> allowed
- same-package `xpspack://` -> allowed
- external `http://` -> blocked
- cross-package `pack://` -> blocked

Reproduced on .NET Framework 3.5/4.7.2/4.8/4.8.1 and .NET 8 / 9 / 10.

----
#### AI description  (iteration 1)
#### PR Classification
Bug fix to resolve a regression in XPS package-boundary enforcement that caused print preview failures when XPS documents used bare `pack://` URIs as PackageStore identities.

#### PR Summary
Fixes a security boundary check that incorrectly rejected same-package XPS resources when the package identity used a bare `pack://` scheme, causing unhandled exceptions during print preview. The fix adds additional exception handlers to properly ...
@himgoyalmicro
himgoyalmicro requested review from a team and a balanced review from Copilot October 14, 2026 05:21
@himgoyalmicro
himgoyalmicro requested a review from a team as a code owner October 14, 2026 05:21
@dotnet-policy-service dotnet-policy-service Bot added the PR metadata: Label to tag PRs, to facilitate with triage label Oct 14, 2026

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🟡 Changes recommended

Bounds validation remains incomplete and restrictive XAML still permits package authorities outside the active XPS package.

5 open findings
What changed in this PR

Hardens WPF native rendering, font processing, XAML/XPS loading, navigation, signatures, and credential-zone decisions against multiple security vulnerabilities.

Changes:

  • Adds bounds, recursion-depth, URI, navigation, and package-boundary protections.
  • Strengthens XPS signature validation and DNS decision caching.
  • Adds compatibility switches and targeted regression tests.
File Description
XpsLoadingContextTests.cs Tests XPS package-boundary enforcement.
DefaultCredentialsZonePolicyTests.cs Updates credential-cache tests.
d3dglyphbank.cpp Hardens glyph destination arithmetic.
pstrans.cpp Adds shader-bytecode bounds checks.
XamlPullParser.cs Limits XAML nesting depth.
XamlAppContextSwitches.cs Adds nesting-guard opt-out.
ReachFramework.csproj Includes Reach security switches.
XpsFixedDocumentSequenceReaderWriter.cs Validates document-reference namespaces.
XpsFixedDocumentReaderWriter.cs Validates page-content namespaces.
XpsDigitalSignature.cs Verifies signature-ID binding.
ReachAppContextSwitches.cs Defines XPS compatibility switches.
NavigationService.cs Propagates restrictive navigation state.
XamlReader.cs Marks restrictively loaded objects.
WpfXamlLoader.cs Marks restrictive-loader output.
RestrictiveXamlXmlReader.cs Blocks unsafe types and URI fetches.
RestrictiveXamlContext.cs Stores restrictive-load state.
PageContent.cs Handles stripped unsafe page content.
PresentationFramework.csproj Includes restrictive context source.
FrameworkAppContextSwitches.cs Adds XAML security opt-outs.
AppContextDefaultValues.cs Enables font protection by default.
XpsLoadingContext.cs Handles additional package URI failures.
CoreAppContextSwitches.cs Defines font-security switch.
DefaultCredentialsZonePolicy.cs Revises DNS decision caching.
main.cpp Initializes native font protection.
ttftable.cpp Guards composite glyphs and cmap reads.
ttf_safe_checks.h Defines font-security checks.
mtxcalc.cpp Propagates composite-glyph errors.
modcmap.cpp Corrects format-6 cmap offsets.
makeglst.cpp Handles invalid composite glyphs.
truetype.h Minor header formatting update.
truetype.cpp Initializes the font-security switch.

🧠 Review effort: Balanced


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

@himgoyalmicro
himgoyalmicro merged commit 65d15ad into main Oct 14, 2026
9 checks passed
@himgoyalmicro
himgoyalmicro deleted the user/himgoyal/fixing_code branch October 14, 2026 07:02
@dotnet-milestone-bot dotnet-milestone-bot Bot added this to the 12.0-preview1 milestone Oct 20, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

PR metadata: Label to tag PRs, to facilitate with triage

Projects

None yet

7 participants