Skip to content

[WebView2] WebView2 SourceProperty uses Uri.ToString(): potential Bug source and pre-escaping expectations for consumers missing in Docs #22115

Closed

Description

@DevTKSS

Current behavior 🐛

While working on with adding / updating xml docs on the eventhandlers here:

I noticed WebView2.Properties.cs currently calls Uri.ToString() with the provided Uri to trigger Navigation:

/// <summary>
/// Identifies the Source dependency property.
/// </summary>
public static DependencyProperty SourceProperty { get; } =
DependencyProperty.Register(nameof(Source), typeof(Uri), typeof(WebView2), new FrameworkPropertyMetadata(null,
(s, e) =>
{
var webView = (WebView2)s;
if (!webView._sourceChangeFromCore)
{
webView.CoreWebView2.Navigate(((Uri)e.NewValue)?.ToString());
}
}));

Which redirects to CoreWebView2.cs:

public void Navigate(string uri)
{
if (!Uri.TryCreate(uri, UriKind.Absolute, out var actualUri))
{
throw new ArgumentException("The passed in value is not an absolute URI", nameof(uri));
}
_processedSource = actualUri;
if (_owner.SwitchSourceBeforeNavigating)
{
Source = actualUri.ToString();
}
UpdateFromInternalSource();
}

which could also possibly enhanced, to allow relative Uri instead of failing, by matching to the BaseUri

AND This does also introduce the excact same pitfall as shown in the samples below, in line 69, which even does now parse the Uri again like this.

Some Examples to better understand the potential pitfalls with the current implementation:

Example 1 — path with space encoded as %20

  • Input: new Uri("http://example.com/a%20b")
  • OriginalString: http://example.com/a%20b
  • ToString(): http://example.com/a b <-- potential problem!
  • AbsoluteUri: http://example.com/a%20b

Example 2 — query containing an escaped ampersand %26

  • Input: new Uri("http://example.com/search?q=a%26b")
  • OriginalString: http://example.com/search?q=a%26b
  • ToString(): http://example.com/search?q=a&b <-- and potential problem!
  • AbsoluteUri: http://example.com/search?q=a%26b

Expected behavior 🎯

Recommended behavior for WebView2.Properties.cs:**

  • For network/browser navigation prefer a transport-safe, escaped absolute form: use AbsoluteUri for absolute Uris, and possibly resolve or fail/throw for relative Uris against a defined .BaseUri before calling Navigate.
  • Avoid Uri.ToString() for navigation because it returns a human-readable, partially unescaped form, while the Caller might already have had Escaped and parsed the required Destination Uri beforehand and not expects it do parse it like that / at all

How to reproduce it (as minimally and precisely as possible) 🔬

No response

Workaround 🛠️

No response

Renderer 🎨

  • Skia
  • Native

Affected platforms 📱💻🖥️

No response

Uno.Sdk version (and other relevant versions) 📦

No response

IDE version 🧑‍💻

No response

Anything else we need to know? 💬

Questions and suggestions:

  1. Are we using ToString() here intentional? Maybe then prefer switching to Uri.OriginalString instead, to avoid parsing beyond what the User is maybe expecting to happen
  2. If the intent is to always navigate to transport-safe absolute URLs, should we instead:
  • absolute Uris: check the provided Uri with Uri.IsWellformedOriginalString and call AbsoluteUri if true
  • relative Uris: resolve the provided Uri against the .BaseUri?
  1. Is this behavior covered by tests? If yes, could you please add to the WebView2 Uno Specifics Docs your expectations to the provided Uri for the Consumers for navigation semantics for the escaped / pre-parsed requirements we need to pay attention to and eventual and relative Uri support in the future?

Thanks!

Activity

  1. added
    triage/untriaged
    difficulty/tbd
    on Dec 12, 2025
  2. added theissue type on Dec 12, 2025
  3. Jen-Uno commented on Dec 12, 2025

    @Jen-Uno
    Contributor
  4. removed
    triage/untriaged
    difficulty/tbd
    on Dec 12, 2025
  5. github-actions commented on Apr 30, 2026

    @github-actions
    Contributor

    This issue has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs or feature requests.

  6. locked as resolved and limited conversation to collaborators on Apr 30, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Labels

No labels
No labels

Type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions