Commit graph

237 commits

Author SHA1 Message Date
Peter Taoussanis
421d45b3c3 Bump Encore dep (v3.0.0) 2020-09-10 22:53:43 +02:00
Peter Taoussanis
e5a614bd9b *serializable-whitelist*: incl. some basic classes in default 2020-09-10 11:18:43 +02:00
Peter Taoussanis
ee9917d42a Update project.clj, bump deps 2020-09-10 11:05:02 +02:00
Peter Taoussanis
79612437ca [#131] *serializable-whitelist*: add JVM property, env var overrides 2020-08-27 10:34:47 +02:00
Peter Taoussanis
5de70b9516 *serializable-whitelist*: support "*" wildcards in class names 2020-08-27 10:34:28 +02:00
Peter Taoussanis
f9d0123d89 *serializable-whitelist*: improve docstring 2020-08-27 10:31:12 +02:00
Peter Taoussanis
040da54936 [#126] extend-freeze: include id collision odds in docstring 2020-08-27 10:31:01 +02:00
Peter Taoussanis
cf84a441f4 Revert v2.14.2 hotfix reset 2020-07-24 19:38:16 +02:00
Peter Taoussanis
ea93fee8e2 v2.14.2 hotfix 2020-07-24 19:37:11 +02:00
Peter Taoussanis
61fb009fdd [BREAKING] [Security] Fix RCE vulnerability
Fix a Remote Code Execution (RCE) vulnerability identified in an
excellent report by Timo Mihaljov (@solita-timo-mihaljov).

You are vulnerable iff both:

  1. You are using Nippy to serialize and deserialize data from an
     UNTRUSTED SOURCE.

  2. You have a vulnerable ("gadget") class on your classpath.
     Notably Clojure <= 1.8 includes such a class [1].
     Many other libraries do too, some examples at [2].

To prevent this risk, a Serialization whitelist has been added.
Any classes not *explicitly* authorized by the whitelist to use
Serialization will NOT be permitted to.

The default whitelist is EMPTY, meaning this is a BREAKING
change iff you make use of Nippy's Serialization support. In
this case, you'll need to update the whitelist for your needs.

For more info see the `*serializable-whitelist*` docstring.

[1] https://clojure.atlassian.net/browse/CLJ-2204
[2] https://github.com/frohoff/ysoserial

Further info below provided by Timo:
------------------------------------

Deserialization vulnerabilities are exploited by constructing objects of classes
whose constructors perform some action that's useful to the attacker. A class like
this is called a gadget, and a collection of such classes that can be combined to
reach the attacker's goal is called a gadget chain.

There are three prerequisites for exploiting a deserialization vulnerability:

  1) The attacker must be able to control the deserialized data, for example,
     by gaining write access to the data store where trusted parties serialize
     data or by exploiting some other vulnerability on the other end of a
     communications channel.

  2) The deserializer must construct objects of classes specified in the
     serialized data. In other words, the attacker must have full control over
     which classes get instantiated.

  3) The classpath must contain gadgets that can be combined into a gadget chain.

The vulnerable code is in Nippy's function `read-serializable`, which calls the
`readObject` method of `ObjectInputStream`.

I have only tested the PoC with the latest stable version, 2.14.0, but looking at
Nippy's Git history, I believe all versions starting with the following commit
are vulnerable:

    commit 9448d2b3ce
    [Thu Oct 24 13:47:25 2013 +0700]

For a user to be affected, they must:

  1) use Nippy to serialize untrusted input, and
  2) have a gadget chain on their classpath.

I suspect (but haven't verified) that using Nippy's encryption feature prevents
exploitation in some cases, but if it's used to encrypt the communications between
two systems, one compromised endpoint could send encrypted but
attacker-controlled data to the other.

Ysoserial [4] contains a list of some Java libraries with known gadget chains.
If any of those libraries can be found on the user's classpath, they are known
to be vulnerable. (Ysoserial's list is not exhaustive, so even if a user doesn't
have these particular libraries on their classpath, they may still have some
other gadget chains loaded.)

Unfortunately Clojure versions before 1.9 contained a gadget chain in the
standard library [5][6], so all Nippy users running Clojure 1.8 or earlier
are vulnerable. (Note that users of later Clojure versions may or may not
be vulnerable, depending on whether they have gadget chains from other
libraries on their classpath.)

[4] https://github.com/frohoff/ysoserial
[5] https://groups.google.com/forum/#!msg/clojure/WaL3hHzsevI/7zHU-L7LBQAJ
[6] https://clojure.atlassian.net/browse/CLJ-2204
2020-07-24 18:17:25 +02:00
Peter Taoussanis
b6c1c09419 Allow freeze, thaw opts to override bindings 2020-07-24 17:15:40 +02:00
Peter Taoussanis
57eae96c7b Add auto-size read-bytes 2020-07-24 17:10:17 +02:00
Peter Taoussanis
1855c50d9b Dynamic-var housekeeping
Also toyed with:

  - Possibility single var derefs at `freeze`/`thaw` call.
    Abandoned since big change, and slower with opts destructuring.

  - Possibility of consolidating all config into a single var.
    Abandoned since breaking, and slower with opts destructuring.
2020-07-24 12:06:04 +02:00
Peter Taoussanis
7aa6425159 [#127] Add utils: freeze-to-string, thaw-from-string (@piotr-yuxuan) 2020-07-23 12:22:27 +02:00
Peter Taoussanis
f1c71b58d8 [Crypto] Use enc/srng 2020-07-23 12:22:27 +02:00
Peter Taoussanis
23276ac910 [#101] NB Change default encryption from AES-CBC to AES-GCM
Why?

  - AES-GCM is faster and can be more secure, Ref. https://goo.gl/Dsc9mL, etc.
  - AES-GCM is an authenticated[1] encryption mechanism, providing
    automatic integrity checks. This is relevant to [#101].

What's the issue with #101?

  - We    compress then encrypt    on freeze ; Reverse would make compression useless
  - So we decrypt  then decompress on thaw

Attempting CBC decryption with the wrong password will often but not
*always* throw. Meaning it's possible for decompression could be
attempted with a junk ba. And this can cause some decompressors to
fail in a destructive way, including large allocations (DDoS) or even
taking down the JVM in extreme cases.

Possible solutions?

  - We could add our own HMAC, etc.
  - And/or we could use something like AES-GCM which offers built-in
    integrity and will throw an AEADBadTagException on failure.

There may indeed be reasons [2,3,4] to consider adding a custom HMAC -
and that's still on the cards for later.

But in the meantime, the overall balance of pros/cons seems to lean
in the direction of choosing AES-GCM as a reasonable default.

Note that the change in this commit is done in a backward-compatible
way using Nippy's versioned header: new payloads will be written using
AES-GCM by default. But old payloads already written using AES-CBC will
continue to be read using that scheme.

References
  [1] https://en.wikipedia.org/wiki/Authenticated_encryption
  [2] https://www.daemonology.net/blog/2009-06-24-encrypt-then-mac.html
  [3] https://blog.cryptographyengineering.com/2011/12/04/matt-green-smackdown-watch-are-aead/
  [4] HMAC vs AEAD integrity,           https://crypto.stackexchange.com/q/24379
  [5] AES-GCM vs HMAC-SHA256 integrity, https://crypto.stackexchange.com/q/30627
2019-01-06 14:13:34 +01:00
Peter Taoussanis
7f9b075ba7 [#114] PR housekeeping 2019-01-06 12:24:29 +01:00
Isak Sky
abb55da29e [#113 #114] Support object arrays (@isaksky) 2019-01-06 12:24:29 +01:00
Peter Taoussanis
c83572f0a8 [#112] PR housekeeping 2018-10-06 10:22:13 +02:00
Isak Sky
67dde8d7bd [#83 #112] Add support for deftype (@isaksky) 2018-10-06 09:57:35 +02:00
Isak Sky
192666c09e [#83 #113] Add URI support (@isaksky) 2018-10-06 09:50:24 +02:00
Peter Taoussanis
2272d5ea57 [#104] Micro-optimization: remove unnecessary runtime 'if' in extend-freeze macro (@scramjet) 2017-12-21 10:47:30 +01:00
Peter Taoussanis
1a8a44286a [#93] Pickup record redefinitions at REPL, etc. (@smee) 2017-12-21 10:12:33 +01:00
Peter Taoussanis
ded6cc034f [#91] Add convenience utils for freeze/thaw to/from files
Suggested by @Engelberg (thanks Mark!).

Also seems to be a common question online, e.g.:
http://stackoverflow.com/q/23018870
2017-02-13 17:52:19 +01:00
Peter Taoussanis
bc33489dce Bump 1-byte cache count: 5->8 2016-10-28 16:52:05 +07:00
Peter Taoussanis
bc5f045979 Revert experimental semi-auto key caching 2016-10-28 16:37:54 +07:00
Peter Taoussanis
7c8acfe663 Experimental: optional semi-auto key caching 2016-10-28 16:36:04 +07:00
Peter Taoussanis
4aa1a3b871 ns form housekeeping 2016-10-28 10:25:46 +07:00
Peter Taoussanis
2eb3d25dba Hotfix: deprecated private API typo 2016-08-23 22:33:34 +07:00
Peter Taoussanis
5c94841313 De-deprecate type ids 6, 80
Conceptually simpler to just retain these as first-class thaw-only
types.
2016-07-26 12:22:23 +07:00
Peter Taoussanis
c1d48c7ef9 Hotfix: missing thaw routines for deprecated type ids: 6, 80
Ref. https://github.com/ptaoussanis/faraday/issues/98
2016-07-26 12:06:23 +07:00
Peter Taoussanis
a8faac734c Sync housekeeping 2016-07-24 15:48:09 +07:00
Peter Taoussanis
e07ec91f41 Misc housekeeping 2016-07-18 11:50:39 +07:00
Peter Taoussanis
3d8bc0eee1 Experimental: add cache metadata support 2016-07-17 15:42:41 +07:00
Peter Taoussanis
773180ef65 Misc minor optimizations, housekeeping 2016-07-17 15:42:41 +07:00
Peter Taoussanis
f94bc79a01 Hotfix: *final-freeze-fallback* back compatibility was broken 2016-06-17 12:25:31 +07:00
Peter Taoussanis
537b39aba2 Hotfix: fn?s were incorrectly reporting true for serializable? 2016-06-17 12:17:53 +07:00
Peter Taoussanis
4e2c24642f Misc housekeeping 2016-06-10 11:18:55 +07:00
Peter Taoussanis
0df6a7b0f3 Misc hk 2016-05-09 14:05:02 +07:00
Peter Taoussanis
cac9123794 Restore backwards compatibility with Timbre v4.x Carmine appender 2016-04-18 13:36:25 +07:00
Peter Taoussanis
460c20d21f NB Fix missing String. charset 2016-04-14 13:19:58 +07:00
Peter Taoussanis
9a354784ae Remove arg type hints (slower) 2016-04-14 12:16:51 +07:00
Peter Taoussanis
c85329fe05 Cache housekeeping (incl. tests, switch to volatiles) 2016-04-14 12:16:51 +07:00
Peter Taoussanis
414b787684 Add fast-freeze, fast-thaw utils 2016-04-14 12:16:51 +07:00
Peter Taoussanis
3ab91763c6 [#82] Make it easier to spot new->old Nippy thaw failures 2016-04-14 12:16:51 +07:00
Peter Taoussanis
8fda27e996 Disable cache 2016-04-14 12:16:51 +07:00
Peter Taoussanis
699bb7cb51 Experimental support for signed counts 2016-04-14 12:16:51 +07:00
Peter Taoussanis
2028f80854 Experimental caching impl. 2016-04-14 12:16:51 +07:00
Peter Taoussanis
b623b4a8cc NB *BREAKING*: refactor type defs, variable-sized types, etc.
Changes incl:
  - Hid a bunch of undocumented impl. details
  - A number of performance optimizations
2016-04-14 12:16:27 +07:00
Peter Taoussanis
3f43542adb Tools housekeeping 2016-04-13 11:13:01 +07:00