fromList functions in unordered-containers leak elements between callsA 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
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
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
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")].
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.
-O0 and with -fno-full-laziness.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.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.
Data.HashMap.Lazy.fromList and fromListWith, and
Data.HashMap.Strict.fromList and fromListWith, since 0.2.0.1Data.HashMap.Lazy.fromListWithKey and
Data.HashMap.Strict.fromListWithKey, since their introduction in 0.2.11.0Data.HashSet.fromList, in 0.2.21 onlyThe 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.
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.
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.
Reported by naso-sbl. Fixed by David Feuer and Simon Jakobi.
{
"home": "https://github.com/haskell/security-advisories",
"osvs": "https://raw.githubusercontent.com/haskell/security-advisories/refs/heads/generated/osv-export",
"repository": "https://github.com/haskell/security-advisories"
}"https://github.com/haskell/security-advisories/tree/main/advisories/published/2026/HSEC-2026-0018.md"
"https://raw.githubusercontent.com/haskell/security-advisories/refs/heads/generated/osv-export/2026/HSEC-2026-0018.json"
"https://github.com/haskell/security-advisories/blob/generated/osv-export/2026/HSEC-2026-0018.json"