HSEC-2026-0018

Vulnerability from osv_haskell – Published: 2026-11-30 11:59 – Updated: 2026-11-30 11:59 – Source website
VLAI
Summary
fromList functions in unordered-containers leak elements between calls
Details

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

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")].

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.

Impacted products
Ecosystem Package Version
Hackage unordered-containers
Affected: ≥ 0.2.0.1, < 0.2.21.1 (ecosystem)

{
  "affected": [
    {
      "database_specific": {
        "human_link": "https://github.com/haskell/security-advisories/tree/main/advisories/published/2026/HSEC-2026-0018.md",
        "osv": "https://raw.githubusercontent.com/haskell/security-advisories/refs/heads/generated/osv-export/2026/HSEC-2026-0018.json"
      },
      "package": {
        "ecosystem": "Hackage",
        "name": "unordered-containers"
      },
      "ranges": [
        {
          "events": [
            {
              "introduced": "0.2.0.1"
            },
            {
              "fixed": "0.2.21.1"
            }
          ],
          "type": "ECOSYSTEM"
        }
      ],
      "severity": [
        {
          "score": "CVSS:3.1/AV:N/AC:H/PR:N/UI:N/S:U/C:L/I:L/A:L",
          "type": "CVSS_V3"
        }
      ]
    }
  ],
  "database_specific": {
    "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"
  },
  "details": "# `fromList` functions in unordered-containers leak elements between calls\n\nA `HashMap` or `HashSet` built with `fromList` or `fromListWith[Key]` could\ncontain elements that were passed to other calls of the same function. For\nexample, with\n\n```haskell\nf :: [Key] -\u003e HashSet Key\nf xs = HashSet.fromList ([a, b] ++ xs)\n```\n\n`f xs` could return a set that also contains elements of `ys` from an earlier\ncall `f ys`. With `fromListWith[Key]`, values passed to other calls could also\nend up combined into the result: with\n\n```haskell\ng :: [(Int, String)] -\u003e HashMap Int String\ng kvs = HashMap.fromListWith (++) ([(1, \"a\"), (2, \"b\")] ++ kvs)\n```\n\nthree calls of `g [(33, \"x\")]` returned `\"x\"`, `\"xx\"` and `\"xxx\"` for key 33.\n\nA call could also replace the value of a shared key for all later calls: with\n\n```haskell\nh :: [(String, String)] -\u003e HashMap String String\nh kvs =\n  HashMap.fromListWith const ([(\"role\", \"user\"), (\"theme\", \"light\")] ++ kvs)\n```\n\n`h []` returned `\"admin\"` for `\"role\"` after a single call\n`h [(\"role\", \"admin\")]`.\n\n## Impact\n\nThe results are wrong without any error or warning. A leaked element or a\nreplaced value is returned by every later call for as long as the shared map\nis alive, which is often until the process ends. In a server where the\nvariable part of the list comes from a request, data from one request can\ntherefore show up in the results for other requests. A client can plant\nelements in the maps or sets built for other clients, and replace the values\nof the shared keys, for example defaults that each request is meant to\noverride for itself only. What follows from that depends on what the\napplication uses the map or set for.\n\nLeaked elements also accumulate. The shared map grows with every leak, and\nwith `fromListWith[Key]` so can the values in it, as in the example `g`. A\nclient that keeps sending new keys can make the process use more and more\nmemory.\n\nWe do not know of an application in which any of this can be exploited.\n\n## Conditions\n\n* The code is compiled with optimizations. In our tests the results were\n  correct with `-O0` and with `-fno-full-laziness`.\n* The list starts with at least two elements that do not depend on the\n  variable part and that have different hashes, as `a` and `b` above. This\n  includes a list literal like `[a, b, x]`. A single shared element, as in\n  `fromList (a : xs)`, is not enough.\n* An element leaks only if its hash places it in a part of the map that the\n  shared elements already occupy. With the two shared elements above, roughly\n  1 in 16 keys does. An element with the same key as a shared element always\n  does.\n\nWhether a given call site goes wrong also depends on GHC\u0027s inlining and\noptimization decisions, so that similar programs can behave differently. We\nhave observed wrong results with GHC 8.4.4, 8.10.7, 9.10.3 and 9.14.1, and\nnone with GHC 7.10.3.\n\n## Affected functions\n\n* `Data.HashMap.Lazy.fromList` and `fromListWith`, and\n  `Data.HashMap.Strict.fromList` and `fromListWith`, since 0.2.0.1\n* `Data.HashMap.Lazy.fromListWithKey` and\n  `Data.HashMap.Strict.fromListWithKey`, since their introduction in 0.2.11.0\n* `Data.HashSet.fromList`, in 0.2.21 only\n\nThe `IsList` instances are defined with these functions, so\n`GHC.Exts.fromList` is affected in the same way: at `HashMap` since the\ninstance was added in 0.2.5.0, at `HashSet` in 0.2.21 only.\n\n`Data.HashMap.Internal`, `Data.HashMap.Internal.Strict` and\n`Data.HashSet.Internal`, which are exposed since 0.2.12.0, export the same\nfunctions.\n\n## Cause\n\nThese functions inserted the list elements into the map under construction\nin-place, in a pure fold. GHC could therefore build the map for the shared\nelements `[a, b]` once and share it between all calls of `f`. Each call then\ninserted its `xs` into that shared map. Depending on the hashes of the\nelements, some of these insertions modified the shared map, so the inserted\nelements also showed up in the results of other calls.\n\n## Fix\n\nSince version 0.2.21.1 each of these functions builds its map entirely in\n`ST`, so the in-place inserts of one call can only affect that call\u0027s own\nmap.\n\nDowngrading from 0.2.21 to 0.2.20.1 only helps for `Data.HashSet.fromList`.\n\n## Credits\n\nReported by naso-sbl. Fixed by David Feuer and Simon Jakobi.\n",
  "id": "HSEC-2026-0018",
  "modified": "2026-11-30T11:59:09Z",
  "published": "2026-11-30T11:59:09Z",
  "references": [
    {
      "type": "REPORT",
      "url": "https://github.com/haskell-unordered-containers/unordered-containers/issues/601"
    },
    {
      "type": "FIX",
      "url": "https://github.com/haskell-unordered-containers/unordered-containers/pull/602"
    },
    {
      "type": "INTRODUCED",
      "url": "https://github.com/haskell-unordered-containers/unordered-containers/commit/7e08bbe7916b1cbafbea9470c069823c91f7a2dd"
    },
    {
      "type": "INTRODUCED",
      "url": "https://github.com/haskell-unordered-containers/unordered-containers/commit/e67e3c7b3e849b63c8dd577cc058937b35b5270c"
    },
    {
      "type": "INTRODUCED",
      "url": "https://github.com/haskell-unordered-containers/unordered-containers/commit/0d0697e597f6b53eeb2f82aa1321f5f63d784682"
    }
  ],
  "schema_version": "1.5.0",
  "summary": "fromList functions in unordered-containers leak elements between calls"
}



Log in or create an account to share your comment.




Tags
Taxonomy of the tags.


Loading…

Loading…

Loading…

Drag nodes to arrange them. Double-click a related vulnerability to open it, or a source to visit its link. The Physics button on the left tunes the layout and the simulation; the legend at the bottom left hides or shows nodes by kind and by sighting type.

Forecast uses a logistic model when the trend is rising, or an exponential decay model when the trend is falling. Fitted via linearized least squares.

Sightings

Author Source Type Date Other

Nomenclature

  • Seen: The vulnerability was mentioned, discussed, or observed by the user.
  • Confirmed: The vulnerability has been validated from an analyst's perspective.
  • Published Proof of Concept: A public proof of concept is available for this vulnerability.
  • Exploited: The vulnerability was observed as exploited by the user who reported the sighting.
  • Patched: The vulnerability was observed as successfully patched by the user who reported the sighting.
  • Not exploited: The vulnerability was not observed as exploited by the user who reported the sighting.
  • Not confirmed: The user expressed doubt about the validity of the vulnerability.
  • Not patched: The vulnerability was not observed as successfully patched by the user who reported the sighting.
Vulnerability timeline

Sightings and recorded dates, grouped by day · UTC

JSON
How durations are calculated

Following the VTEM framework (Black Hat USA 2015), time to patch starts when the vendor or a coordinator was informed, total time to patch at discovery, and disclosure to patch at public disclosure; vendor response time runs from the report to its acknowledgement. Time to exploit and time unpatched start at the earliest discovery or report, falling back to public disclosure. Unpatched time ends at the first recorded patch, or the calculation time when no patch is recorded. Exploitation to patch shows the interval between those two events; a published proof of concept is a public exploit, not exploitation. The method is described in a publication.

Each result shows its source dates. A negative interval means the end event came first; when date-only inputs leave the order open, the result says so. Date-only inputs are approximate. The earliest evidence wins: KEV report dates and sightings are labelled as such. Records describing another vulnerability are listed but never calculated from, and a PoC alone does not establish exploitation. Missing patch evidence does not prove that no patch exists. Filters below change the event list only.

Events included in the timeline

Loading timeline…


    Loading…

    Loading…

    Loading…

    Related by attack behaviour

    Vulnerabilities whose description is nearest to this one in the vector space of the CIRCL/vulnerability-attack-technique-biencoder model. This is a similarity search over the bi-encoder space (plain cosine), not a classification, and it has no measured accuracy.