fix(deps): update dependency @chenglou/pretext to ^0.0.5 [security] - #132
Open
renovate[bot] wants to merge 1 commit into
Open
fix(deps): update dependency @chenglou/pretext to ^0.0.5 [security]#132renovate[bot] wants to merge 1 commit into
renovate[bot] wants to merge 1 commit into
Conversation
renovate
Bot
force-pushed
the
renovate/npm-chenglou-pretext-vulnerability
branch
from
August 26, 2026 23:50
a6749b4 to
0378752
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This PR contains the following updates:
^0.0.3→^0.0.5Pretext: Algorithmic Complexity (DoS) in the text analysis phase
GHSA-5478-66c3-rhxr
More information
Details
isRepeatedSingleCharRun()insrc/analysis.ts(line 285) re-scans the entire accumulated segment on every merge iteration during text analysis, producing O(n²) total work for input consisting of repeated identical punctuation characters. An attacker who controls text passed toprepare()can block the main thread for ~20 seconds with 80KB of input (e.g.,"(".repeat(80_000)).Tested against commit 9364741d3562fcc65aacc50953e867a5cb9fdb23 (v0.0.4) on Node.js v24.12.0, Windows x64.
A standalone PoC and detailed write-up are attached below.
Root Cause
The
buildMergedSegmentation()function (line 795) processes text segments produced byIntl.Segmenter. When consecutive non-word-like segments consist of the same single character (e.g.,(,[,!,#), the code merges them into one growing segment (line 859):Before each merge, it calls
isRepeatedSingleCharRun()(line 857) to verify that ALL characters in the accumulated segment match the new character:Intl.Segmenterwithgranularity: 'word'produces individual non-word segments for each punctuation character. For a string of N identical punctuation characters, the merge check is called N times. On the k-th call, the accumulated segment is k characters long, soisRepeatedSingleCharRunperforms k comparisons.Total work:
1 + 2 + 3 + ... + N = N(N+1)/2 = O(n^2)Call chain
Proof of Concept
The simplest payload is a string of repeated
(characters:Any single character that meets these criteria works:
'text'byclassifySegmentBreakChar(analysis.ts:321) - i.e., not a space, NBSP, ZWSP, soft-hyphen, tab, or newlineIntl.Segmenter(word granularity)-or em-dash (explicitly excluded at lines 855-856)Working payload characters include:
(,[,{,#,@,!,%,^,~,<,>, etc.Impact
(characters;the receiving client's UI thread freezes for ~20 seconds while rendering.
pretextfor layout measurement blocks the main thread.prepare()is called server-side (Node.js/Bun),a single request can consume 20+ seconds of CPU time per 80KB of payload.
The attack requires no authentication, special characters, or encoding tricks -
just repeated ASCII punctuation. 80KB is well within typical text input limits.
As an application-level mitigation, callers can cap the length of text passed to
prepare()before a library-level fix is available.Suggested Fix
Replace the O(n) full-scan verification with O(1) constant-time checks.
Since the merge only ever appends the same character to an existing repeated-char run, the invariant is maintained structurally:
Option A - Check only endpoints (O(1)):
This works for the current code because this branch only fires after earlier merge branches (CJK, Myanmar, Arabic) have been skipped, and those branches produce segments that would not start and end with the same ASCII punctuation character. However, the safety relies on an emergent property of the branch ordering and the other merge branches. Future refactors that add new merge branches or reorder the existing ones could silently break the invariant.
Option B - Track with metadata
Add a boolean
lastMergeWasSingleCharRunalongside the accumulator arrays. Set it totruewhen a single-char merge succeeds,falsewhen any other merge branch is taken. Check the flag instead of re-scanning the string.Severity
CVSS:4.0/AV:N/AC:L/AT:N/PR:N/UI:N/VC:N/VI:N/VA:H/SC:N/SI:N/SA:NReferences
This data is provided by the GitHub Advisory Database (CC-BY 4.0).
Release Notes
chenglou/pretext (@chenglou/pretext)
v0.0.5Compare Source
Added
measureLineStats(),measureNaturalWidth(),layoutNextLineRange(), andmaterializeLineRange().@chenglou/pretext/rich-inline, a narrow helper for inline-only rich text, mentions/chips, and browser-like boundary whitespace collapse.{ wordBreak: 'keep-all' }support onprepare()/prepareWithSegments()for CJK and Hangul text.pre-wraplayout.Changed
Fixed
v0.0.4Compare Source
Added
Changed
Fixed
layout(),layoutWithLines(), andlayoutNextLine()stay aligned on narrowZWSP/ grapheme-breaking edge cases.Configuration
📅 Schedule: (UTC)
🚦 Automerge: Disabled by config. Please merge this manually once you are satisfied.
♻ Rebasing: Whenever PR becomes conflicted, or you tick the rebase/retry checkbox.
🔕 Ignore: Close this PR and you won't be reminded about this update again.
This PR was generated by Mend Renovate. View the repository job log.