mirror of
https://github.com/Pasta-Devs/Marinara-Engine.git
synced 2026-12-03 19:00:50 +07:00
[GH-ISSUE #2364] [Issue]: Regex scripts run content-supplied findRegex with no ReDoS guard — only the ST-card import path is protected #1164
Labels
No labels
android
bug
bugfix
ci
client
code freeze pause
container
dependencies
docs
documentation
duplicate
enhancement
feature
feature
feature
feature-creep
fixed-in-refactor
fixed-in-staging
good first issue
help wanted
in-pr
in-pr
needs-codeowner-decision
normal-scope
old-codebase
old-codebase
pull-request
qol
question
refactor
regression
revisit later
roadmap
scope-risk
scope-risk
server
server
shared
soup
upstream
windows
No milestone
No project
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set.
Reference
Pasta-Devs/Marinara-Engine#1164
Loading…
Add table
Add a link
Reference in a new issue
No description provided.
Delete branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Originally created by @Romuromylus on GitHub (Jun 5, 2026).
Original GitHub issue: https://github.com/Pasta-Devs/Marinara-Engine/issues/2364
Originally assigned to: @Romuromylus on GitHub.
Summary
Severity: Medium — injection / ReDoS.
Regex scripts compile and run a content-supplied
findRegexagainst the full transcript with no ReDoS guard — neither on the storage-validation schema nor on any of the three runtime executors. TheisPatternSafe()guard exists in the repo and is enforced on the ST character-card import path and the lorebook keyword scanner, but the regex-script path skips it entirely. A catastrophically-backtracking pattern that enters storage (via a profile/preset bundle import, or pasted into the editor) freezes the single-threaded renderer on every generation turn.Expected behavior
Every regex-script ingestion point should reject unsafe patterns at the storage boundary, and every runtime executor should refuse to run an unsafe pattern (or run it under the interruptible-worker timeout the lorebook path already uses).
Actual behavior
createRegexScriptSchemavalidatesfindRegexonly as a non-empty string — no safety refinement (src/engine/contracts/schemas/regex.schema.ts:12):All three runtime executors then compile and run the stored pattern with only a syntax-error
try/catch— noisPatternSafe, no length cap, no timeout:prompt-assembly.ts:3241-3242loads allregex-scriptsfrom storage and runsapplyRegexScriptsToPromptMessageson every generation turn, so a stored(a+)+$-class pattern run over attacker-influenced AI output / user input causes catastrophic backtracking and freezes the JS event loop. The lorebook keyword path is hardened viavmRegexExecutor(src/engine/generation-core/lorebooks/regex-timeout.ts:142-150: 50 ms worker deadline +isPatternSafe+MAX_REGEX_SCAN_TEXT_LENGTH), but that fix is scoped only to the keyword scanner — the script executors are unprotected siblings.Note on reachability: the ST character-card import path is already guarded (
src/shared/lib/regex-script-import.ts:82callsisPatternSafeand skips unsafe patterns before storing), so a malicious character card cannot plant an unsafe script. The genuinely unguarded ingestion paths are the full-profile / preset bundle import (ProfileImportSection.tsx→ Rustcommands/storage/profile/legacy.rs:49mapsregex_scripts→regex-scriptsand writes records verbatim; nois_pattern_safeanywhere insrc-tauri) and the in-app editor (RegexScriptEditor.tsx, which only does anew RegExpsyntax check).Steps to reproduce
.marinaraenvelope) whoseregex-scriptscollection contains a script withfindRegex: "(a+)+$"(syntactically valid, catastrophically backtracking).acharacters (model output or user input).Impact area
Environment
330f69a8Logs, screenshots, or video
Static source audit. Cited:
regex.schema.ts:12(no refinement); run-path executorsgeneration-core/regex/regex-application.ts:92,generation/regex-runtime.ts:39,features/catalog/agents/regex-application.ts:67; the guarded referencelorebooks/regex-timeout.ts:142-150+regex-script-import.ts:82.Regression notes
Found via static audit; not a regression. The web build does the identical unguarded thing —
packages/shared/src/schemas/regex.schema.tshas the samefindRegex: z.string().min(1), andpackages/server/.../regex-application.tsuses barenew RegExpwith noisPatternSafe/timeout. The regex-script path was never protected in main; the refactor inherited the gap rather than introducing it. (Separately, #2199 — now fixed — hardened only the lorebook keyword scanner.)Additional context
Single-chokepoint fix: add a pattern-safety refinement to
createRegexScriptSchema/updateRegexScriptSchema(e.g..refine((v) => isPatternSafe(v.findRegex), 'pattern fails ReDoS safety check')) so unsafe patterns are rejected wherever a script is stored, and add the equivalent check on the Rust profile-import path. Then route the three runtime executors through the same guard the lorebook path uses (isPatternSafe+MAX_REGEX_SCAN_TEXT_LENGTH, ideallyvmRegexExecutor). The reference implementation already exists atregex-script-import.ts:82andlorebooks/regex-timeout.ts.Template check
@Romuromylus commented on GitHub (Jun 5, 2026):
Same content-driven renderer-freeze class as #2363 (unbounded macro expansion /
{{roll:NdM}}loop): both are imported-content DoS vectors during prompt assembly that the engine has no resource budget for. Worth addressing together when adding bounds to the content-processing paths.@Romuromylus commented on GitHub (Jun 6, 2026):
Fixed by #2422, merged into
refactor.