Skip to content

Fix potentially vulnerable cloned function - #1647

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

Fix potentially vulnerable cloned function#1647
jokob-sk merged 1 commit into
netalertx:next_releasefrom
npt-1707:fix_CVE-2022-24785

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-2022-24785, was resolved in the repository via this commit moment/moment@4211bfc.

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
    • Enhanced locale loading validation with stricter input checks for improved security.

Review Change Stack

@coderabbitai

coderabbitai Bot commented May 17, 2026

Copy link
Copy Markdown
Contributor
📝 Walkthrough

Walkthrough

A new isLocaleNameSane(name) helper function is introduced in moment.js to reject locale names containing / or \ characters. The loadLocale function's CommonJS/Node locale-loading branch now guards its dynamic module require by verifying the locale name passes this sanitation check before constructing and requiring the locale path.

Changes

Locale Name Sanitization

Layer / File(s) Summary
Locale name sanitization helper and integration
front/lib/moment/moment.js
isLocaleNameSane(name) validates that locale names do not contain path separator characters (/ or \), and the loadLocale function's CommonJS branch now gates its dynamic require('./locale/' + name) call with this check.

Poem

🐰 A moment's path needs mending clear,
No slashes sneaking path traversal near!
With isLocaleNameSane, names are blessed,
Locale loading safe and put to test. ✨

🚥 Pre-merge checks | ✅ 3 | ❌ 2

❌ Failed checks (2 warnings)

Check name Status Explanation Resolution
Title check ⚠️ Warning The title refers to fixing a 'vulnerable cloned function,' but the actual change involves adding input validation to the loadLocale function to prevent path traversal attacks via malicious locale names—not fixing a cloned function itself. Update the title to more accurately reflect the change, such as 'Add locale name validation to prevent path traversal' or 'Fix CVE-2022-24785 by sanitizing locale names in loadLocale.'
Docstring Coverage ⚠️ Warning Docstring coverage is 33.33% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ 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 1845-1848: The isLocaleNameSane function calls name.match()
without ensuring name is a string, which throws for non-string inputs; update
isLocaleNameSane to first check typeof name === 'string' (or use
String.prototype methods safely) and return false for non-strings, then run the
regex match on the validated string; reference the isLocaleNameSane function and
ensure loadLocale callers that rely on its boolean result are still protected
from TypeError by this guard.
🪄 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: 1ec1772b-7134-4975-be93-d426161091bd

📥 Commits

Reviewing files that changed from the base of the PR and between 198ca5d and 35dc9f9.

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

Comment on lines +1845 to +1848
function isLocaleNameSane(name) {
// Prevent names that look like filesystem paths, i.e contain '/' or '\'
return name.match('^[^/\\\\]*$') != null;
}

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 | 🟠 Major | ⚡ Quick win

🧩 Analysis chain

🏁 Script executed:

#!/bin/bash
# Verify the exact unsafe usage and call path in this file.
rg -n -C3 'function isLocaleNameSane|name\.match\(|function loadLocale|isLocaleNameSane\(name\)|function getLocale' front/lib/moment/moment.js

Repository: netalertx/NetAlertX

Length of output: 923


Add type guard to isLocaleNameSane() to prevent runtime crashes on non-string input.

The function calls name.match() without checking if name is a string. Non-string values (e.g., from moment.locale() called with numeric or boolean arguments) will throw a TypeError at line 1847 before the try/catch in loadLocale() can handle it.

Suggested fix
 function isLocaleNameSane(name) {
     // Prevent names that look like filesystem paths, i.e contain '/' or '\'
-    return name.match('^[^/\\\\]*$') != null;
+    return typeof name === 'string' && /^[^/\\]*$/.test(name);
 }
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
function isLocaleNameSane(name) {
// Prevent names that look like filesystem paths, i.e contain '/' or '\'
return name.match('^[^/\\\\]*$') != null;
}
function isLocaleNameSane(name) {
// Prevent names that look like filesystem paths, i.e contain '/' or '\'
return typeof name === 'string' && /^[^/\\]*$/.test(name);
}
🤖 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 1845 - 1848, The isLocaleNameSane
function calls name.match() without ensuring name is a string, which throws for
non-string inputs; update isLocaleNameSane to first check typeof name ===
'string' (or use String.prototype methods safely) and return false for
non-strings, then run the regex match on the validated string; reference the
isLocaleNameSane function and ensure loadLocale callers that rely on its boolean
result are still protected from TypeError by this guard.

@jokob-sk
jokob-sk changed the base branch from main to next_release May 18, 2026 02:17
@jokob-sk
jokob-sk merged commit 9eaaf50 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