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

Initial contents for BinaryFormatter security guide #19442

Closed

Conversation

GrabYourPitchforks
Copy link
Member

@GrabYourPitchforks GrabYourPitchforks commented Jul 11, 2020

Summary

This represents the initial contents for the BinaryFormatter security guide, which will be linked to from https://aka.ms/binaryformatter and is part of the long-term BinaryFormatter obsoletion strategy.

This is intended to be a living document and will eventually grow to include very detailed guidance for specific scenarios, including code samples. By "living document" I mean that we'll probably update it on a monthly cadence until we're satisfied that the guidance covers the necessary use cases. (See #19442 (comment) for a partial list of topics.)

If this repo isn't the proper place for such a document please let me know and I can figure out where else to put it. But given all of the other serialization-related content in this repo, it seemed like a natural fit.

I'm pushing the contents here now so that we can iterate on the formatting or wording if needed. There is already signoff on the high-level concepts covered by the document.

Todo before checkin

  • Update the table at the top, including with keywords and a real asset id
  • Add links from BinaryFormatter API page and related docs to this
  • Include code samples for using XmlSerializer and JsonSerializer
  • Fix wording in other docs to clarify that BinaryFormatter cannot be made safe, even with a custom binder (see Initial contents for BinaryFormatter security guide #19442 (comment) for initial list)

/cc @Rick-Anderson @gewarren

@GrabYourPitchforks
Copy link
Member Author

Topics we'll want to cover, with samples:

  • Serializing Exception graphs
  • Polymorphic deserialization with System.Text.Json
  • Reasoning about cycles, data complexity, algorithmic attacks
  • Deserializing dictionaries safely
  • Dangerous Type.GetType calls

@GrabYourPitchforks
Copy link
Member Author

Docs we need to update because they give improper security guidance:

Buildstarted added a commit to Buildstarted/linksfordevs that referenced this pull request Jul 12, 2020
 1. Added: Initial contents for BinaryFormatter security guide by GrabYourPitchforks · Pull Request #19442 · dotnet/docs
    (dotnet/docs#19442)
 2. Added: crypto_stories.md
    (https://gist.github.com/mimoo/2038533e7c926a1651108fea5d670386)
@Youssef1313
Copy link
Member

There are some roslyn's analyzers related to this, for example CA2300 (and others too). You may like to reference them.

@HurricanKai
Copy link
Member

In my opinion System.Buffers.Binary.BinaryPrimitives should be considered as an alternative next to XML & JSON for those that require binary data.
Especially considering the example of a data file, JSON/XML may not be a viable alternative, as JSON/XML documents can grow very large, and JSON/XML would simply bloat the file too much, also inflating potential load times.
BinaryPrimitives can only encode primitive types, which makes it a more complicated solution, but in some cases, this may be worth it.

@GrabYourPitchforks
Copy link
Member Author

@HurricanKai good suggestion! I'd probably recommend BinaryReader and BinaryWriter instead of BinaryPrimitives since they're more friendly to streaming scenarios, but it still matches the overall spirit of your suggestion.

Co-authored-by: Youssef Victor <31348972+Youssef1313@users.noreply.github.com>
@Rick-Anderson
Copy link
Contributor

Moved to #19445

This was referenced Jul 13, 2020
@GrabYourPitchforks GrabYourPitchforks deleted the bf_sec_guide branch May 20, 2021 21:36
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants