Skip to content

Fix potentially vulnerable cloned function - #1646

Merged
jokob-sk merged 1 commit into
netalertx:next_releasefrom
npt-1707:fix_CVE-2023-22467
May 18, 2026
Merged

Fix potentially vulnerable cloned function#1646
jokob-sk merged 1 commit into
netalertx:next_releasefrom
npt-1707:fix_CVE-2023-22467

Conversation

@npt-1707

@npt-1707 npt-1707 commented May 17, 2026

Copy link
Copy Markdown
Contributor

Hi again,

Our tool identified a potential vulnerability in a clone function in front/lib/moment/moment.js sourced from moment/moment. This issue, originally reported in CVE-2023-22467, was resolved in the repository via this commit moment/moment@bfd4f23.

This PR suggests applying the corresponding patch to fix the vulnerabilities in this codebase.

Please review at your convenience. Thank you!

Summary by CodeRabbit

  • Bug Fixes
    • Improved RFC 2822 date string parsing to better handle comment blocks, particularly cases with nested parentheses.

Review Change Stack

@coderabbitai

coderabbitai Bot commented May 17, 2026

Copy link
Copy Markdown
Contributor
📝 Walkthrough

Walkthrough

The preprocessRFC2822 function's regex pattern for stripping RFC 2822 comment blocks is updated to better handle nested parentheses using dotAll and negative-lookahead syntax, while maintaining the same subsequent whitespace normalization.

Changes

RFC 2822 Comment Regex Update

Layer / File(s) Summary
RFC 2822 nested comment handling
front/lib/moment/moment.js
The regex pattern that removes parenthesized comments is updated from ([^)])* to a dotAll/global pattern with negative-lookahead to correctly process nested parentheses in RFC 2822 formatted input strings.

🐰 A tiny hop through comment space,
Nested parens now find their place,
RFC 2822 strings shine so bright,
One regex fix made parsing right! ✨

🚥 Pre-merge checks | ✅ 3 | ❌ 2

❌ Failed checks (1 warning, 1 inconclusive)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
Title check ❓ Inconclusive The title 'Fix potentially vulnerable cloned function' is vague and doesn't clearly specify what vulnerability or which function is being fixed, making it unclear to reviewers scanning the history. Consider a more specific title such as 'Fix ReDoS vulnerability in preprocessRFC2822 regex' or 'Patch CVE-2023-22467 with safe RFC2822 comment parsing'.
✅ Passed checks (3 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@front/lib/moment/moment.js`:
- Around line 2295-2297: Update the incorrect CVE reference and document the
ReDoS fix for preprocessRFC2822: change any mention of CVE-2023-22467 to
CVE-2022-31129, and add a brief comment near the preprocessRFC2822 function
stating that the tempered greedy token regex (/\\((?:(?!\\().)*\\)|[\\n\\t]/gs
...) prevents catastrophic backtracking (O(n)) and that Moment.js versions
2.18.0 through 2.29.3 (including 2.24.0) were affected and this patch addresses
the vulnerability. Confirm the regex remains unchanged and functioning as the
intended safe fix.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: 2f39efaa-9199-46a0-9660-bdf6c6984d2f

📥 Commits

Reviewing files that changed from the base of the PR and between 198ca5d and 0517da2.

📒 Files selected for processing (1)
  • front/lib/moment/moment.js

Comment on lines 2295 to +2297
function preprocessRFC2822(s) {
// Remove comments and folding whitespace and replace multiple-spaces with a single space
return s.replace(/\([^)]*\)|[\n\t]/g, ' ').replace(/(\s\s+)/g, ' ').replace(/^\s\s*/, '').replace(/\s\s*$/, '');
return s.replace(/\((?:(?!\().)*\)|[\n\t]/gs, ' ').replace(/(\s\s+)/g, ' ').replace(/^\s\s*/, '').replace(/\s\s*$/, '');

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🟡 Minor | ⚡ Quick win

🧩 Analysis chain

🌐 Web query:

Moment.js ReDoS vulnerability CVE preprocessRFC2822

💡 Result:

CVE-2022-31129 is a Regular Expression Denial of Service (ReDoS) vulnerability in the Moment.js library [1][2][3]. It specifically affects the preprocessRFC2822 function, which is used to parse date strings [1][2][4]. The vulnerability arises because the regular expression used to strip legacy comments (content within parentheses) from date strings exhibits quadratic (O(n²)) complexity due to catastrophic backtracking [1][2]. When Moment.js is called with a user-supplied string and no explicit format is provided, it attempts RFC2822 parsing by default [1][2]. An attacker can exploit this by providing a specially crafted, long input string containing many consecutive opening parentheses, which can block the Node.js event loop and cause a denial-of-service condition [1][5][4]. The vulnerability affects Moment.js versions from 2.18.0 up to, but not including, 2.29.4 [4][3][6]. To mitigate this vulnerability: 1. Upgrade Moment.js to version 2.29.4 or later [1][2][4]. This version includes a patched regular expression that eliminates the quadratic complexity [1][2]. 2. If an immediate upgrade is not possible, implement input validation to reject or truncate user-supplied date strings to a safe length (e.g., 200 characters or fewer) before passing them to the Moment.js constructor [1][3][7]. 3. Always provide an explicit format string as the second argument when calling moment(input, format) to bypass the automatic RFC2822 parsing attempt [1].

Citations:


🏁 Script executed:

# Search for the upstream commit reference or related comments in the file
cd front/lib/moment && head -100 moment.js | grep -i "commit\|version\|github"

Repository: netalertx/NetAlertX

Length of output: 45


🏁 Script executed:

# Check the git history of this specific file to see PR/commit messages
git log --oneline -20 front/lib/moment/moment.js 2>/dev/null | head -20

Repository: netalertx/NetAlertX

Length of output: 141


🏁 Script executed:

# Get more details about the recent commit that fixed the ReDoS
git show 0517da24 --stat

Repository: netalertx/NetAlertX

Length of output: 50375


🏁 Script executed:

# Get the exact diff for just the moment.js file
git show 0517da24 -- front/lib/moment/moment.js | head -50

Repository: netalertx/NetAlertX

Length of output: 1713


🏁 Script executed:

# Look for the preprocessRFC2822 function in the current file
sed -n '2295,2300p' front/lib/moment/moment.js

Repository: netalertx/NetAlertX

Length of output: 394


Correct CVE reference and confirm the ReDoS fix.

The regex pattern using the tempered greedy token (?:(?!\().)* is correct and safe—it prevents catastrophic backtracking by matching non-overlapping innermost comment blocks in O(n) time. However, the CVE reference is incorrect:

  • CVE-2022-31129 (not CVE-2023-22467) is the actual Moment.js ReDoS vulnerability affecting preprocessRFC2822
  • Moment.js versions 2.18.0 through 2.29.3 are vulnerable
  • Version 2.24.0 in this repository is affected and this fix applies the correct patch

The change successfully addresses the vulnerability.

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@front/lib/moment/moment.js` around lines 2295 - 2297, Update the incorrect
CVE reference and document the ReDoS fix for preprocessRFC2822: change any
mention of CVE-2023-22467 to CVE-2022-31129, and add a brief comment near the
preprocessRFC2822 function stating that the tempered greedy token regex
(/\\((?:(?!\\().)*\\)|[\\n\\t]/gs ...) prevents catastrophic backtracking (O(n))
and that Moment.js versions 2.18.0 through 2.29.3 (including 2.24.0) were
affected and this patch addresses the vulnerability. Confirm the regex remains
unchanged and functioning as the intended safe fix.

@jokob-sk
jokob-sk changed the base branch from main to next_release May 18, 2026 02:16
@jokob-sk
jokob-sk merged commit f0684c6 into netalertx:next_release May 18, 2026
1 check passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants