# HSEC-2026-0018: fromList functions in unordered-containers leak elements between calls

- Severity: not scored yet
- Known to be exploited: not in CISA's catalogue, which lists only what CISA has confirmed
- Published: 2026-11-30T11:59:09.000Z
- Modified: 2026-11-30T12:15:02.503Z

## Description

# `fromList` functions in unordered-containers leak elements between calls

A `HashMap` or `HashSet` built with `fromList` or `fromListWith[Key]` could
contain elements that were passed to other calls of the same function. For
example, with

```haskell
f :: [Key] -> HashSet Key
f xs = HashSet.fromList ([a, b] ++ xs)
```

`f xs` could return a set that also contains elements of `ys` from an earlier
call `f ys`. With `fromListWith[Key]`, values passed to other calls could also
end up combined into the result: with

```haskell
g :: [(Int, String)] -> HashMap Int String
g kvs = HashMap.fromListWith (++) ([(1, "a"), (2, "b")] ++ kvs)
```

three calls of `g [(33, "x")]` returned `"x"`, `"xx"` and `"xxx"` for key 33.

A call could also replace the value of a shared key for all later calls: with

```haskell
h :: [(String, String)] -> HashMap String String
h kvs =
  HashMap.fromListWith const ([("role", "user"), ("theme", "light")] ++ kvs)
```

`h []` returned `"admin"` for `"role"` after a single call
`h [("role", "admin")]`.

## Impact

The results are wrong without any error or warning. A leaked element or a
replaced value is returned by every later call for as long as the shared map
is alive, which is often until the process ends. In a server where the
variable part of the list comes from a request, data from one request can
therefore show up in the results for other requests. A client can plant
elements in the maps or sets built for other clients, and replace the values
of the shared keys, for example defaults that each request is meant to
override for itself only. What follows from that depends on what the
application uses the map or set for.

Leaked elements also accumulate. The shared map grows with every leak, and
with `fromListWith[Key]` so can the values in it, as in the example `g`. A
client that keeps sending new keys can make the process use more and more
memory.

We do not know of an application in which any of this can be exploited.

## Conditions

* The code is compiled with optimizations. In our tests the results were
  correct with `-O0` and with `-fno-full-laziness`.
* The list starts with at least two elements that do not depend on the
  variable part and that have different hashes, as `a` and `b` above. This
  includes a list literal like `[a, b, x]`. A single shared element, as in
  `fromList (a : xs)`, is not enough.
* An element leaks only if its hash places it in a part of the map that the
  shared elements already occupy. With the two shared elements above, roughly
  1 in 16 keys does. An element with the same key as a shared element always
  does.

Whether a given call site goes wrong also depends on GHC's inlining and
optimization decisions, so that similar programs can behave differently. We
have observed wrong results with GHC 8.4.4, 8.10.7, 9.10.3 and 9.14.1, and
none with GHC 7.10.3.

## Affected functions

* `Data.HashMap.Lazy.fromList` and `fromListWith`, and
  `Data.HashMap.Strict.fromList` and `fromListWith`, since 0.2.0.1
* `Data.HashMap.Lazy.fromListWithKey` and
  `Data.HashMap.Strict.fromListWithKey`, since their introduction in 0.2.11.0
* `Data.HashSet.fromList`, in 0.2.21 only

The `IsList` instances are defined with these functions, so
`GHC.Exts.fromList` is affected in the same way: at `HashMap` since the
instance was added in 0.2.5.0, at `HashSet` in 0.2.21 only.

`Data.HashMap.Internal`, `Data.HashMap.Internal.Strict` and
`Data.HashSet.Internal`, which are exposed since 0.2.12.0, export the same
functions.

## Cause

These functions inserted the list elements into the map under construction
in-place, in a pure fold. GHC could therefore build the map for the shared
elements `[a, b]` once and share it between all calls of `f`. Each call then
inserted its `xs` into that shared map. Depending on the hashes of the
elements, some of these insertions modified the shared map, so the inserted
elements also showed up in the results of other calls.

## Fix

Since version 0.2.21.1 each of these functions builds its map entirely in
`ST`, so the in-place inserts of one call can only affect that call's own
map.

Downgrading from 0.2.21 to 0.2.20.1 only helps for `Data.HashSet.fromList`.

## Credits

Reported by naso-sbl. Fixed by David Feuer and Simon Jakobi.

(As written by Haskell Security Advisories.)

## Affected

- unordered-containers (Hackage): from 0.2.0.1 before 0.2.21.1

## References

- <https://github.com/haskell-unordered-containers/unordered-containers/issues/601> (report)
- <https://github.com/haskell-unordered-containers/unordered-containers/pull/602> (fix)
- <https://github.com/haskell-unordered-containers/unordered-containers/commit/7e08bbe7916b1cbafbea9470c069823c91f7a2dd> (introduced)
- <https://github.com/haskell-unordered-containers/unordered-containers/commit/e67e3c7b3e849b63c8dd577cc058937b35b5270c> (introduced)
- <https://github.com/haskell-unordered-containers/unordered-containers/commit/0d0697e597f6b53eeb2f82aa1321f5f63d784682> (introduced)

## Sources

- Haskell Security Advisories: [HSEC-2026-0018](https://osv.dev/vulnerability/HSEC-2026-0018), CC0-1.0, modified 2026-11-30

---

Page: https://cve.day/HSEC-2026-0018 · Whole record: https://cve.day/HSEC-2026-0018.json · Rebuilt by cve.day 2026-11-30T12:37:24.831Z
