mirror of
https://github.com/Pasta-Devs/Marinara-Engine.git
synced 2026-12-03 19:00:50 +07:00
[PR #2422] [MERGED] Guard profile-import regex scripts against ReDoS patterns #5598
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#5598
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?
📋 Pull Request Information
Original PR: https://github.com/Pasta-Devs/Marinara-Engine/pull/2422
Author: @Romuromylus
Created: 6/6/2026
Status: ✅ Merged
Merged: 6/6/2026
Merged by: @Romuromylus
Base:
refactor← Head:fix/regex-redos-guard📝 Commits (1)
ffe866dGuard profile-import regex scripts against ReDoS patterns📊 Changes
2 files changed (+265 additions, -0 deletions)
View changed files
📝
src-tauri/src/commands/storage/profile.rs(+264 -0)📝
src-tauri/src/commands/storage/profile/legacy.rs(+1 -0)📄 Description
Linked issue
Closes #2364
Why this change
findRegexagainst the full transcript on every generation turn. Only the ST character-card import path was guarded byisPatternSafe; the profile/preset bundle import wroteregex-scriptsrows verbatim with no ReDoS check (the issue's repro: import a.marinaraprofile whoseregex-scriptscontains(a+)+$, then send a turn with a long run ofa→ the single-threaded renderer freezes on catastrophic backtracking).What changed
src-tauri/src/commands/storage/profile.rs: addeddrop_unsafe_regex_scriptsplus a faithful Rust port of the TypeScriptisPatternSafeheuristic (src/engine/shared/regex/regex-safety.ts— star-height,{n,m}bounds, length cap). The modern profile import (profile_collections_import_plan) now dropsregex-scriptsrows whosefindRegexfails the heuristic, mirroring the existing ST-card import behavior of skipping unsafe patterns at the storage boundary.src-tauri/src/commands/storage/profile/legacy.rs: the legacy SQLite profile import calls the samesuper::drop_unsafe_regex_scripts, so both import paths share one source of truth.Scope note (deliberate)
This PR guards the import boundary — the issue's demonstrated vector. I intentionally did not add the
isPatternSafeheuristic to the in-app editor schema or the three runtime script executors, because the existing heuristic rejects common safe patterns (\n{3,},\s{2,}) and both shipped default regex scripts (the HTML-stripper and the blank-line collapser seeded inseed_defaults.rs). A schema refine would block users from saving those patterns, and a runtime skip would silently break the seeded defaults. The issue's preferred runtime hardening is the lorebook scanner's interruptible-worker timeout (vmRegexExecutor,regex-timeout.ts); routing the script executors through that timeout (so a catastrophic pattern is interrupted without dropping safe-but-heuristic-failing patterns) is a larger follow-up worth its own PR.Refactor impact
Primary owner: Rust storage (imports)
Impact areas reviewed:
src-tauri/src/commands/storage/profile.rs(profile_collections_import_plan+ new helper)src-tauri/src/commands/storage/profile/legacy.rs(legacy import per-collection match)Boundary notes:
profile.rsand is shared with thelegacysubmodule viasuper::. No TS, engine, or runtime path touched, so seeded defaults and the editor are unaffected.Pressure points touched:
Validation
pnpm checkpasses before PR push/handoffManual verification notes
cargo test --manifest-path src-tauri/Cargo.toml -p marinara-engine(profile import) — a local-only test confirmed a profile importingfindRegex: "(a+)+$"drops that script while a safea+script imports. The Rust heuristic was cross-checked against the TSisPatternSafefor parity.cargo clippy --manifest-path src-tauri/Cargo.toml --workspace --all-targets -- -D warnings— clean.Feature Discoverability
src/features/shell/discovery/Reason:
Docs and release impact
🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.