mirror of
https://github.com/Pasta-Devs/Marinara-Engine.git
synced 2026-12-03 19:00:50 +07:00
[GH-ISSUE #2620] [Issue]: Server prompt-context regex scripts run with no execution timeout (event-loop-blocking ReDoS) #1295
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#1295
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 18, 2026).
Original GitHub issue: https://github.com/Pasta-Devs/Marinara-Engine/issues/2620
Originally assigned to: @Romuromylus on GitHub.
Summary
Severity: Low — performance / security (ReDoS). The server prompt-context regex engine compiles and runs
promptOnlyregex scripts against every prompt message on every/generaterequest with no execution timeout. A catastrophic-backtracking pattern stalls the Node event loop for the whole process, hanging generation for all users. The sibling untrusted-regex path (lorebook keyword scan) already defends against exactly this with a 50ms vm timeout +isPatternSafe; the prompt engine has neither.Expected behavior
Prompt-context regex execution should be bounded (timeout) and/or statically pre-filtered (
isPatternSafe), the same way the lorebook keyword scanner is, so a pathological pattern cannot block the event loop.Actual behavior
applyRegexScriptsToPromptMessagesruns on the per-request generation path (generate.routes.ts:1443,chats.routes.ts:1740,dry-run-route.ts:849). The sibling lorebook path runs regex inside a vm withDEFAULT_REGEX_TIMEOUT_MS = 50(services/lorebook/regex-timeout.ts) and statically pre-filters viaisPatternSafe(lorebook-keyword-matching.ts:40); the prompt engine applies neither. ThePOST/PATCH /regex-scriptsroute validates only viacreateRegexScriptSchema(findRegexisz.string().min(1)) and never callsisPatternSafe, so a hostile/buggy pattern is stored verbatim and recompiled+run every turn. Empirically,/(a|a)+$/against'a'.repeat(30)+'!'ran ~98s in Node. Note: the ST card importer forcespromptOnly:false(st-character.importer.ts:148) and the prompt engine only runspromptOnly===truescripts, so this is a self/co-tenant DoS reachable by an authenticated operator, not a remote card-injection vector.Steps to reproduce
promptOnly=trueand a catastrophic pattern, e.g.findRegex(a|a)+$(via the authenticatedPOST /regex-scripts)./generateso the script is compiled and applied to each prompt message.Environment
staging @ 56f700cd(v2.0.0)Logs, screenshots, or video
Static source audit, cited to file:line above. Empirically:
(a|a)+$on a 31-char input ran ~98s in Node.Additional context
Fix sketch. Gate
promptOnlyregex compilation inapplyRegexScriptsToPromptTextbehindisPatternSafe(findRegex)(skip / literal-fallback on failure), mirroringlorebook-keyword-matching.ts:40, and/or run the replace under the same vm-timeout posture asregex-timeout.tsso a pathological pattern aborts at ~50ms instead of stalling the loop. Also applyisPatternSafein thePOST/PATCH /regex-scriptsroute validation. Reference implementations:services/lorebook/regex-timeout.tsandlorebook-keyword-matching.ts.Regression notes. Not a regression —
maincarries byte-equivalent prompt-regex code (same no-timeoutnew RegExp+applyRegexReplacement), the same unguarded route validation, and already has the lorebookregex-timeout.tsguard. The inconsistency is pre-existing on the release baseline. Distinct from #2526 (lorebook scan perf).Template check
@Romuromylus commented on GitHub (Jun 18, 2026):
Fixed in #2623, merged to
staging(e1132e5b). Closing manually since the PR targetedstagingrather than the default branch.