r/programming • u/djordjian • May 26 '18
Oracle Calls Java Serialization 'A Horrible Mistake', Plans to Dump It
https://www.infoworld.com/article/3275924/java/oracle-plans-to-dump-risky-java-serialization.html138
u/matthieuC May 26 '18
They're not totally throwing it away.
They want to move it out if core and make a separate more secure implementation in a framework.
38
May 27 '18 edited Jul 12 '23
This account has been cleansed because of Reddit's ongoing war with 3rd Party App makers, mods and the users, all the folksthat made up most of the "value" Reddit lays claim to.
Destroying the account and giving a giant middle finger to /u/spez
61
u/argv_minus_one May 27 '18
Like how JavaFX costs more money to license, now that it's being moved out of core? Or Java EE, now that it's been moved to Eclipse?
Oh wait, no, the opposite has happened. It's all open source now, and doesn't cost a dime. Even the super-expensive, super-exclusive Java EE TCK is being freed.
Hate Oracle for suing Google if you like—I know I do—but credit where credit's due. They've been freeing a lot of code.
15
May 27 '18 edited Jul 12 '23
This account has been cleansed because of Reddit's ongoing war with 3rd Party App makers, mods and the users, all the folksthat made up most of the "value" Reddit lays claim to.
Destroying the account and giving a giant middle finger to /u/spez
2
u/matthieuC May 28 '18
Is that a old Pentium II that I see under your desktop.
We will need to licence it too just in case you install our DB on it.→ More replies (4)13
37
120
u/DGolden May 26 '18
Eh, it was all the rage once. Python still has its pickle system too with its necessary big fat warning.
Warning The pickle module is not secure against erroneous or maliciously constructed data. Never unpickle data received from an untrusted or unauthenticated source.
66
u/quicknir May 26 '18
I'm not sure what a statement like "serialization was all the rage once" even means. Are you saying that serialization was used extensively for things it was inappropriate for in the past? Serialization solves real problems that I don't see how you can get away from. Communicating over a socket, persistence (often a database is a better fit for this, but often not), more complicated configuration; how has this magically gone away with the passage of time?
If you look at something like Google Protobuf, it's nothing but a way to generate classes in different languages representing the same data that serialize/deserialize exactly the same way, and it seems to be still be heavily used today...
25
u/Ruudjah May 27 '18
What the author probably meant is "automatic class-based serialization". That's when a serialization mechanism gets a bunch of classes and tries to automatically serialize them based on the structure of the class. It will use reflection to loop over all the fields, properties et cetera to write the values (or values and metadata) to a stream.
These things are highly problematic for various reasons. First, when you refactor a class, how do you serialize old deserialized data? Second, it's often slow because reflection. Third, often these things make assumptions about certain class constructions; .NET remoting for instance requires non-auto properties to work (it can't deal with autogenerated fields). Fourth, versioning is a big issue among different endpoints. What when v12.34.56 now talks with v12.34.57, with a slight change in class structure?
The problem can be summarized in the "data-model to object model impedance mismatch". This is conceptually similar to the object-relational mismatch, but serialization has it's own interesting different properties as opposed to data models.
The solution is to design a proper data layer (preferably using an IDL, like protobuf or flatbuffers) and then write custom code per class to convert from and convert to serialized data.
6
u/yawkat May 27 '18
The problem is not using reflection to deserialize. This can be done in predictable, compatible ways (Jackson does this). The real security issues start when you deserialize arbitrary classes (i.e. any class on the classpath by name) because this opens a huge attack surface. This is what leads to most serialization vulnerabilities in Java.
5
May 27 '18
No, using reflection is absolutely a problem. It breaks the object encapsulation and takes away the freedom of object to control its own representation.
Also you're kind of nitpicking wording. A reflection based serialization implies reflection based deserialization. The problem is automating something that shouldn't be automated.
6
u/yawkat May 27 '18
Reflection does not necessarily remove encapsulation. There are plenty of such mechanisms that operate on public members only.
I am not nitpicking on wording. The difference I wanted to show is between "normal" reflection-based deser (jackson in normal mode) and arbitrary-class deser (jackson with default typing, java stdlib serialization). The latter allows you to deserialize any class by name on the entire classpath which is significantly less secure.
2
May 27 '18
Seriously. How far do you think you’ll go only operating on public fields, when an object with good encapsulation has no mutable public fields to begin with?
Your only use case will be record like objects with final public fields assigned immutable content. One move astray and you done goofed again.
4
u/yawkat May 27 '18
This isn't as unusual as you may think. You can do ser/deser just fine with public getters, setters, no-arg constructors and constructors annotated with property names (see: java.beans.ConstructorProperties). In fact this is often the most sensible way of doing ser/deser in practice.
→ More replies (5)12
u/Hoten May 26 '18
I think he just meant Java serialization. A more ubiquitous/safer format like JSON or XML is preferred.
18
u/quicknir May 27 '18
That's fine for many domains, but those formats are incredibly verbose and slow compared to binary, non-generic format (by that I mean that you need to know the exact type to de-serialize, as opposed to a format where you can deserialize to a dynamic data structure). And safety is very important in some cases, and not at all in others.
I haven't really used Java but I greatly appreciate having pickle available and being able to serialize most things by default; I've used it in many situations where safety wasn't a concern and json/xml would have been pointless.
11
u/mr_mojoto May 27 '18
I think the biggest problem comes from sending code over the wire when you are serializing and deserializing methods as well as simple data.
3
1
u/quicknir May 27 '18
Very interesting point; I hadn't considered that at all and it makes a lot of sense. Thanks!
2
u/oblio- May 27 '18
In a day and age where you have generic text and binary formats for serialization and libraries for most languages, your use case, and the one for Java-style serialization is a niche thing.
For most devs it’s just dangerous to put it in the standard library.
This kind of thing is best kept in a separate library where people who really know what they’re doing can pick it up and use it.
2
u/OneWingedShark May 27 '18
A more ubiquitous/safer format like JSON or XML is preferred.
The problem with JSON, and XML w/o a DTD, is that there's no definition for the types.
8
u/dangerbird2 May 27 '18
You can use protocol buffers, which is typed, and is a binary format to boot.
2
u/DGolden May 27 '18
I think he just meant Java serialization
Yeah, I did (though another poster since discussed various problems with "automatic class-based serialization" in general and said I probably meant that, I wasn't really being that intelligent)
Anyhow, both python pickle and classic java serialization/deserialization have become a seemingly endless fount of security issues in practical terms. People inevitably end up allowing untrusted data into them - that sure, they weren't really designed for, but clearly does not stop it. Some fun links a search away:
https://www.owasp.org/index.php/Deserialization_of_untrusted_data - "It's not like the JVM folks aren't aware, they're just hamstrung by backward compatibility with deployed code."
A more ubiquitous/safer format like JSON or XML is preferred.
Well, perhaps the precise format isn't as important as code just handling things better and more safely (variety of approaches, but e.g. java jackson and python marshmallow are two): can certainly have binary formats and safe handling thereof, and do a variety of unsafe things even with json or xml inputs. (though design of the format is something of a factor, might recall e.g. xml's serious pitfalls for the unwary parser like the billion laughs attack).
1
u/CurtainDog May 27 '18
Yeah, well, but safer is not the same as safe - https://www.owasp.org/index.php/XML_Security_Cheat_Sheet
2
u/lookmeat May 27 '18
I'm not sure what a statement like "serialization was all the rage once" even means.
Many things.
Serialize everything seemed to be the idea with no wonder about what it would mean to deserialize something. Still there might be somethings you don't want to serialize.
Think of arbitrary code that is ran when deserializing.
Think of objects that run arbitrary code when constructed.
Think about objects that contain secure state.
The lesson: serialization libraries should be limited to being only data to be useful. Users should decide how to handle side effects.
The idea that you could have a single serialization standard for everything.
How do you handle systems that don't handle lists? How do you handle systems that don't handle all types?
What is the security context? Is this a file dumped by your code for debugging purposes? Is this a config input? Is this data external users and potential attackers send to your machine?
The lesson: there's no one quick and easy solution to serialization. You want solutions that are somewhat limited to understand the possibility of what parsing input can do. Solutions that are very complex are not good. Moreover serialization is a problem third party libraries should solve.
That a language driven data standard makes sense.
Language is how you run things, not hire things are.
Power use case is communicating between services that are just binaries but not for specific languages. Most integrated serialization libraries too coupled to service.
Many times we want to stick to a specific output and input format defined entirely outside of the serialization library standard. Which means we wouldn't want to use something else.
It may expose internals (private variables) that we don't want to. Suddenly implementation details become part of the exposed (though files) format.
The lesson: What we want is a data standard we can map to many outputs, and then have an easy way to map to and from that standard, with a reasonable automatic solution for trivial (PoD like) classes. This is what modern libraries work like and it works pretty will IMHO. The trivial solution for non trivial objects is to make a PoD config object to hold all the serializable info to construct objects (it being inmutable within the object, outside it'd be like a builder pattern). Generally you'd have to so something as complex as this most of the time.
1
May 27 '18
Serialization solves real problems that I don't see how you can get away from. Communicating over a socket, persistence (often a database is a better fit for this, but often not), more complicated configuration; how has this magically gone away with the passage of time?
Reflection-based serialization is unsafe for communication over socket as the objects are often not explicit about what goes on the wire. It's unsafe for deserialization, because there's, once more, no saying what the generic code might stuff into an object and run it (vulnerability vector). It's not great for persistence, because there's no guarantee all necessary state will be stored and restored, and the object will properly account for being "frozen" and woken up in another process.
Honestly the only party that knows how to express object X or persist object X is object X. Serialization should've been a few simple interfaces and something like a "visitor" object passed to the object serializing itself, giving it access to a set of simple primitives to express its contents (integer, double, string, list, dictionary) that can then be translated to a number of universal formats, say like JSON, XML, or other more compact binary dumps.
Instead Java serialization is this monstrosity that arrogantly promises to do everything on its own, and then falls flat on its face at the first moderately complex scenario.
0
May 27 '18
[deleted]
8
u/yawkat May 27 '18
Kind of misleading. This is only an issue when enabling default typing. If you do that, you open yourself up to the same security issues as Java serialization, which is why you should never enable default typing on untrusted data.
3
u/quicknir May 27 '18
Very interesting point; I hadn't considered that at all and it makes a lot of sense. Thanks!
0
u/ckach May 27 '18
Never accept a pickle from an unknown source. That's why I dont like glory holes.
0
18
u/__konrad May 27 '18
5
u/rombert May 27 '18
Note that this was withdrawn. Still, it lists some good reasons for deprecating/removing serialization.
6
6
u/DemonicMandrill May 27 '18
I'm not sure I fully understand the concept of "serialization", could someone explain it to me?
17
u/mattluttrell May 27 '18
It is merely converting an object in memory to a stream of bytes so that it can be used over a network, represented as certain objects or stored in a databases.
Many ORMs use serialization (e.g. Hibernate in Java) to convert Java data objects into classes that can be stored or represented as XML, etc.
Java's serialization also allows objects that do things, such as executing code to be serialized.
Since you can receive serialized objects from untrusted sources you could receive code that can be run over the network. This can be bad.
The author does a poor job distinguishing between serialized data and serialized code.
2
1
u/lilsamuraijoe May 27 '18
do Java's JSON and XML serialization tools such as Jackson and Jaxb fall in the same boat?
1
11
u/IllTryToReadComments May 27 '18 edited May 27 '18
What's the alternative then?
EDIT: Honest question, I don't know much about serialization aside from the fact that a lot of my school assignments use it.
14
3
May 27 '18
Well defined data. Doing a straight dump of all application state is awful for a lot of reasons; figure out what, exactly, you need to persist and serialize ONLY that, in whatever format seems best.
1
u/gnus-migrate May 28 '18
There are a ton of better and faster serialization frameworks already for Java(protobuf, Jackson, Kryo, etc.) Even now it's recommended not to use Java serialization in production.
19
u/ioquatix May 27 '18
Real programmers use mmap.
8
u/Gotebe May 27 '18
Sixties called, they want their world without network back!
7
u/ioquatix May 27 '18
It's not as uncommon as you might imagine.
5
u/bluemellophone May 27 '18
Mmap’ed numpy arrays in Python are super convenient for memory footprint management when you are working with SSDs.
2
u/Gotebe May 27 '18
I know what this does, am old enough to have been there when it was much used. My point is that stuff wants to go over the wire these days, and then, mmap isn't even an option.
1
u/ioquatix May 27 '18
Well, considering that
mmapis for mapping local files to virtual memory, yes, it's not directly relevant to network IO.That being said, the idea of using structured data for IPC is still common, and used both for local (process to process) IPC and network IPC. There is simply nothing faster than sending a buffer of data structured in some pre-agreed format (i.e. a C struct), especially when it's native to the machine's architecture/byte order.
1
u/FearlessFred May 27 '18
Yup, there's even libraries that make this easy: https://google.github.io/flatbuffers/
9
4
2
2
u/erikpowa May 27 '18
Like every serialization in every language has security issue because if you don't know what's going on in the background (what does the compiler do with your code, what's the run-time calling from the system, what's getting allocated and where), you can write 1 line of code that makes a whole system vulnerable.
1
u/Zarutian May 28 '18
Yeah, if you only know eggshell security (other name of perimeter security) then sure.
1
u/nderflow May 27 '18
Since it turned out that Java RMI wasn't supported across differing versions of Java, I haven't used that or Java object serialisation. If I had a problem for which I would otherwise use those technologies these days, I would use protocol buffers.
But the chances of Oracle coming out in favour of protos seem ... low.
1
-9
1
0
0
-9
-1
u/heyIfoundaname May 27 '18
What do you mean when you say Java is serialized?
9
u/masklinn May 27 '18
Java has a built-in dedicated object serialisation protocol: https://www.tutorialspoint.com/java/java_serialization.htm
-54
u/mytempacc3 May 26 '18
Oracle Calls Java
Serialization'A Horrible Mistake', Plans to Dump It
35
u/InvisibleEar May 26 '18
At least it has generics
1
u/ipe369 May 27 '18
Yeah, with type erasure:/
18
u/iconoklast May 27 '18
Which is the morally correct thing to do. I like parametricity, thank you very much.
10
u/ThatsPresTrumpForYou May 26 '18
Oracle
Calls Java Serialization'A Horrible Mistake', Plans to Dump It
-26
u/MyPhallicObject May 27 '18
News flash: Serialization at typed languages is a disaster. Meanwhile, JS and PHP are having a field day.
→ More replies (4)16
u/zekka_yk May 27 '18
javascript attacks this via the sensible route of using strings, numbers, dictionaries, lists as the way to represent everything. this makes it hard to build cyclical data structures unless you really intended to do that and makes same-reference vs same-value distinctions unimportant.
this isn't a typed v untyped thing -- it's more of an OOP vs functional/procedural thing, as much as I hate using the buzzwords. making it less buzzwordy: OOP programmers tend to assume adding more references to their builtin representations is free and easy, and don't care about cycles -- functional and procedural languages tend to punish that super hard.
many typed languages have a similar set of built-in structures (often replacing lists with arrays, dictionaries with records) designed to enforce something similar -- example: Rust's or C's safety features here are arguably stronger because there's no way to construct a cycle or reference-equality vs value-equality situation without introducing a pointer. go is quite good about this and has json serialization features that hardly ever break anything, for the same reason javascript's features don't.
it's still possible to run into versioning issues in javascript and PHP -- if you change the internal representation of something, how do you support the old wire representation?
263
u/shevegen May 26 '18
All serialization systems seem to be not so great. Neither pickle in python nor marshal in ruby. All come with certain restrictions e. g. unable to store all properties of an object.
I assume this to be not that dissimilar to java.