Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Bug] System browser process on Linux writes junk to standard out/error #2427

Closed
1 task done
mjcheetham opened this issue Feb 23, 2021 · 5 comments · Fixed by #2507
Closed
1 task done

[Bug] System browser process on Linux writes junk to standard out/error #2427

mjcheetham opened this issue Feb 23, 2021 · 5 comments · Fixed by #2507

Comments

@mjcheetham
Copy link
Contributor

See the original issue: git-ecosystem/git-credential-manager#286

Logs and Network traces

Which Version of MSAL are you using ?
4.3.0

Platform
netcoreapp3.1

What authentication flow has the issue?

  • Desktop / Mobile
    • Interactive - system browser

Is this a new or existing app?
b. The app is in production, I haven't upgraded MSAL, but started seeing this issue

Repro
On Linux, create a new console app, set Chromium set as your default browser and open an existing tab:

var pca = BuildPublicClientApplication();
var result = await pca.AcquireTokenInteractive().ExecuteAsync();

Expected behavior
A new tab is opened to the authentication page; nothing is written to the console.

Actual behavior
Text is written to the console.

Possible Solution
Detach/redirect stdout & err from the child process when launching a browser on Linux.

Additional context/ Logs / Screenshots
The problem appears to be the use of Process.Start when opening the URL on Linux. The .NET Core BCL uses xdg-open (amongst others) to start the new process/default browser, but it does not detach the standard in/out/err streams from the calling process. This means anything written by the browser (e.g., Chromium) or xdg-open will be written to the entry process' streams!

In GCM, who is invoked by Git, we must communicate back to Git over the standard output stream, and this noise is causing issues.

@bgavrilMS bgavrilMS modified the milestones: 4.28.0, 4.29.0 Mar 15, 2021
@pmaytak pmaytak self-assigned this Mar 25, 2021
@pmaytak
Copy link
Contributor

pmaytak commented Mar 26, 2021

Hi @mjcheetham
I made the related changes in PR #2507. Here's a build that includes those changes: Microsoft.Identity.Client.4.29.0-20210325.2.zip. Can you please test if it solves the issue?

I don't know if I was able to repro the exact behavior. I tried on Ubuntu with Chromium. I built my test project for Linux, then ran that executable from the terminal window.

  • When I already had Chromium open, I would get this written to the terminal:
    image
  • When I didn't have the browser open, I would get this in the terminal:
    image

Is the expectation that a new terminal window should be open for that console output? Or is this a different behavior that you're getting?

@mjcheetham
Copy link
Contributor Author

I don't know if I was able to repro the exact behavior. I tried on Ubuntu with Chromium. I built my test project for Linux, then ran that executable from the terminal window.

  • When I already had Chromium open, I would get this written to the terminal:
    image
  • When I didn't have the browser open, I would get this in the terminal:
    image

Is the expectation that a new terminal window should be open for that console output? Or is this a different behavior that you're getting?

The expectation is that there should be nothing written to the standard output or error streams.

When the .NET application (Git Credential Manager in our case) calls Process::Start, on Linux it will fork & execve and the new process (xdg-open and friends) will inherit the stdin/out/err file descriptors. Chromium likes to write a lot of crud to output and error that is being consumed by our calling process (Git).

Redirecting the streams in .NET should cause new streams/file descriptors to be created for xdg-open. The new FDs are not connected to any console (only accessible from the process.StandardOutput/Error property in .NET/MSAL). MSAL can just ignore reading those streams.

Just getting my Linux box ready to test.

@mjcheetham
Copy link
Contributor Author

mjcheetham commented Mar 29, 2021

Hi @pmaytak I've just tried the new package out, and this still does not fix the issue (see my reply on the PR).

If you're looking for a repro, here's the smallest one:

namespace TestApp
{
    class Program
    {
        public static async Task Main(string[] args)
        {
            const string clientId = "872cd9fa-d31f-45e0-9eab-6e460a02d1f1";
            string[] scopes = new { "User.Read" };
            var pca = PublicClientApplicationBuilder.Create(clientId)
                .WithRedirectUri("http://localhost")
                .Build();
            var result = await pca.AcquireTokenInteractive(scopes).ExecuteAsync();
        }
    }
}
<Project Sdk="Microsoft.NET.Sdk">
  <PropertyGroup>
    <OutputType>Exe</OutputType>
    <TargetFramework>net5.0</TargetFramework>
  </PropertyGroup>
  <ItemGroup>
    <PackageReference Include="Microsoft.Identity.Client" Version="4.28.1" />
  </ItemGroup>
</Project>
$ dotnet run

(chrome:21189): Gtk-WARNING **: 13:58:53.285: Theme parsing error gtk.css:1565.23: 'font-feature-settings' is not a valid property name

(chrome:21189): Gtk-WARNING **: 13:58:53.289: Theme parsing error gtk.css:3615.25: 'font-feature-settings' is not a valid property name

(chrome:21189): Gtk-WARNING **: 13:58:53.290: Theme parsing error gtk.css:4077.23: 'font-feature-settings' is not a valid property name
Opening in existing browser session.

☝️ those messages to standard out/error should not be written.

@jennyf19 jennyf19 modified the milestones: 4.29.0, 4.30 Mar 29, 2021
@pmaytak pmaytak added Fixed and removed In Progress labels Mar 31, 2021
@pmaytak
Copy link
Contributor

pmaytak commented Apr 22, 2021

This is included in MSAL 4.30.0 release.

cc: @mjcheetham

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

Successfully merging a pull request may close this issue.

5 participants