Skip to content

MediaPlayer cannot play back audio files from secure HTTPS sources #722

Closed

Description

@dotMorten
  • .NET Core Version: 3.0.0-preview6-27720-09
  • Windows version: (winver) 1903
  • Does the bug reproduce also in WPF for .NET Framework 4.8?: Yes

Problem description:
When pointing to a https source on MediaPlayer, you'll get a NullReferenceException. This doesn't occur with http.
However this doesn't happen in click-once deployments, because that's what it uses to check if the secure connection is used or not, but since most scenarios aren't click-once this fails because
null is returned.

It's clear the code here never assumed this wouldn't be used in a click-once scenario (appDeploymentUri us null so crashes on line 987):

// access is allowed in the following cases (only 1 & 2 require elevation):
// 1) to any HTTPS media if app is NOT coming from HTTPS
// 2) to URI in the current directory of the fusion cache
// 3) to site of origin media
if (SecurityHelper.AreStringTypesEqual(uriToOpen.Scheme, Uri.UriSchemeHttps))
{
// target is HTTPS. Then, elevate ONLY if we are NOT coming from HTTPS (=XDomain HTTPS app to HTTPS media disallowed)
Uri appDeploymentUri = SecurityHelper.ExtractUriForClickOnceDeployedApp();
if (!SecurityHelper.AreStringTypesEqual(appDeploymentUri.Scheme, Uri.UriSchemeHttps))
{
new WebPermission(NetworkAccess.Connect, BindUriHelper.UriToString(uriToOpen)).Assert();
elevated = true;
}
}

Actual behavior:
image

StackTrace: ``` at System.Windows.Media.MediaPlayerState.OpenMedia(Uri source) at System.Windows.Media.MediaPlayerState.SetSource(Uri source) at System.Windows.Media.MediaPlayerState.Open(Uri source) at System.Windows.Media.MediaPlayer.Open(Uri source) at test.MainWindow.Button_Click(Object sender, RoutedEventArgs e) in e:\GitHub\dotnet\test\MainWindow.xaml.cs:line 33 at System.Windows.EventRoute.InvokeHandlersImpl(Object source, RoutedEventArgs args, Boolean reRaised) at System.Windows.UIElement.RaiseEventImpl(DependencyObject sender, RoutedEventArgs args) at System.Windows.UIElement.RaiseEvent(RoutedEventArgs e) at System.Windows.Controls.Primitives.ButtonBase.OnClick() at System.Windows.Controls.Button.OnClick() at System.Windows.Controls.Primitives.ButtonBase.OnMouseLeftButtonUp(MouseButtonEventArgs e) at System.Windows.UIElement.OnMouseLeftButtonUpThunk(Object sender, MouseButtonEventArgs e) at System.Windows.Input.MouseButtonEventArgs.InvokeEventHandler(Delegate genericHandler, Object genericTarget) at System.Windows.RoutedEventArgs.InvokeHandler(Delegate handler, Object target) at System.Windows.EventRoute.InvokeHandlersImpl(Object source, RoutedEventArgs args, Boolean reRaised) at System.Windows.UIElement.ReRaiseEventAs(DependencyObject sender, RoutedEventArgs args, RoutedEvent newEvent) at System.Windows.UIElement.OnMouseUpThunk(Object sender, MouseButtonEventArgs e) at System.Windows.Input.MouseButtonEventArgs.InvokeEventHandler(Delegate genericHandler, Object genericTarget) at System.Windows.RoutedEventArgs.InvokeHandler(Delegate handler, Object target) at System.Windows.EventRoute.InvokeHandlersImpl(Object source, RoutedEventArgs args, Boolean reRaised) at System.Windows.UIElement.RaiseEventImpl(DependencyObject sender, RoutedEventArgs args) at System.Windows.UIElement.RaiseTrustedEvent(RoutedEventArgs args) at System.Windows.Input.InputManager.ProcessStagingArea() at System.Windows.Input.InputProviderSite.ReportInput(InputReport inputReport) at System.Windows.Interop.HwndMouseInputProvider.ReportInput(IntPtr hwnd, InputMode mode, Int32 timestamp, RawMouseActions actions, Int32 x, Int32 y, Int32 wheel) at System.Windows.Interop.HwndMouseInputProvider.FilterMessage(IntPtr hwnd, WindowMessage msg, IntPtr wParam, IntPtr lParam, Boolean& handled) at System.Windows.Interop.HwndSource.InputFilterMessage(IntPtr hwnd, Int32 msg, IntPtr wParam, IntPtr lParam, Boolean& handled) at MS.Win32.HwndWrapper.WndProc(IntPtr hwnd, Int32 msg, IntPtr wParam, IntPtr lParam, Boolean& handled) at MS.Win32.HwndSubclass.DispatcherCallbackOperation(Object o) at System.Windows.Threading.ExceptionWrapper.InternalRealCall(Delegate callback, Object args, Int32 numArgs) at System.Windows.Threading.ExceptionWrapper.TryCatchWhen(Object source, Delegate callback, Object args, Int32 numArgs, Delegate catchHandler) at System.Windows.Threading.Dispatcher.LegacyInvokeImpl(DispatcherPriority priority, TimeSpan timeout, Delegate method, Object args, Int32 numArgs) at MS.Win32.HwndSubclass.SubclassWndProc(IntPtr hwnd, Int32 msg, IntPtr wParam, IntPtr lParam) at MS.Win32.UnsafeNativeMethods.DispatchMessage(MSG& msg) at System.Windows.Threading.Dispatcher.PushFrameImpl(DispatcherFrame frame) at System.Windows.Threading.Dispatcher.PushFrame(DispatcherFrame frame) at System.Windows.Threading.Dispatcher.Run() at System.Windows.Application.RunDispatcher(Object ignore) at System.Windows.Application.RunInternal(Window window) at System.Windows.Application.Run(Window window) at System.Windows.Application.Run() at test.App.Main() ```

Expected behavior:
Audio plays

Minimal repro:

MediaPlayer player = new MediaPlayer();
player.Open(new Uri("https://www.thesoundarchive.com/email/youGotmail.wav"));

Remove "s" from https, and the audio will play fine.

Activity

  1. added this to the Future milestone on May 24, 2019
  2. jviolas commented on Jun 20, 2019

    @jviolas

    It's not only audio files, it's true for video too. And it's the same with System.Windows.Controls.MediaElement control.
    This crashes has been around for years in WPF...

  3. stevenbrix commented on Jun 22, 2019

    @stevenbrix
    Contributor

    @grubioe i don't recall the discussion we had around this one, but i'm wondering if we should revisit our previous decision and consider fixing this for 3.0? it seems a little backwards that we are forcing http connections instead of https

  4. stevenbrix commented on Jun 22, 2019

    @stevenbrix
    Contributor

    However this doesn't happen in click-once deployments, because that's what it uses to check if the secure connection is used or not, but since most scenarios aren't click-once this fails because
    null is returned.

    This may sound like a naive question, but do most apps use their own deployment mechanism? If so, why would they not use ClickOnce? Does you know if this repros when using MSIX? We should probably review any code that makes assumptions about ClickOnce and see if they still hold true with MSIX.

  5. removed this from the Future milestone on Jun 23, 2019
  6. weltkante commented on Jun 24, 2019

    @weltkante

    This may sound like a naive question, but do most apps use their own deployment mechanism?

    As far as I know most people are either using MSIX directly or 3rd party installers (usually based on MSIX). I rarely see ClickOnce, probably because its not very flexible when you have applications which are more than a single exe + dll bundle (like having optional installable features, start menu integration, registry keys, multiple exe files, etc.)

  7. dotMorten commented on Jun 24, 2019

    @dotMorten
    ContributorAuthor

    PR linked above also fixes this issue, so this issue should soon (finally) be taken care off

  8. dotMorten commented on Jun 27, 2019

    @dotMorten
    ContributorAuthor

    Pulled latest code in master and tried out #969. I can confirm this fixes this issue.

  9. eFloh commented on Jan 11, 2022

    @eFloh

    this is still open in .NET 4.8, fixed only in .NET Core.

  10. vishalmsft commented on Jan 13, 2022

    @vishalmsft
    Contributor

    @eFloh This is not planned to be taken in 4.8. Thank you for bringing this up.

  11. ghost locked as resolved and limited conversation to collaborators on Apr 17, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions