GHSA-q87h-c5m7-659j

Suggest an improvement
Source
https://github.com/advisories/GHSA-q87h-c5m7-659j
Import Source
https://github.com/github/advisory-database/blob/main/advisories/github-reviewed/2026/11/GHSA-q87h-c5m7-659j/GHSA-q87h-c5m7-659j.json
JSON Data
https://api.osv.dev/v1/vulns/GHSA-q87h-c5m7-659j
Aliases
Published
2026-11-20T23:48:51Z
Modified
2026-11-21T00:00:04Z
Severity
  • 5.3 (Medium) CVSS_V3 - CVSS:3.1/AV:N/AC:L/PR:N/UI:N/S:U/C:N/I:N/A:L CVSS Calculator
Summary
Inscriptis: Quadratic memory growth from sibling <table> elements in get_text()
Details

Summary

Every sibling <table> adds another level of the parent's indentation, so the size of get_text() output grows quadratically with the number of tables. In the measurements below, a 240 KB HTML document produces about 1 billion characters and uses about 1 GB of memory.

Details

table_end_handler() (model/tag/table_tag.py) writes the rendered table into the parent element with HtmlElement.write_verbatim_text() (model/html_element.py). For a block-level parent, write_verbatim_text() calls canvas.open_block(), which pushes the parent's padding_inline onto the prefix stack. The following close_block() never pops it; only Canvas.close_tag() calls prefix.remove_last_prefix(). So each table leaves one extra padding entry on the stack.

This has been present since 2.0 (commit 84ec720).

>>> get_text('<ul>' + '<table><tr><td>a</td></tr></table>' * 4 + '</ul>')
'        a\n        \n            a\n            \n                a\n                \n                    a\n                    '

PoC

import sys, time, resource
from inscriptis import get_text

n = int(sys.argv[1])
html = "<ul>" + "<table></table>" * n + "</ul>"
t = time.time(); out = get_text(html)
print(len(html), f"{time.time()-t:.2f}s", len(out), resource.getrusage(resource.RUSAGE_SELF).ru_maxrss // 2**20, "MiB")

inscriptis 2.7.5, Python 3.11, macOS (2.0.0 behaves the same):

tables HTML time output chars peak RSS
1,000 15 KB 0.02 s 4.0 M 31 MiB
4,000 60 KB 0.33 s 64 M 154 MiB
8,000 120 KB 1.31 s 256 M 463 MiB
16,000 240 KB 5.63 s 1,024 M 991 MiB

When the input doubles, output size and memory grow about 4 times.

Impact

Any application that converts untrusted HTML with inscriptis can be made to exhaust memory with a small document. This includes crawlers, RAG and LLM ingestion pipelines, and inscriptis-api. No authentication and no user interaction are needed.

Fix

         self.canvas.write(self, text, whitespace=WhiteSpace.pre)

         if self.display == Display.block:
+            self.canvas.current_block.prefix.remove_last_prefix()
             self.canvas.close_block(self)

With this change the 240 KB input above produces 288 K characters in 0.14 s with 27 MiB peak RSS. A single table renders exactly as before, and the existing test suite passes.

Database specific
{
    "cwe_ids": [
        "CWE-400",
        "CWE-407"
    ],
    "github_reviewed": true,
    "github_reviewed_at": "2026-11-20T23:48:51Z",
    "nvd_published_at": "2026-11-20T17:18:12Z",
    "severity": "MODERATE"
}
References

Affected packages

PyPI / inscriptis

Package

Name
inscriptis
View open source insights on deps.dev
Purl
pkg:pypi/inscriptis

Affected ranges

Type
ECOSYSTEM
Events
Introduced
2.0.0
Fixed
2.7.6

Affected versions

2.*
2.0.0
2.1.1
2.2.0
2.3.0
2.3.1
2.3.2
2.4.0
2.4.0.1
2.5.0
2.5.1
2.5.2
2.5.3
2.6.0
2.7.0
2.7.1
2.7.2
2.7.3
2.7.4
2.7.5

Database specific

last_known_affected_version_range
"<= 2.7.5"
source
"https://github.com/github/advisory-database/blob/main/advisories/github-reviewed/2026/11/GHSA-q87h-c5m7-659j/GHSA-q87h-c5m7-659j.json"