# GHSA-F8F4-95Q3-38QW: @rhinostone/swig-twig excessive memory allocation

- Database: GitHub
- Severity: CVSS 7.5 (High)
- Published: 2026-10-24
- Modified: 2026-10-24

## Affected versions

- @rhinostone/swig-twig (npm): from 2.0.0-alpha.3, fixed in 2.9.2
- @rhinostone/swig-jinja2 (npm): from 2.5.0, fixed in 2.9.2
- @rhinostone/swig-core (npm): from 2.0.0-alpha.5, fixed in 2.9.2

## Description

### Overview
Three template features built an array whose length came from a number in the data supplied at render time (template locals), with no upper limit:

1. swig-twig ranges `a..b` (the range helper in @rhinostone/swig-core) build one element per value from `a` to `b`, so a bound such as `1e8` built an array of 100 million numbers. A range whose values reach 2^53 (9007199254740992) never ended: from 2^53 on, adding 1 no longer changes a JavaScript number, so the loop kept adding the same value. 2.8.2 made a range with an infinite bound empty (GHSA-48rg-vg49-r5vm), but a bound at or beyond 2^53 still never ended.
2. `batch` in swig-twig and swig-jinja2 pads the last chunk up to the batch size when a fill value is given, so a size such as `1e8` built a chunk of that length.
3. swig-jinja2 `slice` builds one column per count, so a count such as `1e7` built that many columns.

The array grows until the V8 heap limit, and the process then aborts with "JavaScript heap out of memory", which a program cannot catch. Under a 256 MB heap each of these aborted the process within a second (a `slice` count of `1e7`, the other sizes `1e8`). With a larger heap a larger number is needed, except for a range whose values reach 2^53, which aborts the process whatever the heap.

### Impact
Availability only (no confidentiality or integrity impact). In an application that passes a number from the request into a swig-twig range bound, a `batch` size or a swig-jinja2 `slice` count, a single request can abort the Node.js process.

### Affected & patched
- @rhinostone/swig-twig >= 2.0.0-alpha.3, < 2.9.2: `batch` with a fill value since 2.0.0-alpha.3, ranges (`a..b`) since 2.0.0-alpha.5.
- @rhinostone/swig-jinja2 >= 2.5.0, < 2.9.2: `slice`, and `batch` with a fill value.
- @rhinostone/swig-core >= 2.0.0-alpha.5, < 2.9.2: the range helper behind swig-twig's `a..b`.

@rhinostone/swig and @rhinostone/swig-django have none of these features and are not affected.

Fixed in 2.9.2: a range of more than 1,000,000 elements is empty, as for an infinite bound, which includes a range whose values reach 2^53; swig-jinja2 `slice` with more than 1,000,000 columns returns an empty list, as for an infinite count; and `batch` leaves the last chunk unpadded for a size above 1,000,000. Smaller ranges, slices and batches are unchanged. The 2.9.2 frontends require @rhinostone/swig-core 2.9.2, so upgrade the packages together.

### Workarounds
- Upgrade to 2.9.2 or later.
- Otherwise, limit numbers taken from untrusted data before they reach a range bound, a `batch` size or a `slice` count, for example to between -1,000,000 and 1,000,000.

### References
- swig-core range helper and swig-twig — https://github.com/gina-io/swig/commit/7288240dd7d08b08946d182054588cde9b2e6f6a
- swig-jinja2 — https://github.com/gina-io/swig/commit/02f1d10ba7eabf45a12ea34b55b3fbb62b9caf85
- Release notes — https://github.com/gina-io/swig/blob/v2.9.2/HISTORY.md
- Earlier fix for an infinite range bound — https://github.com/gina-io/swig/security/advisories/GHSA-48rg-vg49-r5vm

## References

- https://github.com/gina-io/swig/security/advisories/GHSA-f8f4-95q3-38qw

Page: https://cve.now/GHSA-F8F4-95Q3-38QW

Wrong or missing data? Send feedback: POST https://cve.now/api/v1/feedback (see https://cve.now/agents#feedback).
