Skip to content

chore(deps): update dependency immutable to v4 [security]#2832

Open
renovate[bot] wants to merge 1 commit into
mainfrom
renovate/npm-immutable-vulnerability
Open

chore(deps): update dependency immutable to v4 [security]#2832
renovate[bot] wants to merge 1 commit into
mainfrom
renovate/npm-immutable-vulnerability

Conversation

@renovate

@renovate renovate Bot commented Jul 21, 2026

Copy link
Copy Markdown
Contributor

This PR contains the following updates:

Package Change Age Confidence
immutable (source) 3.8.34.3.9 age confidence

Immutable.js List 32-bit trie overflow → unrecoverable DoS

CVE-2026-59879 / GHSA-v56q-mh7h-f735

More information

Details

Summary

List#set, List#setSize, List#setIn, List#updateIn (and the functional set / setIn / updateIn) mishandle an index or size in the range [2 ** 30, 2 ** 31):

  • On an empty List the operation enters an uncatchable infinite loop (a tight CPU spin; a surrounding try/catch never regains control). Only killing the worker recovers it.
  • On a populated List (≥ 32 elements — i.e. any array of ≥ 32 items turned into a List by fromJS) the loop allocates without bound → heap exhaustion → the process aborts (SIGABRT, exit 134, or kernel OOM-kill 137). A real crash, not a recoverable error.

The index may be a numeric string, so it can come straight from a request body, URL, or key-path. A single small unauthenticated request is enough.

There is also a companion silent data-corruption issue in setSize:

List([1, 2, 3]).setSize(2 ** 31); // before fix => size 0  (silently cleared)
List([1, 2, 3]).setSize(2 ** 32 + 5); // before fix => size 5  (huge value wraps to 5)
Impact

Availability only. A reachable configuration is any endpoint that routes untrusted input into a List index or a setIn/updateIn key-path — which the extremely common state = fromJS(body); state.setIn(userPath, value) pattern does (config stores, document/collection editors, redux-immutable reducers, JSON-Patch endpoints, etc.).

No confidentiality or integrity impact, no RCE. The companion setSize bug can silently corrupt application state (wrong size) without crashing.

Reproduction (immutable 5.1.7)
import { fromJS, List } from 'immutable';

// 1) Populated List: OOM -> process abort (SIGABRT, exit 134) within ~2s
fromJS({ items: new Array(64).fill(0) }).setIn(['items', '1073741824'], 'x');

// 2) Empty List: hangs forever, uncatchable
List().set(2 ** 30, 'x');

// 3) Silent truncation
List([1, 2, 3]).setSize(2 ** 31); // => size 0
List([1, 2, 3]).setSize(2 ** 32 + 5); // => size 5

A remote 43-byte HTTP request ({"path":["items","1073741824"],"value":"x"}) is sufficient to abort a worker that applies it via state = state.setIn(path, value).

Any index in [2 ** 30, 2 ** 31) works (1073741824, 2000000000, …). An index in [2 ** 31, 2 ** 32) does not crash — it silently wraps (clearing the List) via the same root cause.

Root cause

List stores its values in a 32-wide trie (SHIFT = 5, so each level addresses 5 more bits) and uses signed 32-bit bitwise arithmetic throughout setListBounds() (src/List.js):

  1. Infinite loop (the hang / OOM). The level-raising loop
while (newTailOffset >= 1 << (newLevel + SHIFT)) {
  newRoot = new VNode(
    newRoot && newRoot.array.length ? [newRoot] : [],
    owner
  );
  newLevel += SHIFT;
}

relies on 1 << (newLevel + SHIFT). A JavaScript shift count is taken mod 32, so once newLevel + SHIFT reaches 31 the term goes negative (1 << 31 === -2147483648) and at 32 wraps to 1 (1 << 35 === 8). The comparison then stays true forever and the loop never terminates. On a populated List, each iteration retains a new VNode ([newRoot]), so the heap fills and V8 aborts; on an empty List it spins on CPU without allocating.

  1. Silent wraparound (the setSize corruption). The begin |= 0 / end |= 0 coercion (ToInt32) silently wraps large finite values ((2 ** 31) | 0 === -2147483648, (2 ** 32 + 5) | 0 === 5), producing a wrong resulting size instead of an error.

The threshold is 2 ** 30: that is the largest size for which 1 << (newLevel + SHIFT) stays a valid positive 32-bit integer throughout the loops (newLevel + SHIFT stays ≤ 30).

Remediation

The fix is contained to setListBounds() in src/List.js:

  1. Validate up front, before the lossy | 0 coercion. Compute the intended origin and capacity in full precision and throw a clear, catchable RangeError when they exceed the addressable range (MAX_LIST_SIZE = 2 ** 30). Infinity/NaN are left to the existing | 0 → 0 behaviour (so setSize(Infinity) stays 0 and slice(0, Infinity) still means "to the end").

  2. Stop the shift from wrapping. Replace 1 << exp in the level-raising loops with a helper that uses the cheap bitwise shift while it is exact (exp ≤ 30, the common path including every push/setSize/slice) and falls back to the non-wrapping 2 ** exp only for the rare deep trees reached when a negative origin (unshift / negative index) is normalized to a large positive capacity (exp can reach 35 there, where 1 << 35 would wrap to 8).

This turns every hang, the misleading "Maximum call stack size exceeded", the OOM/SIGABRT, and the silent setSize truncation into one descriptive RangeError, preserves all behaviour for sizes < 2 ** 30, and keeps the hot push path on the fast bitwise shift (the 2 ** exp branch is never reached by non-negative operations).

Is the new limit a breaking change?

No working code is affected. A List could never actually hold ≥ 2 ** 30 values before — the attempt hung, crashed, or silently corrupted the size. The limit was already implicit in the 32-bit trie; the fix only makes it explicit and catchable, mirroring native JS arrays (new Array(2 ** 32)RangeError: Invalid array length). The single observable behaviour change is that setSize(hugeValue), which used to return a silently wrong size, now throws. 2 ** 30 ≈ 1.07 billion entries (~8 GB of pointers alone), far beyond any practical use.

Mitigations (for users who cannot upgrade immediately)
  • Validate/clamp any externally supplied List index or setIn/updateIn key-path segment against a sane maximum before passing it to immutable.
  • Reject numeric path segments ≥ 2 ** 30.
  • Run request handling in a worker that can be restarted, and cap the heap (--max-old-space-size) so an abort is contained.

Severity

  • CVSS Score: 8.7 / 10 (High)
  • Vector String: CVSS:4.0/AV:N/AC:L/AT:N/PR:N/UI:N/VC:N/VI:N/VA:H/SC:N/SI:N/SA:N

References

This data is provided by OSV and the GitHub Advisory Database (CC-BY 4.0).


Immutabl: Hash-collision algorithmic complexity denial of service in Immutable.Map/Set

CVE-2026-59880 / GHSA-xvcm-6775-5m9r

More information

Details

Summary

Immutable.Map and Immutable.Set keep keys that share the same 32-bit hash in a collision bucket that is scanned linearly. The string hash is public and deterministic, so an attacker who controls the keys inserted into a Map can craft many keys that all collide, degrading insertion and lookup from amortized O(1) to O(n) per operation — and O(n²) to build or read the whole set. A small, attacker-shaped payload can therefore consume disproportionate CPU and, on a single-threaded runtime such as Node.js, stall the event loop and deny service.

Details

The string hash uses the JVM-style polynomial hashed = (31 * hashed + charCode) | 0. Strings such as "Aa" and "BB" hash to the same value (65*31+97 == 66*31+66 == 2112), and concatenating such blocks yields 2^n distinct strings sharing one hash (40 characters ⇒ >1,000,000 colliding keys).
All such keys route to a single HashCollisionNode, whose get/update walk the entire bucket testing is(). There is no per-process salt, so the colliding set is fully precomputable from the open-source algorithm.

Proof of concept

Inserting N colliding keys (e.g. via Immutable.Map(obj) / Immutable.fromJS(obj)) is O(N²). Measured on one machine, ~8,000 colliding
keys take ~0.7 s to build and ~0.6 s to read, scaling ×4 per doubling; ~16,000 keys exceed several seconds.

Impact

CPU-bound denial of service in applications that ingest attacker-controlled object keys into Immutable structures, e.g. Immutable.Map(req.body), Immutable.fromJS(req.body), state.merge(userObject) / mergeDeep(...). Applications that only store attacker input as values under fixed keys are not affected.

Affected versions

All versions through 5.1.7 (the deterministic string hash and linear collision bucket have existed since the 4.x line).

Patches

Fixed in 5.1.8 (adjust to the actual release): large collision buckets are indexed by a per-process seeded secondary hash, restoring near-linear behavior for the affected paths. The public hash() is unchanged (no breaking change), and is() remains the sole authority on key equality.

Workarounds

Before passing untrusted data to Immutable.js: cap request body size, limit object key count/length, and reject high-cardinality payloads; avoid building Maps directly from untrusted object keys.

References
  • CWE-407 (Inefficient Algorithmic Complexity), CWE-400 (Uncontrolled Resource Consumption)
  • OWASP API4:2023 (Unrestricted Resource Consumption)

Severity

  • CVSS Score: 8.7 / 10 (High)
  • Vector String: CVSS:4.0/AV:N/AC:L/AT:N/PR:N/UI:N/VC:N/VI:N/VA:H/SC:N/SI:N/SA:N

References

This data is provided by OSV and the GitHub Advisory Database (CC-BY 4.0).


Release Notes

immutable-js/immutable-js (immutable)

v4.3.9

Compare Source

v4.3.8

Compare Source

Fix Improperly Controlled Modification of Object Prototype Attributes ('Prototype Pollution') in immutable

v4.3.7

Compare Source

v4.3.6

Compare Source

v4.3.5

Compare Source

v4.3.4

Compare Source

v4.3.3

Compare Source

v4.3.2

Compare Source

  • [TypeScript] Fix isOrderedSet type #​1948

v4.3.1

Compare Source

  • Faster and implementation of some #​1944
  • [internal] remove unused exports #​1928

v4.3.0

Compare Source

v4.2.4

Compare Source

v4.2.3

Compare Source

  • [TypeScript] groupBy return either a Map or an OrderedMap: make the type more precise than base Collection #​1924

v4.2.2

Compare Source

v4.2.1

Compare Source

  • [Typescript] rollback some of the change on toJS to avoir circular reference

v4.2.0

Compare Source

  • [TypeScript] Better type for toJS #​1917 by jdeniau
    • [TS Minor Break] tests are ran with TS > 4.5 only. It was tested with TS > 2.1 previously, but we want to level up TS types with recent features. TS 4.5 has been released more than one year before this release. If it does break your implementation (it might not), you should probably consider upgrading to the latest TS version.
  • Added a partition method to all containers #​1916 by johnw42

v4.1.0

Compare Source

v4.0.0

Compare Source

This release brings new functionality and many fixes.

  1. Key changes
  2. Note for users of v4.0.0-rc.12
  3. Breaking changes
  4. New
  5. Fixed
Key changes
   Diff of changed API (click to expand)
+  Collection.[Symbol.iterator]
+  Collection.toJSON
+  Collection.update
+  Collection.Indexed.[Symbol.iterator]
+  Collection.Indexed.toJSON
+  Collection.Indexed.update
+  Collection.Indexed.zipAll
+  Collection.Keyed.[Symbol.iterator]
+  Collection.Keyed.toJSON
+  Collection.Keyed.update
+  Collection.Set.[Symbol.iterator]
+  Collection.Set.toJSON
+  Collection.Set.update
-  Collection.size
-  Collection.Indexed.size
-  Collection.Keyed.size
-  Collection.Set.size

+  List.[Symbol.iterator]
+  List.toJSON
+  List.wasAltered
+  List.zipAll
-  List.mergeDeep
-  List.mergeDeepWith
-  List.mergeWith

+  Map.[Symbol.iterator]
+  Map.deleteAll
+  Map.toJSON
+  Map.wasAltered

+  OrderedMap.[Symbol.iterator]
+  OrderedMap.deleteAll
+  OrderedMap.toJSON
+  OrderedMap.wasAltered
+  OrderedSet.[Symbol.iterator]
+  OrderedSet.toJSON
+  OrderedSet.update
+  OrderedSet.wasAltered
+  OrderedSet.zip
+  OrderedSet.zipAll
+  OrderedSet.zipWith

+  Record.[Symbol.iterator]
+  Record.asImmutable
+  Record.asMutable
+  Record.clear
+  Record.delete
+  Record.deleteIn
+  Record.merge
+  Record.mergeDeep
+  Record.mergeDeepIn
+  Record.mergeDeepWith
+  Record.mergeIn
+  Record.mergeWith
+  Record.set
+  Record.setIn
+  Record.toJSON
+  Record.update
+  Record.updateIn
+  Record.wasAltered
+  Record.withMutations
+  Record.Factory.displayName
-  Record.butLast
-  Record.concat
-  Record.count
-  Record.countBy
-  Record.entries
-  Record.entrySeq
-  Record.every
-  Record.filter
-  Record.filterNot
-  Record.find
-  Record.findEntry
-  Record.findKey
-  Record.findLast
-  Record.findLastEntry
-  Record.findLastKey
-  Record.first
-  Record.flatMap
-  Record.flatten
-  Record.flip
-  Record.forEach
-  Record.groupBy
-  Record.includes
-  Record.isEmpty
-  Record.isSubset
-  Record.isSuperset
-  Record.join
-  Record.keyOf
-  Record.keySeq
-  Record.keys
-  Record.last
-  Record.lastKeyOf
-  Record.map
-  Record.mapEntries
-  Record.mapKeys
-  Record.max
-  Record.maxBy
-  Record.min
-  Record.minBy
-  Record.reduce
-  Record.reduceRight
-  Record.rest
-  Record.reverse
-  Record.skip
-  Record.skipLast
-  Record.skipUntil
-  Record.skipWhile
-  Record.slice
-  Record.some
-  Record.sort
-  Record.sortBy
-  Record.take
-  Record.takeLast
-  Record.takeUntil
-  Record.takeWhile
-  Record.toArray
-  Record.toIndexedSeq
-  Record.toKeyedSeq
-  Record.toList
-  Record.toMap
-  Record.toOrderedMap
-  Record.toOrderedSet
-  Record.toSet
-  Record.toSetSeq
-  Record.toStack
-  Record.valueSeq
-  Record.values

+  Seq.[Symbol.iterator]
+  Seq.toJSON
+  Seq.update
+  Seq.Indexed.[Symbol.iterator]
+  Seq.Indexed.toJSON
+  Seq.Indexed.update
+  Seq.Indexed.zipAll
+  Seq.Keyed.[Symbol.iterator]
+  Seq.Keyed.toJSON
+  Seq.Keyed.update
+  Seq.Set.[Symbol.iterator]
+  Seq.Set.toJSON
+  Seq.Set.update

+  Set.[Symbol.iterator]
+  Set.toJSON
+  Set.update
+  Set.wasAltered

+  Stack.[Symbol.iterator]
+  Stack.toJSON
+  Stack.update
+  Stack.wasAltered
+  Stack.zipAll

+  ValueObject.equals
+  ValueObject.hashCode

-  Iterable.*
-  Iterable.Indexed.*
-  Iterable.Keyed.*
-  Iterable.Set.*
Note for users of v4.0.0-rc.12

There were mostly bugfixes and improvements since RC 12. Upgrading should be painless for most users.
However, there is one breaking change: The behavior of merge and mergeDeep has changed. See below for details.

BREAKING
merge()
  • No longer use value-equality within merge() (#​1391)

    This rectifies an inconsistent behavior between x.merge(y) and x.mergeDeep(y) where merge would
    use === on leaf values to determine return-self optimizations, while mergeDeep would use is().
    This improves consistency across the library and avoids a possible performance pitfall.

  • No longer deeply coerce argument to merge() (#​1339)

    Previously, the argument provided to merge() was deeply converted to Immutable collections via fromJS().
    This was the only function in the library which calls fromJS() indirectly,
    and it was surprising and made it difficult to understand what the result of merge() would be.
    Now, the value provided to merge() is only shallowly converted to an Immutable collection, similar to
    related methods in the library. This may change the behavior of your calls to merge().

mergeDeep()
  • Replace incompatible collections when merging nested data (#​1840)

    It will no longer merge lists of tuples into maps. For more information see
    #​1840 and the updated mergeDeep() documentation.

  • Concat Lists when merging deeply (#​1344)

    Previously, calling map.mergeDeep() with a value containing a List would replace the values in the
    original List. This has always been confusing, and does not properly treat List as a monoid.
    Now, List.merge is simply an alias for List.concat, and map.mergeDeep() will concatenate deeply-found lists
    instead of replacing them.

Seq
  • Remove IteratorSequence. Do not attempt to detect iterators in Seq(). (#​1589)

    Iterables can still be provided to Seq(), and most Iterators are also
    Iterables, so this change should not affect the vast majority of uses.
    For more information, see PR #​1589

  • Remove Seq.of() (#​1311, #​1310)

    This method has been removed since it cannot be correctly typed. It's recommended to convert
    Seq.of(1, 2, 3) to Seq([1, 2, 3]).

isImmutable()
  • isImmutable() now returns true for collections currently within a withMutations() call. (#​1374)

    Previously, isImmutable() did double-duty of both determining if a value was a Collection or Record
    from this library as well as if it was outside a withMutations() call.
    This latter case caused confusion and was rarely used.

toArray()
  • KeyedCollection.toArray() returns array of tuples. (#​1340)

    Previously, calling toArray() on a keyed collection (incl Map and OrderedMap) would
    discard keys and return an Array of values. This has always been confusing, and differs from Array.from().
    Now, calling toArray() on a keyed collection will return an Array of [key, value] tuples, matching
    the behavior of Array.from().

concat()
  • list.concat() now has a slightly more efficient implementation and map.concat() is an alias for map.merge(). (#​1373)

    In rare cases, this may affect use of map.concat() which expected slightly different behavior from map.merge().

Collection, formerly Iterable
  • The Iterable class has been renamed to Collection, and isIterable() has been renamed to isCollection().
    Aliases with the existing names exist to make transitioning code easier.
Record
  • Record is no longer an Immutable Collection type.
    • Now isCollection(myRecord) returns false instead of true.
    • The sequence API (such as map, filter, forEach) no longer exist on Records.
    • delete() and clear() no longer exist on Records.
Other breaking changes
  • Potentially Breaking: Improve hash speed and avoid collision for common values (#​1629)

    Causes some hash values to change, which could impact the order of iteration of values in some Maps
    (which are already advertised as unordered, but highlighting just to be safe)

  • Node buffers no longer considered value-equal (#​1437)

  • Plain Objects and Arrays are no longer considered opaque values (#​1369)

    This changes the behavior of a few common methods with respect to plain Objects and Arrays where these were
    previously considered opaque to merge() and setIn(), they now are treated as collections and can be merged
    into and updated (persistently). This offers an exciting alternative to small Lists and Records.

  • The "predicate" functions, isCollection, isKeyed, isIndexed, isAssociative have been moved from Iterable. to the top level exports.

  • The toJSON() method performs a shallow conversion (previously it was an alias for toJS(), which remains a deep conversion).

  • Some minor implementation details have changed, which may require updates to libraries which deeply integrate with Immutable.js's private APIs.

  • The Cursor API is officially deprecated. Use immutable-cursor instead.

  • Potentially Breaking: [TypeScript] Remove Iterable<T> as tuple from Map constructor types (#​1626)

    Typescript allowed constructing a Map with a list of List instances, assuming each was a key, value pair.
    While this runtime behavior still works, this type led to more issues than it solved, so it has been removed.
    (Note, this may break previous v4 rcs, but is not a change against v3)

New
  • Update TypeScript and Flow definitions:
    • The Flowtype and TypeScript type definitions have been completely rewritten with much higher quality and accuracy,
      taking advantage of the latest features from both tools.
    • Simplified TypeScript definition files to support all UMD use cases (#​1854)
    • Support Typescript 3 (#​1593)
    • Support Typescript strictNullChecks (#​1168)
    • Flow types to be compatible with the latest version 0.160.0
    • Enable flow strict (#​1580)
  • Add "sideEffects: false" to package.json (#​1661)

  • Use ES standard for iterator method reuse (#​1867)

  • Generalize fromJS() and Seq() to support Sets (#​1865)

  • Top level predicate functions (#​1600)

    New functions are exported from the immutable module:
    isSeq(), isList(), isMap(), isOrderedMap(), isStack(), isSet(), isOrderedSet(), and isRecord().

  • Improve performance of toJS (#​1581)

    Cursory test is >10% faster than both v3.8.2 and v4.0.0-rc.7,
    and corrects the regression since v4.0.0-rc.9.

  • Added optional notSetValue in first() and last() (#​1556)

  • Make isArrayLike check more precise to avoid false positives (#​1520)

  • map() for List, Map, and Set returns itself for no-ops (#​1455) (5726bd1)

  • Hash functions as objects, allowing functions as values in collections (#​1485)

  • Functional API for get(), set(), and more which support both Immutable.js collections and plain Objects and Arrays (#​1369)

  • Relicensed as MIT (#​1320)

  • Support for Transducers! (ee9c68f1)

  • Add new method, zipAll() (#​1195)

  • Bundle and distribute an "es module" so Webpack and Rollup can use tree-shaking for smaller builds (#​1204)

  • Warn instead of throw when getIn() has a bad path (668f2236)

  • A new predicate function isValueObject() helps to detect objects which implement equals() and hashCode(),
    and type definitions now define the interface ValueObject which you can implement in your own code to create objects which
    behave as values and can be keys in Maps or entries in Sets.

  • Using fromJS() with a "reviver" function now provides access to the key path to each translated value. (#​1118)

Fixed
  • Fix issue with IE11 and missing Symbol.iterator (#​1850)

  • Fix ordered set with map (#​1663)

  • Do not modify iter during List.map and Map.map (#​1649)

  • Fix ordered map delete all (#​1777)

  • Hash symbols as objects (#​1753)

  • Fix returning a Record in merge() when Record is empty (#​1785)

  • Fix for RC~12: Records from different factories aren't equal (#​1734)

  • "too much recursion" error when creating a Record type from an instance of another Record (#​1690)

  • Fix glob for npm format script on Windows (#​18)

  • Remove deprecated cursor API (#​13)

  • Add missing es exports (#​1740)

  • Support nulls in genTypeDefData.js (#​185)

  • Support isPlainObj in IE11 and other esoteric parameters f3a6d5ce

  • Set.map produces valid underlying map (#​1606)

  • Support isPlainObj with constructor key (#​1627)

  • groupBy no longer returns a mutable Map instance (#​1602)

  • Fix issue where refs can recursively collide, corrupting .size (#​1598)

  • Throw error in mergeWith() method if missing the required merger function (#​1543)

  • Update isPlainObj() to workaround Safari bug and allow cross-realm values (#​1557)

  • Fix missing "& T" to some methods in RecordInstance (#​1464)

  • Make notSetValue optional for typed Records (#​1461) (a1029bb)

  • Export type of RecordInstance (#​1434)

  • Fix Record size check in merge() (#​1521)

  • Fix Map#concat being not defined (#​1402)

  • getIn() no longer throws when encountering a missing path (#​1361)
  • Do not throw when printing value that cannot be coerced to primitive (#​1334)
  • Do not throw from hasIn (#​1319)

  • Long hash codes no longer cause an infinite loop (#​1175)

  • slice() which should return an empty set could return a full set or vice versa (#​1245, #​1287)

  • Ensure empty slices do not throw when iterated (#​1220)

  • Error during equals check on Record with undefined or null (#​1208)

  • Fix size of count() after filtering or flattening (#​1171)


Configuration

📅 Schedule: (in timezone Europe/Zurich)

  • Branch creation
    • At any time (no schedule defined)
  • Automerge
    • At any time (no schedule defined)

🚦 Automerge: Disabled by config. Please merge this manually once you are satisfied.

Rebasing: Whenever PR becomes conflicted, or you tick the rebase/retry checkbox.

🔕 Ignore: Close this PR and you won't be reminded about this update again.


  • If you want to rebase/retry this PR, check this box

This PR was generated by Mend Renovate. View the repository job log.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

0 participants