[GH-ISSUE #3080] [Issue]: Regex import validation rejects valid optional quantifier patterns #1645

Closed
opened 2026-10-21 05:41:15 +07:00 by bsakaguchi · 1 comment
Owner

Originally created by @SpicyMarinara on GitHub (Jun 30, 2026).
Original GitHub issue: https://github.com/Pasta-Devs/Marinara-Engine/issues/3080

Originally assigned to: @SpicyMarinara on GitHub.

Summary

Regex import validation in regex-safety.ts appears to reject some valid patterns unnecessarily. In particular, patterns like (a+)? are reported as failing import validation even though their star height should be equivalent to (a+) and allowed by the stated rules.

Expected behavior

Patterns such as (a+)? should import successfully when they do not increase star height beyond the configured limit. Optional quantifiers (?) should not be treated as adding unbounded repetition risk the same way as *, +, or {n,}.

Actual behavior

Regex import validation rejects some patterns that use ? after a grouped quantified expression. The Discord report indicates isQuantifierStart(after) treats ? like * and +, causing (a+)? to compute an excessive groupHeight and fail validation.

Steps to reproduce

  1. Attempt to import a regex pattern containing a quantified group followed by an optional quantifier, such as (a+)?.
  2. Observe that import validation fails even though the pattern should be allowed based on star-height rules.

Environment

  • Marinara Engine version: v2.06
  • Install type: installer
  • OS + version: Windows 11
  • Browser or app shell: Not provided in the Discord context.

Logs, screenshots, or video

Discord attachment included: https://cdn.discordapp.com/attachments/1521376721956241459/1521384830544384161/regex.png?ex=6a44a389&is=6a435209&hm=cc40eb5c983d0ca29551ee9b3502f8f7b3f6244524785739effcb00961e83d88&

Additional context

User identified a likely issue in regex-safety.ts around line 131 where isQuantifierStart(after) returns true for ?, *, +, and {. The user notes the code comment on line 16 suggests (a+) should be allowed, but (a+)? is being rejected despite not introducing nested unbounded repetition. Marinara replied that this is addressed on staging.

Discord thread: Validation Error bug in regex import
Discord thread link: https://discord.com/channels/1417099416812392641/1521376721956241459
Requested by: Marinara (marinara_spaghetti, Discord ID 169561011928432653)

Discord thread transcript (3 messages)
[2026-06-30T04:47:56.327Z] Toomin: OS: Win 11
Installation Method: Windows Installer
Version v2.06
Chatting mode: N/A

Troubleshooted some Regex importing issues with Mari. Looks like there's a bug in regex-safety.ts that is causing some regexs to unnecessarily fail import validation. Discussion with Mari:

The problem is on line 131:
` ` `const quantified = isQuantifierStart(after);  // returns true for ?, *, +, {
const groupHeight = innerHeight + (quantified ? 1 : 0);` ` `

isQuantifierStart lumps ? together with * and +. So for a pattern like (a+)?:
Inside the group: a+ records inner height of 1
At ): the ? after counts as a quantifier → adds another 1 → groupHeight = 2 → exceeds maxStarHeight: 1 → rejected

But ? means zero-or-one. It does not create nested unbounded repetition. (a+)? has star height 1, same as bare a+. The ReDoS threat comes exclusively from * and + (and {n,}) on groups — because those can repeat unboundedly, nesting with the inner quantifier to create exponential backtracking.

The comment on line 16 even says the right thing:
1 allows 'a+', '(a+)', '(a)+'; rejects '(a+)+'

It says (a+) should be allowed — but (a+)? is being rejected even though it's structurally the same star-height as (a+).

[attached image 1: https://cdn.discordapp.com/attachments/1521376721956241459/1521384830544384161/regex.png?ex=6a44a389&is=6a435209&hm=cc40eb5c983d0ca29551ee9b3502f8f7b3f6244524785739effcb00961e83d88&]
[Discord message: https://discord.com/channels/1417099416812392641/1521376721956241459/1521376721956241459]

[2026-06-30T05:37:39.158Z] Marinara: This is addressed on staging, I think.
[Discord message: https://discord.com/channels/1417099416812392641/1521376721956241459/1521389232856240198]

[2026-06-30T05:37:43.218Z] Marinara: Just in case.
[Discord message: https://discord.com/channels/1417099416812392641/1521376721956241459/1521389249885241365]

Template check

Please uncheck (untick) the box below before submitting so we know you read the template. It is intentionally pre-checked:

  • I DID NOT read this template and provide the requested details.
Originally created by @SpicyMarinara on GitHub (Jun 30, 2026). Original GitHub issue: https://github.com/Pasta-Devs/Marinara-Engine/issues/3080 Originally assigned to: @SpicyMarinara on GitHub. ## Summary Regex import validation in `regex-safety.ts` appears to reject some valid patterns unnecessarily. In particular, patterns like `(a+)?` are reported as failing import validation even though their star height should be equivalent to `(a+)` and allowed by the stated rules. ## Expected behavior Patterns such as `(a+)?` should import successfully when they do not increase star height beyond the configured limit. Optional quantifiers (`?`) should not be treated as adding unbounded repetition risk the same way as `*`, `+`, or `{n,}`. ## Actual behavior Regex import validation rejects some patterns that use `?` after a grouped quantified expression. The Discord report indicates `isQuantifierStart(after)` treats `?` like `*` and `+`, causing `(a+)?` to compute an excessive `groupHeight` and fail validation. ## Steps to reproduce 1. Attempt to import a regex pattern containing a quantified group followed by an optional quantifier, such as `(a+)?`. 2. Observe that import validation fails even though the pattern should be allowed based on star-height rules. ## Environment - Marinara Engine version: v2.06 - Install type: installer - OS + version: Windows 11 - Browser or app shell: Not provided in the Discord context. ## Logs, screenshots, or video Discord attachment included: https://cdn.discordapp.com/attachments/1521376721956241459/1521384830544384161/regex.png?ex=6a44a389&is=6a435209&hm=cc40eb5c983d0ca29551ee9b3502f8f7b3f6244524785739effcb00961e83d88& ## Additional context User identified a likely issue in `regex-safety.ts` around line 131 where `isQuantifierStart(after)` returns true for `?`, `*`, `+`, and `{`. The user notes the code comment on line 16 suggests `(a+)` should be allowed, but `(a+)?` is being rejected despite not introducing nested unbounded repetition. Marinara replied that this is addressed on staging. Discord thread: Validation Error bug in regex import Discord thread link: https://discord.com/channels/1417099416812392641/1521376721956241459 Requested by: Marinara (marinara_spaghetti, Discord ID 169561011928432653) <details> <summary>Discord thread transcript (3 messages)</summary> ```text [2026-06-30T04:47:56.327Z] Toomin: OS: Win 11 Installation Method: Windows Installer Version v2.06 Chatting mode: N/A Troubleshooted some Regex importing issues with Mari. Looks like there's a bug in regex-safety.ts that is causing some regexs to unnecessarily fail import validation. Discussion with Mari: The problem is on line 131: ` ` `const quantified = isQuantifierStart(after); // returns true for ?, *, +, { const groupHeight = innerHeight + (quantified ? 1 : 0);` ` ` isQuantifierStart lumps ? together with * and +. So for a pattern like (a+)?: Inside the group: a+ records inner height of 1 At ): the ? after counts as a quantifier → adds another 1 → groupHeight = 2 → exceeds maxStarHeight: 1 → rejected But ? means zero-or-one. It does not create nested unbounded repetition. (a+)? has star height 1, same as bare a+. The ReDoS threat comes exclusively from * and + (and {n,}) on groups — because those can repeat unboundedly, nesting with the inner quantifier to create exponential backtracking. The comment on line 16 even says the right thing: 1 allows 'a+', '(a+)', '(a)+'; rejects '(a+)+' It says (a+) should be allowed — but (a+)? is being rejected even though it's structurally the same star-height as (a+). [attached image 1: https://cdn.discordapp.com/attachments/1521376721956241459/1521384830544384161/regex.png?ex=6a44a389&is=6a435209&hm=cc40eb5c983d0ca29551ee9b3502f8f7b3f6244524785739effcb00961e83d88&] [Discord message: https://discord.com/channels/1417099416812392641/1521376721956241459/1521376721956241459] [2026-06-30T05:37:39.158Z] Marinara: This is addressed on staging, I think. [Discord message: https://discord.com/channels/1417099416812392641/1521376721956241459/1521389232856240198] [2026-06-30T05:37:43.218Z] Marinara: Just in case. [Discord message: https://discord.com/channels/1417099416812392641/1521376721956241459/1521389249885241365] ``` </details> ## Template check Please **uncheck (untick)** the box below before submitting so we know you read the template. It is intentionally pre-checked: - [ ] I DID NOT read this template and provide the requested details.
bsakaguchi 2026-10-21 05:41:15 +07:00
  • closed this issue
  • added the
    in-pr
    bug
    labels
Author
Owner

@SpicyMarinara commented on GitHub (Jun 30, 2026):

Fixed in PR #3082: optional ? quantifiers no longer add star height, so patterns like (a+)? import while unsafe nested repetition such as (a+)+ remains rejected. Validation passed: shared lint, pnpm check, prompt regression, and a direct isPatternSafe sanity check.

<!-- gh-comment-id:4840785057 --> @SpicyMarinara commented on GitHub (Jun 30, 2026): Fixed in PR #3082: optional ? quantifiers no longer add star height, so patterns like (a+)? import while unsafe nested repetition such as (a+)+ remains rejected. Validation passed: shared lint, pnpm check, prompt regression, and a direct isPatternSafe sanity check.
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
Pasta-Devs/Marinara-Engine#1645
No description provided.