-
-
Notifications
You must be signed in to change notification settings - Fork 165
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
Fix DoS vunerability with ujson.Obj and upack.Obj #449
Conversation
e5e1bdc
to
0975905
Compare
- Replace `mutable.LinkedHashMap` with `mutable.Map` ujson and upack API `LinkedHashMap` is not secure because of com-lihaoyi#446 This commit removes it from the API and replaces the implementation with a bespoke wrapper around java.util.LinkedHashMap that also extends scala's `mutable.Map` - Add test for issue com-lihaoyi#446
e86dedf
to
0354039
Compare
LinkedHashMap
with mutable.Map
ujson and upack API2b41b9f
to
c66be64
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You changed the visibility of various case classes. Is this also motivated by improving binary compatibility story, or only to better control the construction process? If the former, there is more to do, at least for Scala 2, namely hiding the copy
and the unapply
methods.
I made the |
Rather than privatizing all the constructors, could we just publicize |
@lihaoyi We also have upack.. So maybe it can be an |
I don't think we need to communicate it's only used in ujson.Value. As you said, it's used in upack as well. It can just be a generic "mutable string map preserving input ordering" class. StringMap or ObjMap both sound good to me I don't think we should overhaup the ujson.Obj API in this PR. Not because it doesn't need work, just that that work is pretty orthogonal to fixing this particular performance issue. Regardless, if we wanted to add more helpers on ujson.Obj/ujson.Value it should be possible later without bincompat breakage |
The problem is that |
If this map is a pragmatic mostly internal structure, lets find a pragmatic name paired with some ScalaDoc. What about |
sounds good. I think just |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good to me i think
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good to me. This was lots of work to be on the safe side. Nice job.
Can you update the PR description? I'd like to use it as commit message, too.
Thank you very much @lefou! |
Fixes: #446
Replace
scala.collection.mutable.LinkedHashMap
withupickle.core.LinkedHashMap
inujson.Obj
andupack.Obj
scala.collection.mutable.LinkedHashMap
is not secure because of #446An attacker can create a sequence of keys that return the same
hashCode
.This PR replaces it with
upickle.core.LinkedHashMap
, a bespoke wrapper ofjava.util.LinkedHashMap
which extendsscala.collection.mutable.Map
sincejava.util.LinkedHashMap
is safe against this kind of hash-collision attacks.