Commit graph

559 commits

Author SHA1 Message Date
Peter Taoussanis
8f71638a19 Officially allow binding config via calls to freeze, thaw, etc. 2020-09-10 22:56:45 +02:00
Peter Taoussanis
25706d09d5 [BREAKING] Standardize :nippy/_ response forms 2020-09-10 22:53:45 +02:00
Peter Taoussanis
b4b5450d97 Serializable: mod whitelist check impl. to match Tufte 2020-09-10 22:53:45 +02:00
Peter Taoussanis
252d898ff1 Misc housekeeping 2020-09-10 22:53:45 +02:00
Peter Taoussanis
ee12b40dde Add auto-size read-str 2020-09-10 22:53:45 +02:00
Peter Taoussanis
421d45b3c3 Bump Encore dep (v3.0.0) 2020-09-10 22:53:43 +02:00
Peter Taoussanis
7464f1e044 [BREAKING] Bump minimum Clojure 1.5->1.7 2020-09-10 12:37:21 +02:00
Peter Taoussanis
ac14ed42b1 v2.15.3 2020-09-10 11:48:45 +02:00
Peter Taoussanis
a90551d40c *serializable-whitelist*: add quarantine test 2020-09-10 11:27:59 +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
7fe200e60a v2.15.2
Encore 1.123.0 introduced an issue affecting Timbre.
Issue was addressed with Encore 2.125.2.

Updating Encore here doesn't affect Nippy, but may be helpful
for users of Nippy that also use Timbre and that haven't otherwise
updated to a newer version of Encore yet.
2020-08-31 09:14:49 +02:00
Peter Taoussanis
aaf54d9c9c v2.15.1 2020-08-27 10:34:48 +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
640c6dbbb0 v2.15.0 2020-07-24 19:24:46 +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
e554dbb1c5 Fix tests path 2020-07-24 17:09:58 +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
809bcdc649 Bump deps 2020-07-23 12:22:27 +02:00
Peter Taoussanis
721b0fb4eb [#120] Update freezable? to cover nil 2020-07-23 12:22:27 +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
649e140889 [Crypto] Add rand-long [n] arity 2019-03-30 13:42:46 +01:00
Peter Taoussanis
ee31c1c64b v2.15.0-RC1 2019-02-16 10:37:51 +01:00
Peter Taoussanis
7ea7bc5247 Bump misc deps 2019-02-16 10:36:19 +01:00
Peter Taoussanis
f955ed9b7e [#116] Update lz4 lib: 1.3->1.5 (@johnmcconnell)
The Maven group had changed, so didn't notice newer versions were
available. Changelog at https://github.com/lz4/lz4-java/blob/master/CHANGES.md#150.
2019-01-19 10:50:37 +01:00
Peter Taoussanis
4dc1e121e9 v2.15.0-alpha9 2019-01-06 14:21:30 +01: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
ae8baa639d [Crypto] Misc housekeeping, prep for next release 2019-01-06 12:24:29 +01:00
Peter Taoussanis
b0c7a0f8c7 [Crypto] Rename some arguments for extra clarity 2019-01-06 12:24:29 +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
d2252d8e21 Bump deps 2019-01-06 12:24:29 +01:00
Peter Taoussanis
5a705ca79e v2.15.0-alpha4 2018-10-07 09:39:28 +02:00
Peter Taoussanis
cfc904799b [Crypto] Rename prng->srng
Better reflects the fact that the source of randomness is now
actually conditional (e.g. via InstanceStrong).
2018-10-07 09:38:48 +02:00
Peter Taoussanis
90f0ff9315 [Crypto] sha512-key-ba: support utf8 *or* ba keys
Minor convenience.
2018-10-06 13:52:45 +02: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
972c637ff4 v2.15.0-alpha3 2018-09-23 19:39:59 +02:00
Peter Taoussanis
e16c64c4f4 [Crypto] Add secure rand-nth fn 2018-09-23 19:38:51 +02:00
Peter Taoussanis
f6c17a7411 [Crypto] Tune prng re-seeding frequency 2018-09-15 22:20:27 +02:00
Peter Taoussanis
bfc65f0970 v2.15.0-alpha2 2018-09-15 12:01:07 +02:00