k-john-gough / gppg

GPPG is a parser generator that produces parsers written in the C# V2 or higher. The input language is YACC-like, and the parsers are LALR(1), with the usual automatic disambiguations. Designed to work with GPLEX.
Other
37 stars 23 forks source link

BinaryFormatter is obsolete and should not be used. #8

Open kyanha opened 10 months ago

kyanha commented 10 months ago

(Mr. Gough, I understand that you are fully retired, and I am not requesting you change this unless you feel like it. I'm just documenting this issue, for anyone who, like me, is trying to compile gppg against a newer version of dotnet, such as net6.0 or net7.0.)

https://aka.ms/binaryformatter has a lot of information on this issue, including an explanation of why BinaryFormatter is insecure and cannot be made secure. (Anything which performs unrestricted polymorphic deserialization cannot be made secure.) This is used in CodeGenerator.cs and ParseHelper.cs. For security, it recommends:

-XmlSerializer and DataContractSerializer to serialize object graphs into and from XML. Do not confuse DataContractSerializer with NetDataContractSerializer.

k-john-gough commented 10 months ago

Hi Kyle

And thanks for the email.

Yes, I am fully retired, but I would like to keep GPPG and GPLEX going as long as the community finds them useful.

The issue with the Binary Formatter is really, very much, a specialized one. The facility is only used in the case where two (or more) parsers have to share a token type. One parser declares /sharetokens, which causes the creation of file ${parsername}Tokens.dat. The other parsers then declare /importtokens=filepath to share the definitions. The main use of this is to write parsers that invoke ad-hoc lookahead in a sub-parser and then back-track to the main parser. Yes, pretty specialized stuff!

Because this is such a specialized case, I didn't bother defining a format for the token file and left it to the binary formatter.

A simple way to eliminate the security hole would be to create an XML format for the token file and change the two references in ParseHelper.cs and CodeGenerator.cs to use the XML reader and writer. (An even simpler fix would be to get rid of /importtokens and /sharetokens, but it would break the code of anyone who IS using the facility.

If anybody out there wants to have a go, I would be happy to cast an eye over it. If absolutely necessary I could probably do it myself, but I am getting pretty rusty with C#

Cheers John Gough


From: Kyle H @.> Sent: Tuesday, 12 September 2023 9:25 AM To: k-john-gough/gppg @.> Cc: Subscribed @.***> Subject: [k-john-gough/gppg] BinaryFormatter is obsolete and should not be used. (Issue #8)

(Mr. Gough, I understand that you are fully retired, and I am not requesting you change this unless you feel like it. I'm just documenting this issue, for anyone who, like me, is trying to compile gppg against a newer version of dotnet, such as net6.0 or net7.0.)

https://aka.ms/binaryformatter has a lot of information on this issue, including an explanation of why BinaryFormatter is insecure and cannot be made secure. (Anything which performs unrestricted polymorphic deserialization cannot be made secure.) This is used in CodeGenerator.cs and ParseHelper.cs. For security, it recommends:

-XmlSerializerhttps://learn.microsoft.com/en-us/dotnet/api/system.xml.serialization.xmlserializer and DataContractSerializerhttps://learn.microsoft.com/en-us/dotnet/api/system.runtime.serialization.datacontractserializer to serialize object graphs into and from XML. Do not confuse DataContractSerializer with NetDataContractSerializerhttps://learn.microsoft.com/en-us/dotnet/api/system.runtime.serialization.netdatacontractserializer.

— Reply to this email directly, view it on GitHubhttps://github.com/k-john-gough/gppg/issues/8, or unsubscribehttps://github.com/notifications/unsubscribe-auth/AEC5EFAXPTOSRO32HUQT6ELXZ6MWDANCNFSM6AAAAAA4UBDUPM. You are receiving this because you are subscribed to this thread.Message ID: @.***>

ernstc commented 9 months ago

Hi @k-john-gough , Hi @kyanha ,

A while ago, I have forked gppg and gplex for developing YaccLexTools package aimed to simplify the use of Yacc and Lex files in C# projets. In the last year I have made a huge maintenance to my project for supporting also .NET Core and .NET 5+, and in this context I have already resolved this issue using JSON serialization with System.Text.Json. If you want to take a look, here are the specific changes I have made: https://github.com/ernstc/gppg/commit/545abdc876a88e791b4cf05320d7dc5180257e54

If your are interested, I will create a pull request for updating also this repository.

Cheers Ernesto Cianciotta

k-john-gough commented 9 months ago

Hi Ernesto

Thank you for your email.

And, more importantly, thank you for making the changes to gppg to avoid the use of BinaryFormatter, and also to work with the more recent releases of .NET. I would certainly like your work to be available to other users of gppg and gplex. We could do this by you creating a pull request, but in the long term I need someone to take over management of the two github accounts. Are you willing to be that person?

Please consider this offer. I am very happy to answer any questions you might have regarding the programs, and also can supply the sources for the documentation (which is not currently on github).

Best regards K John Gough

From: Ernesto Cianciotta @.> Sent: Friday, October 6, 2023 8:47 PM To: k-john-gough/gppg @.> Cc: K John Gough @.>; Mention @.> Subject: Re: [k-john-gough/gppg] BinaryFormatter is obsolete and should not be used. (Issue #8)

Hi @k-john-goughhttps://github.com/k-john-gough , Hi @kyanhahttps://github.com/kyanha ,

A while ago, I have forked gppg and gplex for developing YaccLexTools https://github.com/ernstc/YaccLexTools package aimed to simplify the use of Yacc and Lex files in C# projets. In the last year I have made a huge maintenance to my project for supporting also .NET Core and .NET 5+, and in this context I have already resolved this issue using JSON serialization with System.Text.Json. If you want to take a look, here are the specific changes I have made: @.***https://github.com/ernstc/gppg/commit/545abdc876a88e791b4cf05320d7dc5180257e54

If your are interested, I will create a pull request for updating also this repository.

Cheers Ernesto Cianciotta

— Reply to this email directly, view it on GitHubhttps://github.com/k-john-gough/gppg/issues/8#issuecomment-1750396743, or unsubscribehttps://github.com/notifications/unsubscribe-auth/AEC5EFBA5HHTGJEXELJRZKTX57OTZAVCNFSM6AAAAAA4UBDUPOVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMYTONJQGM4TMNZUGM. You are receiving this because you were mentioned.Message ID: @.**@.>>

ernstc commented 8 months ago

Dear Mr. Gough, I am honored for your offer. I can help to take alive the two projects by let them be up to date with the evolutions of .NET in the future and for resolving issues, wherever possible.

Best Regards, Ernesto Cianciotta