Skip to content

Don't log action and page handler arguments above Trace level #9227

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

Merged
merged 6 commits into from
Apr 15, 2019

Conversation

pranavkm
Copy link
Contributor

@pranavkm pranavkm commented Apr 9, 2019

Fixes #9121

Impact

The contract for logging says any sensitive information would be logged at LogLevel.Trace. However, MVC logs some user inputs which could contain potentially sensitive information at LogLevel.Info

Workaround
Workaround is to disable Info logging for Mvc.

Risk
This should be fairly low risk. Logging MVC is disabled in production applications.

@pranavkm pranavkm requested a review from dougbu April 9, 2019 23:21
Copy link
Contributor

@dougbu dougbu left a comment

Choose a reason for hiding this comment

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

Which milestone is this PR intended for? Doesn't look like an approval process has begun.

@poke
Copy link
Contributor

poke commented Apr 10, 2019

As per #9121, can we please keep logging the action arguments, but just use a different log level that allows us to include possibly sensitive information? So Debug or Trace? Having this information available by default is very valuable.

@pranavkm
Copy link
Contributor Author

@poke sure. I can log it as a separate log message at debug level. I do want to keep the log level for the current action executing \ page executing unchanged at Info.

@poke
Copy link
Contributor

poke commented Apr 10, 2019

That’s perfect! Thanks a lot!

1,
"Executing action method {ActionName} with arguments ({Arguments}) - Validation state: {ValidationState}");
_actionMethodExecutingWithArguments = LoggerMessage.Define<string, string[]>(
LogLevel.Debug,
Copy link
Member

Choose a reason for hiding this comment

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

This has to be Trace not debug. Debug is not supposed to include sensitive information.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I did consider setting this to trace. While not identical, we do log some other things including the RVD at Debug level: https://github.com/aspnet/AspNetCore/blob/ee0fb6d0e268afcb4848c64ef42a0cb0f48f8e3f/src/Mvc/Mvc.Core/src/Internal/MvcCoreLoggerExtensions.cs#L779-L782

Should I do a pass over these?

Copy link
Member

Choose a reason for hiding this comment

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

We don't consider route values to be sensitive.

@dougbu
Copy link
Contributor

dougbu commented Apr 11, 2019

@pranavkm the next shiproom meeting is tomorrow at 11:00. Please add the requisite label and approval template before that. We aren't meeting again before the merge deadline and discussions in the room tend to go quicker.

@Eilon Eilon added the area-mvc Includes: MVC, Actions and Controllers, Localization, CORS, most templates label Apr 11, 2019
@pranavkm pranavkm changed the title Don't log action and page handler arguments Don't log action and page handler arguments above Trace level Apr 11, 2019
@pranavkm pranavkm added the Servicing-consider Shiproom approval is required for the issue label Apr 11, 2019
@vivmishra vivmishra added Servicing-approved Shiproom has approved the issue and removed Servicing-consider Shiproom approval is required for the issue labels Apr 11, 2019
@vivmishra vivmishra added this to the 2.1.11 milestone Apr 11, 2019
@vivmishra
Copy link

Approved for 2.1.11, 2.2.5 and 3.0.

@pranavkm
Copy link
Contributor Author

Logs from controllers and Razor Pages with this change

@poke
Copy link
Contributor

poke commented Apr 11, 2019

With this change, is there a way now to say which overload of a method is being executed?

Say there's one Login() and one Login(LoginViewModel). Before, you could tell (from the info logs) which overload was being executed. Now that information is gone and you would actually need the debug logs.

Copy link
Contributor

@dougbu dougbu left a comment

Choose a reason for hiding this comment

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

@pranavkm please let me know if this is ready to merge. That is, do you have additional changes you want to make?

@pranavkm
Copy link
Contributor Author

@poke unfortunately that seems to be the case. I had a look at if there's a straightforward solution to including this information in these logs, but that not seem to be the case. We can certainly make this nicer in 3.0. For 2.1 and 2.2, a possible workaround add a trace level filter for the category Microsoft.AspNetCore.Mvc.Internal.ControllerActionInvoker:

  "Logging": {
    "LogLevel": {
      "Default": "Warning",
      "Microsoft.AspNetCore.Mvc.Internal.ControllerActionInvoker": "Trace"
    }

@pranavkm pranavkm force-pushed the prkrishn/dont-log branch from 59bddbf to 070e855 Compare April 12, 2019 17:15
@dougbu
Copy link
Contributor

dougbu commented Apr 13, 2019

@pranavkm please let me know if this is ready to merge.

@dougbu
Copy link
Contributor

dougbu commented Apr 14, 2019

🆙📅 to do the needful in PatchConfig.props

@poke
Copy link
Contributor

poke commented Apr 14, 2019

@pranavkm What do you think about including the number of arguments in the log message? That way it should give a good idea which overload is called (not perfect but better than nothing). And it would be straight forward to do so to.

(I don't want to further delay this PR with this though, so feel free to merge this for now and maybe we can look at it again for 3.0)

@rynowak
Copy link
Member

rynowak commented Apr 15, 2019

We talked about including the types of the arguments on Thursday. We have some existing code that does this elsewhere.

@natemcmaster
Copy link
Contributor

Once merged, will this need to be part of 2.2.x as well? If so, make sure the bot-generated PR is completed, which should be opened shortly after this PR is completed.

@pranavkm pranavkm force-pushed the prkrishn/dont-log branch from b188d80 to ad391ae Compare April 15, 2019 16:57
@pranavkm
Copy link
Contributor Author

🆙 📅

@pranavkm
Copy link
Contributor Author

Here's what it looks like now:

info: Microsoft.AspNetCore.Hosting.Internal.WebHost[1]
      Request starting HTTP/1.1 GET http://localhost:51001/
info: Microsoft.AspNetCore.Mvc.Internal.ControllerActionInvoker[3]
      Route matched with {action = "Index", controller = "Home", page = ""}. Executing controller action with signature Microsoft.AspNetCore.Mvc.IActionResult Index() on controller MvcSandbox.Controllers.HomeController (MvcSandbox).
info: Microsoft.AspNetCore.Mvc.Internal.ControllerActionInvoker[1]
      Executing action method MvcSandbox.Controllers.HomeController.Index (MvcSandbox) - Validation state: Valid
info: Microsoft.AspNetCore.Mvc.Internal.ControllerActionInvoker[2]
      Executed action method MvcSandbox.Controllers.HomeController.Index (MvcSandbox), returned result Microsoft.AspNetCore.Mvc.ViewResult in 5.5025ms.
info: Microsoft.AspNetCore.Mvc.ViewFeatures.ViewResultExecutor[1]
      Executing ViewResult, running view Index.
info: Microsoft.AspNetCore.Mvc.ViewFeatures.ViewResultExecutor[4]
      Executed ViewResult - view Index executed in 283.7445ms.
info: Microsoft.AspNetCore.Mvc.Internal.ControllerActionInvoker[2]
      Executed action MvcSandbox.Controllers.HomeController.Index (MvcSandbox) in 402.5448ms
info: Microsoft.AspNetCore.Hosting.Internal.WebHost[2]
      Request finished in 944.9806ms 200 text/html; charset=utf-8

@pranavkm
Copy link
Contributor Author

@natemcmaster \ @dougbu could you merge?

@natemcmaster natemcmaster merged commit 836964a into release/2.1 Apr 15, 2019
@natemcmaster natemcmaster deleted the prkrishn/dont-log branch April 15, 2019 20:29
@pranavkm pranavkm added the accepted This issue has completed "acceptance" testing (including accessibility) label Apr 19, 2019
@pranavkm
Copy link
Contributor Author

Verified this change is also present in 2.2.5.

@fiksen99
Copy link

fiksen99 commented Aug 9, 2019

Which version did this make it into? We are using 2.1.7 and I see no 2.1 updates since

@vivmishra
Copy link

You can view the various downloads for 2.X releases at https://dotnet.microsoft.com/download/dotnet-core
We are at v2.1.12 for 2.1.

@fiksen99
Copy link

fiksen99 commented Aug 9, 2019 via email

@pranavkm
Copy link
Contributor Author

pranavkm commented Aug 9, 2019

@fiksen99 for .NET Framework, the change would be in the corresponding Microsoft.AspNetCore.Mvc package, not in the metapackage. I'd recommend using the NuGet UI to update to the latest patch releases of all of the Microsoft..* packages.

@fiksen99
Copy link

fiksen99 commented Aug 9, 2019

Thanks, I initially thought that would be the case, but in the Microsoft.AspNetCore.Mvc nuget, we see the lastest 2.1.X update is 2.1.3 in October 2018
image
https://www.nuget.org/packages/Microsoft.AspNetCore.Mvc/

@poke
Copy link
Contributor

poke commented Aug 9, 2019

The changes are in AspNetCore.Mvc.Core and AspNetCore.Mvc.RazorPages, version 2.1.11 each.

I am not sure why the parent package AspNetCore.Mvc wasn't updated to transitively deliver these versions. I would assume that this is actually a publishing bug, since neither Mvc.Core nor Mvc.RazorPages are packages that you usually have to depend on explicitly on netfx.

@fiksen99
Copy link

Thanks. Do you know who owns updating the AspNetCore.Mvc package, and are they aware of this issue?

Are there any potential implications of referenceing AspNetCore.Mvc 2.1.3 and then directly referencing AspNetCore.Mvc.Core 2.1.11+? Or are they intended to be backwards compatible?

@poke
Copy link
Contributor

poke commented Aug 10, 2019

Are there any potential implications of referenceing AspNetCore.Mvc 2.1.3 and then directly referencing AspNetCore.Mvc.Core 2.1.11+?

That should work. Referencing the newer version explicitly will make AspNetCore.Mvc use that version (instead of the older one) too.

@fiksen99
Copy link

makes sense. Would be great to get the entire main Mvc package released too. I assume given 2.1 is LTS, the intention is that these packages continue to receive updates

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
accepted This issue has completed "acceptance" testing (including accessibility) area-mvc Includes: MVC, Actions and Controllers, Localization, CORS, most templates Servicing-approved Shiproom has approved the issue
Projects
None yet
Development

Successfully merging this pull request may close these issues.

8 participants