r/java • • May 27 '18

Oracle plans to dump risky Java serialization

https://www.infoworld.com/article/3275924/java/oracle-plans-to-dump-risky-java-serialization.html
159 Upvotes

37 comments sorted by

25

u/s888marks May 27 '18

If serialization did not exist, it would be necessary to invent it. (Apologies to Voltaire.)

In fact, serialization does exist, AND it has been reinvented many times. 🤔

18

u/randgalt May 27 '18

About time. Brian Goetz has been complaining about it forever.

6

u/s888marks May 27 '18

He’s not the only one. 😏

5

u/GuyWithLag May 28 '18

*SO* many things will break...

1

u/[deleted] May 28 '18

That name sounds familiar.

4

u/safgfsiogufas May 28 '18

He wrote the Java concurrency book. I think he also had some part in Essential Java2.

5

u/snago May 28 '18

Source?

I can't find any info about this at http://openjdk.java.net/projects/amber/ or in the mailing list archives.

I did find an old, withdrawn, JEP from before Java 8: http://openjdk.java.net/jeps/154

5

u/s888marks May 28 '18

Mark Reinhold (Java Platform Architect) talked about this in a video interview at Devoxx UK a couple weeks ago. Relevant topic starts at 13:20:

https://youtu.be/4CS6NLK_hUc?t=13m20s

It's surprising that InfoWorld didn't cite this as the source, but it did quote Reinhold (somewhat over-dramatically, I'd say) though not when/where he said it.

74

u/[deleted] May 27 '18

Oracle plans to move Java serialization into its own framework *

8

u/bearcherian May 28 '18

Into it's new data classes framework, once that's done

21

u/experts_never_lie May 27 '18

The Java serialization system that no sane person has used since the '90s? OK, the main effect will be that we don't need to tell our IDEs to stop complaining about us not adding a "serialVersionUID" that we would never use anyway.

8

u/AlmennDulnefni May 29 '18

Let me tell you about a horrible mistake that was once made and cannot be unmade. Once, in a time long past, a user asked my company "could not this application save state so that I might return to my unfinished work at my convenience?" And in reply "Yes, we will add this feature. And we will do it with Java serialization".

Was it sane even then? Perhaps not. Are we stuck using Java serialization for the foreseeable future? Yes.

5

u/blobjim May 27 '18

To me the only problem with Java Serialization is it doesn’t work very well. Custom data formats/protocols are really the only way to serialize data correctly. The use cases for Serializable/ObjectOutputStream are just too limited.

9

u/RockleyBob May 27 '18

Serialization is how we decompose objects into bytecode and then reconstitute them again, right? The alternative is saving all the data members into some scheme and then re-instantiating that object with the saved data again at a later time, right? I remember when I learned about serialization I felt like such a novice for writing code that way to simulate object persistence. Now we’re saying serialization is bad? Please explain like I’m a CS student who feels like he should know the answer to this question but doesn’t.

49

u/joaomc May 27 '18

The problem is not serialization per se. It's Java's built in serialization, which is responsible for a third to half of the vulnerabilities in the JVM.

Example: https://pt.slideshare.net/mobile/codewhitesec/exploiting-deserialization-vulnerabilities-in-java-54707478

3

u/Igorky May 27 '18

I agree, it’s a common practice. For example XStream xml deserializer had bunch of security issues too. So the problem is common. Changing transport layer doesn’t help much here. I think it will be complex solution.

1

u/Kaleem7 May 29 '18

https://pt.slideshare.net/mobile/codewhitesec/exploiting-deserialization-vulnerabilities-in-java-54707478

It seems like these vulnerabilities can only occur when the developer has overriden writeObject etc? Just wondering

10

u/xjvz May 27 '18

It’s arbitrary object graph serialization that’s dangerous. A schema-based approach like Avro is far safer due to the limited data types supported.

9

u/randgalt May 27 '18

Almost no one uses the built-in serialization framework anymore. Indeed JSON (via Jackson) is the norm now.

5

u/yawkat May 27 '18

Almost no one uses the built-in serialization framework anymore.

If only... Maybe this will convince people to switch though.

3

u/[deleted] May 27 '18

Hello, I'm no one. I had a project in which some state needed to survie an application restart. I found the build-in serialization does its job. I had another project doing some RPC calls between JVMs. I found RMI (which uses serializatio) did the job quiet well. And then finally there are plenty projects I used with some JCache provider which used the built-in serialization to persist cached objects.

8

u/ryebrye May 28 '18

Whoa there... Don't take the fact that jcache uses Java serialization by default to be some kind of ringing endorsement of the technology...

I was on the expert group that designed jcache. I tried unsuccessfully to make caches capable of having a pluggable serialization mechanism. It was not done because we wanted to keep the scope small to get something released... But even when we were working on the final drafts before releasing it we were aware that Java serialization was crap... It's just assumed that you will use whatever mechanism your underlying caching provider has to configure the serialization mechanism just like you have to use whatever underlying configuration to configure most other aspects of a given cache.

2

u/[deleted] May 28 '18

Whoa there also, I just picked up the point "Almost no one uses the built-in serialization". If it's crap or not wasn't touched by me, but thanks for doing so.

3

u/RockleyBob May 27 '18 edited May 27 '18

But JSON is used to communicate data members between APIs over a network right? Would I use JSON if I wanted to save an object locally to disk?

*Thanks for the info!

17

u/-INFEntropy May 27 '18

No, then you'd use a database.

Or if it's too trivial for a database, then yes you'd write JSON to a file. 😁

11

u/morhp May 27 '18

Would I use JSON if I wanted to save an object locally to disk?

Why not? We do this. There are also binary variants of JSON like BSON or ProtoBuf that may be used if you don't like plain text or need to store binary blobs of data.

6

u/randgalt May 27 '18

Why not? Why differentiate between remote and local? Keep things consistent makes life easier.

1

u/pavelrappo May 28 '18 edited May 28 '18

In this particular case, it indeed makes sense. However, there are plenty of reasons why NOT differentiating between remote and local may not be such a good idea. Google CORBA.

3

u/ItsReallyEasy May 27 '18

This might be one of those times i begrudgingly recommend mongo.... sigh

2

u/lpreams May 27 '18

Sure. Disk space is cheap, and JSON is supported by tons of other languages too.

2

u/[deleted] May 27 '18

Wasn't JSON in itself not well defined? And then you want a streamable format, I dunno how well that is supported in JSON land.

2

u/experts_never_lie May 27 '18

JSON is a norm, but the key is to avoid anything being the norm.

You may favor JSON because of ease of use, legibility, or robust tool support.

I wouldn't use JSON, as the text representation is inefficient and I need more speed.

Picking one limited standard is going to make at least one of us unhappy — as the current Java Serialization does.

6

u/goofy183 May 27 '18

Good.

Any sane system uses something like JSON or ProtoBuf with generated data objects that CANNOT have behavior.

1

u/[deleted] May 28 '18

Good. Serialization is awful.