Doc 1834/migration - #671
Conversation
✅ Deploy Preview for incomparable-tiramisu-91a96a ready!
To edit notification comments on pull requests, go to your Netlify project configuration. |
Wiz Scan Summary
To detect these findings earlier in the dev lifecycle, try the Wiz Code extension for VS Code, JetBrains, or Visual Studio. |
| const DOCS_DIR = path.join(__dirname, "..", "..", "docs"); | ||
|
|
||
| function walk(dir, acc) { | ||
| for (const entry of fs.readdirSync(dir, { withFileTypes: true })) { |
There was a problem hiding this comment.
Improper Limitation of Pathname to Restricted Directory (Path Traversal) (CWE-22)
More Details
Path traversal vulnerabilities occur when user-supplied input is used to construct file paths without proper validation or sanitization. This allows an attacker to access files and directories outside the intended scope, potentially exposing sensitive data or enabling unauthorized system access.
The risk stems from the application's failure to properly restrict file operations to a limited directory. By manipulating the file path with special characters like "../", an attacker can traverse the file system hierarchy and access arbitrary files or directories.
Successful exploitation of a path traversal vulnerability can lead to data breaches, unauthorized access to system resources, and potentially complete system compromise. It is crucial to validate and sanitize all user input used in file operations to prevent such attacks.
| Attribute | Value |
|---|---|
| Impact | |
| Likelihood |
Remediation
Path traversal vulnerabilities occur when user-supplied input is used to construct file paths without proper validation or sanitization. This allows an attacker to access files and directories outside the intended scope, potentially exposing sensitive data or enabling unauthorized system access. Successful exploitation of a path traversal vulnerability can lead to data breaches, unauthorized access to system resources, and potentially complete system compromise.
To fix this issue, you should validate and sanitize all user input used in file operations to prevent path traversal attacks. This can be achieved by using a secure path resolution library or by implementing strict input validation and sanitization routines. Avoid concatenating user input directly into file paths, and instead, use platform-specific path normalization functions to resolve paths safely.
Code examples
// VULNERABLE CODE - User input is concatenated directly into the file path
const fs = require('fs');
const userInput = "../../../sensitive.txt";
fs.readFile(`/app/files/${userInput}`, (err, data) => {
// ...
});// SECURE CODE - User input is sanitized, and path is resolved securely
const fs = require('fs');
const path = require('path');
const userInput = "../../../sensitive.txt";
const sanitizedPath = path.resolve('/app/files', path.normalize(userInput));
fs.readFile(sanitizedPath, (err, data) => {
// ...
});Additional recommendations
- Use the built-in
pathmodule in Node.js to safely construct file paths. - Implement strict input validation and sanitization routines for all user input used in file operations.
- Follow the principle of least privilege and restrict file operations to a limited directory scope.
- Adhere to security best practices outlined in the OWASP Top 10 and CWE guidelines for handling user input and file operations.
- Consider using a secure path resolution library like
path-sanitizerorsecure-path-resolvefor additional protection against path traversal attacks.
Rule ID: WS-I011-TYPESCRIPT-00001
| // doc id -> absolute source path, or null if neither .mdx nor .md exists. | ||
| function sourceFor(id) { | ||
| for (const ext of [".mdx", ".md"]) { | ||
| const p = path.resolve(DOCS_DIR, `${id}${ext}`); |
There was a problem hiding this comment.
Path Traversal Vulnerability in Node.js (CWE-22)
More Details
This rule detects potential path traversal vulnerabilities in Node.js applications. Path traversal vulnerabilities occur when user input is passed unsanitized to file system operations, allowing attackers to access arbitrary files and directories on the server.
This issue presents a significant security risk as it can lead to unauthorized access to sensitive data, code execution, and complete system compromise. If exploited, an attacker could read confidential files, modify system files, or even execute malicious code on the server.
| Attribute | Value |
|---|---|
| Impact | |
| Likelihood |
Remediation
Path traversal vulnerabilities allow an attacker to access arbitrary files on the system, potentially exposing sensitive data or enabling further attacks. This vulnerability arises when user input is passed unsanitized to path manipulation functions like path.join or path.resolve, allowing an attacker to traverse the file system using patterns like ../.
To fix this issue, user input should be sanitized or validated before being passed to path manipulation functions. This can be done by using allowlists, removing or encoding special characters, or validating the resulting path against a set of allowed directories.
Code examples
// VULNERABLE CODE - User input is passed directly to path.join
const userInput = req.query.file;
const filePath = path.join(__dirname, userInput);
fs.readFile(filePath, (err, data) => { ... });// SECURE CODE - User input is sanitized before path manipulation
const userInput = req.query.file;
const sanitizedInput = sanitizeInput(userInput); // Implement sanitization logic
const filePath = path.join(__dirname, sanitizedInput);
fs.readFile(filePath, (err, data) => { ... });Additional recommendations
- Follow the principle of least privilege and restrict file access as much as possible.
- Use allowlists instead of denylist-based input validation when possible.
- Consider using libraries like
path-sanitizerorsanitize-filenamefor input sanitization. - Adhere to the OWASP Input Validation Cheat Sheet and other relevant security standards.
- As an alternative approach, consider using a virtual file system or sandboxing techniques to isolate file operations from the main system.
Rule ID: WS-I013-JAVASCRIPT-00098
| const warnings = []; | ||
| const { text, sectionCount, linkCount } = buildLlmsTxt(siteConfig, warnings); | ||
|
|
||
| fs.writeFileSync(path.join(outDir, "llms.txt"), text); |
There was a problem hiding this comment.
Path Traversal Vulnerability in Node.js (CWE-22)
More Details
This rule detects potential path traversal vulnerabilities in Node.js applications. Path traversal vulnerabilities occur when user input is passed unsanitized to file system operations, allowing attackers to access arbitrary files and directories on the server.
This issue presents a significant security risk as it can lead to unauthorized access to sensitive data, code execution, and complete system compromise. If exploited, an attacker could read confidential files, modify system files, or even execute malicious code on the server.
| Attribute | Value |
|---|---|
| Impact | |
| Likelihood |
Remediation
Path traversal vulnerabilities allow an attacker to access arbitrary files on the system, potentially exposing sensitive data or enabling further attacks. This vulnerability arises when user input is passed unsanitized to path manipulation functions like path.join or path.resolve, allowing an attacker to traverse the file system using patterns like ../.
To fix this issue, user input should be sanitized or validated before being passed to path manipulation functions. This can be done by using allowlists, removing or encoding special characters, or validating the resulting path against a set of allowed directories.
Code examples
// VULNERABLE CODE - User input is passed directly to path.join
const userInput = req.query.file;
const filePath = path.join(__dirname, userInput);
fs.readFile(filePath, (err, data) => { ... });// SECURE CODE - User input is sanitized before path manipulation
const userInput = req.query.file;
const sanitizedInput = sanitizeInput(userInput); // Implement sanitization logic
const filePath = path.join(__dirname, sanitizedInput);
fs.readFile(filePath, (err, data) => { ... });Additional recommendations
- Follow the principle of least privilege and restrict file access as much as possible.
- Use allowlists instead of denylist-based input validation when possible.
- Consider using libraries like
path-sanitizerorsanitize-filenamefor input sanitization. - Adhere to the OWASP Input Validation Cheat Sheet and other relevant security standards.
- As an alternative approach, consider using a virtual file system or sandboxing techniques to isolate file operations from the main system.
Rule ID: WS-I013-JAVASCRIPT-00098
| const empty = { inline: [], blocks: [] }; | ||
|
|
||
| // Field-requirement / support badges. | ||
| if (BADGE[name]) return { inline: BADGE[name](), blocks: [] }; |
There was a problem hiding this comment.
Unsafe Dynamic Method Invocation (CWE-94)
More Details
This rule detects instances where non-static data is used to retrieve and execute functions from an object dynamically. This practice can be dangerous as it may allow executing arbitrary code if the data is user-controlled or untrusted.
The vulnerability arises when the application takes user input or external data and uses it to dynamically invoke methods or functions on an object. If an attacker can control the input, they may be able to execute arbitrary code within the application, leading to various security risks such as code injection, data tampering, or unauthorized access. The potential consequences of this vulnerability can range from data leakage to complete system compromise, depending on the application's functionality and the attacker's capabilities.
| Attribute | Value |
|---|---|
| Impact | |
| Likelihood |
Remediation
The use of non-static data to retrieve and execute functions from an object can lead to code injection vulnerabilities. If the data used to determine the function to execute is user-controlled or comes from an untrusted source, an attacker could potentially execute arbitrary code on the system, leading to various security risks such as data theft, system compromise, or denial of service.
To remediate this issue, it is recommended to use a whitelist approach, where only a predefined set of allowed functions can be executed. This can be achieved by using an object or map that maps function names to their corresponding function references. When executing a function, check if the requested function name exists in the whitelist, and if so, execute the corresponding function reference. If the requested function is not in the whitelist, do not execute it and handle the case appropriately (e.g., log the attempt, return an error, or take other appropriate actions).
Code examples
// VULNERABLE CODE - Non-static data is used to retrieve and execute a function
const obj = {
foo: () => console.log('foo'),
bar: () => console.log('bar')
};
const functionName = getUserInput(); // Potentially untrusted input
obj[functionName](); // Executing the function based on user input// SECURE CODE - Using a whitelist approach
const allowedFunctions = {
'foo': () => console.log('foo'),
'bar': () => console.log('bar')
};
const functionName = getUserInput();
if (allowedFunctions.hasOwnProperty(functionName)) {
allowedFunctions[functionName](); // Execute the function if it's in the whitelist
} else {
console.error('Invalid function name');
}Additional recommendations
- Follow the principle of least privilege and only allow the minimum set of functions required for the application to function correctly.
- Consider using a strict Content Security Policy (CSP) to prevent the execution of inline scripts and restrict the sources from which scripts can be loaded.
- Implement input validation and sanitization to ensure that user input is properly validated and sanitized before being used in any security-sensitive operations.
- Adhere to the OWASP Top 10 and other relevant security standards to mitigate common web application vulnerabilities.
- Consider using a secure coding library or framework that provides built-in protection against code injection vulnerabilities.
Rule ID: WS-I013-JAVASCRIPT-00106
| const p = path.resolve(DOCS_DIR, `${id}${ext}`); | ||
| // Path-traversal guard (CWE-22): sidebar ids must stay inside docs/. | ||
| if (!p.startsWith(DOCS_DIR + path.sep)) return null; | ||
| if (fs.existsSync(p)) return p; |
There was a problem hiding this comment.
Improper Limitation of Pathname to Restricted Directory (Path Traversal) (CWE-22)
More Details
Path traversal vulnerabilities occur when user-supplied input is used to construct file paths without proper validation or sanitization. This allows an attacker to access files and directories outside the intended scope, potentially exposing sensitive data or enabling unauthorized system access.
The risk stems from the application's failure to properly restrict file operations to a limited directory. By manipulating the file path with special characters like "../", an attacker can traverse the file system hierarchy and access arbitrary files or directories.
Successful exploitation of a path traversal vulnerability can lead to data breaches, unauthorized access to system resources, and potentially complete system compromise. It is crucial to validate and sanitize all user input used in file operations to prevent such attacks.
| Attribute | Value |
|---|---|
| Impact | |
| Likelihood |
Remediation
Path traversal vulnerabilities occur when user-supplied input is used to construct file paths without proper validation or sanitization. This allows an attacker to access files and directories outside the intended scope, potentially exposing sensitive data or enabling unauthorized system access. Successful exploitation of a path traversal vulnerability can lead to data breaches, unauthorized access to system resources, and potentially complete system compromise.
To fix this issue, you should validate and sanitize all user input used in file operations to prevent path traversal attacks. This can be achieved by using a secure path resolution library or by implementing strict input validation and sanitization routines. Avoid concatenating user input directly into file paths, and instead, use platform-specific path normalization functions to resolve paths safely.
Code examples
// VULNERABLE CODE - User input is concatenated directly into the file path
const fs = require('fs');
const userInput = "../../../sensitive.txt";
fs.readFile(`/app/files/${userInput}`, (err, data) => {
// ...
});// SECURE CODE - User input is sanitized, and path is resolved securely
const fs = require('fs');
const path = require('path');
const userInput = "../../../sensitive.txt";
const sanitizedPath = path.resolve('/app/files', path.normalize(userInput));
fs.readFile(sanitizedPath, (err, data) => {
// ...
});Additional recommendations
- Use the built-in
pathmodule in Node.js to safely construct file paths. - Implement strict input validation and sanitization routines for all user input used in file operations.
- Follow the principle of least privilege and restrict file operations to a limited directory scope.
- Adhere to security best practices outlined in the OWASP Top 10 and CWE guidelines for handling user input and file operations.
- Consider using a secure path resolution library like
path-sanitizerorsecure-path-resolvefor additional protection against path traversal attacks.
Rule ID: WS-I011-TYPESCRIPT-00001
| // robots.txt) carrying the Sitemap: hints. If one already exists, we only | ||
| // append the Sitemap: lines we're missing — idempotent, never clobbering. | ||
| function ensureRobotsSitemaps(outDir, sitemapUrls) { | ||
| const robotsPath = path.join(outDir, ROBOTS_FILE); |
There was a problem hiding this comment.
Path Traversal Vulnerability in Node.js (CWE-22)
More Details
This rule detects potential path traversal vulnerabilities in Node.js applications. Path traversal vulnerabilities occur when user input is passed unsanitized to file system operations, allowing attackers to access arbitrary files and directories on the server.
This issue presents a significant security risk as it can lead to unauthorized access to sensitive data, code execution, and complete system compromise. If exploited, an attacker could read confidential files, modify system files, or even execute malicious code on the server.
| Attribute | Value |
|---|---|
| Impact | |
| Likelihood |
Remediation
Path traversal vulnerabilities allow an attacker to access arbitrary files on the system, potentially exposing sensitive data or enabling further attacks. This vulnerability arises when user input is passed unsanitized to path manipulation functions like path.join or path.resolve, allowing an attacker to traverse the file system using patterns like ../.
To fix this issue, user input should be sanitized or validated before being passed to path manipulation functions. This can be done by using allowlists, removing or encoding special characters, or validating the resulting path against a set of allowed directories.
Code examples
// VULNERABLE CODE - User input is passed directly to path.join
const userInput = req.query.file;
const filePath = path.join(__dirname, userInput);
fs.readFile(filePath, (err, data) => { ... });// SECURE CODE - User input is sanitized before path manipulation
const userInput = req.query.file;
const sanitizedInput = sanitizeInput(userInput); // Implement sanitization logic
const filePath = path.join(__dirname, sanitizedInput);
fs.readFile(filePath, (err, data) => { ... });Additional recommendations
- Follow the principle of least privilege and restrict file access as much as possible.
- Use allowlists instead of denylist-based input validation when possible.
- Consider using libraries like
path-sanitizerorsanitize-filenamefor input sanitization. - Adhere to the OWASP Input Validation Cheat Sheet and other relevant security standards.
- As an alternative approach, consider using a virtual file system or sandboxing techniques to isolate file operations from the main system.
Rule ID: WS-I013-JAVASCRIPT-00098
|
|
||
| // Path-traversal guard (CWE-22): `rel` derives from frontmatter slugs; | ||
| // never write a mirror outside the build output directory. | ||
| const outPath = path.resolve(outDir, rel); |
There was a problem hiding this comment.
Path Traversal Vulnerability in Node.js (CWE-22)
More Details
This rule detects potential path traversal vulnerabilities in Node.js applications. Path traversal vulnerabilities occur when user input is passed unsanitized to file system operations, allowing attackers to access arbitrary files and directories on the server.
This issue presents a significant security risk as it can lead to unauthorized access to sensitive data, code execution, and complete system compromise. If exploited, an attacker could read confidential files, modify system files, or even execute malicious code on the server.
| Attribute | Value |
|---|---|
| Impact | |
| Likelihood |
Remediation
Path traversal vulnerabilities allow an attacker to access arbitrary files on the system, potentially exposing sensitive data or enabling further attacks. This vulnerability arises when user input is passed unsanitized to path manipulation functions like path.join or path.resolve, allowing an attacker to traverse the file system using patterns like ../.
To fix this issue, user input should be sanitized or validated before being passed to path manipulation functions. This can be done by using allowlists, removing or encoding special characters, or validating the resulting path against a set of allowed directories.
Code examples
// VULNERABLE CODE - User input is passed directly to path.join
const userInput = req.query.file;
const filePath = path.join(__dirname, userInput);
fs.readFile(filePath, (err, data) => { ... });// SECURE CODE - User input is sanitized before path manipulation
const userInput = req.query.file;
const sanitizedInput = sanitizeInput(userInput); // Implement sanitization logic
const filePath = path.join(__dirname, sanitizedInput);
fs.readFile(filePath, (err, data) => { ... });Additional recommendations
- Follow the principle of least privilege and restrict file access as much as possible.
- Use allowlists instead of denylist-based input validation when possible.
- Consider using libraries like
path-sanitizerorsanitize-filenamefor input sanitization. - Adhere to the OWASP Input Validation Cheat Sheet and other relevant security standards.
- As an alternative approach, consider using a virtual file system or sandboxing techniques to isolate file operations from the main system.
Rule ID: WS-I013-JAVASCRIPT-00098
| // Path-traversal guard (CWE-22): `rel` derives from frontmatter slugs; | ||
| // never write a mirror outside the build output directory. | ||
| const outPath = path.resolve(outDir, rel); | ||
| if (!outPath.startsWith(path.resolve(outDir) + path.sep)) { |
There was a problem hiding this comment.
Path Traversal Vulnerability in Node.js (CWE-22)
More Details
This rule detects potential path traversal vulnerabilities in Node.js applications. Path traversal vulnerabilities occur when user input is passed unsanitized to file system operations, allowing attackers to access arbitrary files and directories on the server.
This issue presents a significant security risk as it can lead to unauthorized access to sensitive data, code execution, and complete system compromise. If exploited, an attacker could read confidential files, modify system files, or even execute malicious code on the server.
| Attribute | Value |
|---|---|
| Impact | |
| Likelihood |
Remediation
Path traversal vulnerabilities allow an attacker to access arbitrary files on the system, potentially exposing sensitive data or enabling further attacks. This vulnerability arises when user input is passed unsanitized to path manipulation functions like path.join or path.resolve, allowing an attacker to traverse the file system using patterns like ../.
To fix this issue, user input should be sanitized or validated before being passed to path manipulation functions. This can be done by using allowlists, removing or encoding special characters, or validating the resulting path against a set of allowed directories.
Code examples
// VULNERABLE CODE - User input is passed directly to path.join
const userInput = req.query.file;
const filePath = path.join(__dirname, userInput);
fs.readFile(filePath, (err, data) => { ... });// SECURE CODE - User input is sanitized before path manipulation
const userInput = req.query.file;
const sanitizedInput = sanitizeInput(userInput); // Implement sanitization logic
const filePath = path.join(__dirname, sanitizedInput);
fs.readFile(filePath, (err, data) => { ... });Additional recommendations
- Follow the principle of least privilege and restrict file access as much as possible.
- Use allowlists instead of denylist-based input validation when possible.
- Consider using libraries like
path-sanitizerorsanitize-filenamefor input sanitization. - Adhere to the OWASP Input Validation Cheat Sheet and other relevant security standards.
- As an alternative approach, consider using a virtual file system or sandboxing techniques to isolate file operations from the main system.
Rule ID: WS-I013-JAVASCRIPT-00098
| return matter.stringify("", data).trimEnd(); | ||
| } | ||
|
|
||
| const defaultReadFile = (p) => fs.readFileSync(p, "utf8"); |
There was a problem hiding this comment.
Improper Limitation of Pathname to Restricted Directory (Path Traversal) (CWE-22)
More Details
Path traversal vulnerabilities occur when user-supplied input is used to construct file paths without proper validation or sanitization. This allows an attacker to access files and directories outside the intended scope, potentially exposing sensitive data or enabling unauthorized system access.
The risk stems from the application's failure to properly restrict file operations to a limited directory. By manipulating the file path with special characters like "../", an attacker can traverse the file system hierarchy and access arbitrary files or directories.
Successful exploitation of a path traversal vulnerability can lead to data breaches, unauthorized access to system resources, and potentially complete system compromise. It is crucial to validate and sanitize all user input used in file operations to prevent such attacks.
| Attribute | Value |
|---|---|
| Impact | |
| Likelihood |
Remediation
Path traversal vulnerabilities occur when user-supplied input is used to construct file paths without proper validation or sanitization. This allows an attacker to access files and directories outside the intended scope, potentially exposing sensitive data or enabling unauthorized system access. Successful exploitation of a path traversal vulnerability can lead to data breaches, unauthorized access to system resources, and potentially complete system compromise.
To fix this issue, you should validate and sanitize all user input used in file operations to prevent path traversal attacks. This can be achieved by using a secure path resolution library or by implementing strict input validation and sanitization routines. Avoid concatenating user input directly into file paths, and instead, use platform-specific path normalization functions to resolve paths safely.
Code examples
// VULNERABLE CODE - User input is concatenated directly into the file path
const fs = require('fs');
const userInput = "../../../sensitive.txt";
fs.readFile(`/app/files/${userInput}`, (err, data) => {
// ...
});// SECURE CODE - User input is sanitized, and path is resolved securely
const fs = require('fs');
const path = require('path');
const userInput = "../../../sensitive.txt";
const sanitizedPath = path.resolve('/app/files', path.normalize(userInput));
fs.readFile(sanitizedPath, (err, data) => {
// ...
});Additional recommendations
- Use the built-in
pathmodule in Node.js to safely construct file paths. - Implement strict input validation and sanitization routines for all user input used in file operations.
- Follow the principle of least privilege and restrict file operations to a limited directory scope.
- Adhere to security best practices outlined in the OWASP Top 10 and CWE guidelines for handling user input and file operations.
- Consider using a secure path resolution library like
path-sanitizerorsecure-path-resolvefor additional protection against path traversal attacks.
Rule ID: WS-I011-TYPESCRIPT-00001
|
|
||
| it("emits many mirrors across the corpus", () => { | ||
| const count = (dir) => | ||
| fs.readdirSync(dir, { withFileTypes: true }).reduce((n, e) => { |
There was a problem hiding this comment.
Improper Limitation of Pathname to Restricted Directory (Path Traversal) (CWE-22)
More Details
Path traversal vulnerabilities occur when user-supplied input is used to construct file paths without proper validation or sanitization. This allows an attacker to access files and directories outside the intended scope, potentially exposing sensitive data or enabling unauthorized system access.
The risk stems from the application's failure to properly restrict file operations to a limited directory. By manipulating the file path with special characters like "../", an attacker can traverse the file system hierarchy and access arbitrary files or directories.
Successful exploitation of a path traversal vulnerability can lead to data breaches, unauthorized access to system resources, and potentially complete system compromise. It is crucial to validate and sanitize all user input used in file operations to prevent such attacks.
| Attribute | Value |
|---|---|
| Impact | |
| Likelihood |
Remediation
Path traversal vulnerabilities occur when user-supplied input is used to construct file paths without proper validation or sanitization. This allows an attacker to access files and directories outside the intended scope, potentially exposing sensitive data or enabling unauthorized system access. Successful exploitation of a path traversal vulnerability can lead to data breaches, unauthorized access to system resources, and potentially complete system compromise.
To fix this issue, you should validate and sanitize all user input used in file operations to prevent path traversal attacks. This can be achieved by using a secure path resolution library or by implementing strict input validation and sanitization routines. Avoid concatenating user input directly into file paths, and instead, use platform-specific path normalization functions to resolve paths safely.
Code examples
// VULNERABLE CODE - User input is concatenated directly into the file path
const fs = require('fs');
const userInput = "../../../sensitive.txt";
fs.readFile(`/app/files/${userInput}`, (err, data) => {
// ...
});// SECURE CODE - User input is sanitized, and path is resolved securely
const fs = require('fs');
const path = require('path');
const userInput = "../../../sensitive.txt";
const sanitizedPath = path.resolve('/app/files', path.normalize(userInput));
fs.readFile(sanitizedPath, (err, data) => {
// ...
});Additional recommendations
- Use the built-in
pathmodule in Node.js to safely construct file paths. - Implement strict input validation and sanitization routines for all user input used in file operations.
- Follow the principle of least privilege and restrict file operations to a limited directory scope.
- Adhere to security best practices outlined in the OWASP Top 10 and CWE guidelines for handling user input and file operations.
- Consider using a secure path resolution library like
path-sanitizerorsecure-path-resolvefor additional protection against path traversal attacks.
Rule ID: WS-I011-TYPESCRIPT-00001
| for (const entry of fs.readdirSync(dir, { withFileTypes: true })) { | ||
| // Docusaurus excludes `_`-prefixed files/dirs from routing (partials). | ||
| if (entry.name.startsWith("_")) continue; | ||
| const full = path.join(dir, entry.name); |
There was a problem hiding this comment.
Path Traversal Vulnerability in Node.js (CWE-22)
More Details
This rule detects potential path traversal vulnerabilities in Node.js applications. Path traversal vulnerabilities occur when user input is passed unsanitized to file system operations, allowing attackers to access arbitrary files and directories on the server.
This issue presents a significant security risk as it can lead to unauthorized access to sensitive data, code execution, and complete system compromise. If exploited, an attacker could read confidential files, modify system files, or even execute malicious code on the server.
| Attribute | Value |
|---|---|
| Impact | |
| Likelihood |
Remediation
Path traversal vulnerabilities allow an attacker to access arbitrary files on the system, potentially exposing sensitive data or enabling further attacks. This vulnerability arises when user input is passed unsanitized to path manipulation functions like path.join or path.resolve, allowing an attacker to traverse the file system using patterns like ../.
To fix this issue, user input should be sanitized or validated before being passed to path manipulation functions. This can be done by using allowlists, removing or encoding special characters, or validating the resulting path against a set of allowed directories.
Code examples
// VULNERABLE CODE - User input is passed directly to path.join
const userInput = req.query.file;
const filePath = path.join(__dirname, userInput);
fs.readFile(filePath, (err, data) => { ... });// SECURE CODE - User input is sanitized before path manipulation
const userInput = req.query.file;
const sanitizedInput = sanitizeInput(userInput); // Implement sanitization logic
const filePath = path.join(__dirname, sanitizedInput);
fs.readFile(filePath, (err, data) => { ... });Additional recommendations
- Follow the principle of least privilege and restrict file access as much as possible.
- Use allowlists instead of denylist-based input validation when possible.
- Consider using libraries like
path-sanitizerorsanitize-filenamefor input sanitization. - Adhere to the OWASP Input Validation Cheat Sheet and other relevant security standards.
- As an alternative approach, consider using a virtual file system or sandboxing techniques to isolate file operations from the main system.
Rule ID: WS-I013-JAVASCRIPT-00098
| for (const entry of fs.readdirSync(dir, { withFileTypes: true })) { | ||
| // Docusaurus excludes `_`-prefixed files/dirs from routing (partials). | ||
| if (entry.name.startsWith("_")) continue; | ||
| const full = path.join(dir, entry.name); |
There was a problem hiding this comment.
Path Traversal Vulnerability in Node.js (CWE-22)
More Details
This rule detects potential path traversal vulnerabilities in Node.js applications. Path traversal vulnerabilities occur when user input is passed unsanitized to file system operations, allowing attackers to access arbitrary files and directories on the server.
This issue presents a significant security risk as it can lead to unauthorized access to sensitive data, code execution, and complete system compromise. If exploited, an attacker could read confidential files, modify system files, or even execute malicious code on the server.
| Attribute | Value |
|---|---|
| Impact | |
| Likelihood |
Remediation
Path traversal vulnerabilities allow an attacker to access arbitrary files on the system, potentially exposing sensitive data or enabling further attacks. This vulnerability arises when user input is passed unsanitized to path manipulation functions like path.join or path.resolve, allowing an attacker to traverse the file system using patterns like ../.
To fix this issue, user input should be sanitized or validated before being passed to path manipulation functions. This can be done by using allowlists, removing or encoding special characters, or validating the resulting path against a set of allowed directories.
Code examples
// VULNERABLE CODE - User input is passed directly to path.join
const userInput = req.query.file;
const filePath = path.join(__dirname, userInput);
fs.readFile(filePath, (err, data) => { ... });// SECURE CODE - User input is sanitized before path manipulation
const userInput = req.query.file;
const sanitizedInput = sanitizeInput(userInput); // Implement sanitization logic
const filePath = path.join(__dirname, sanitizedInput);
fs.readFile(filePath, (err, data) => { ... });Additional recommendations
- Follow the principle of least privilege and restrict file access as much as possible.
- Use allowlists instead of denylist-based input validation when possible.
- Consider using libraries like
path-sanitizerorsanitize-filenamefor input sanitization. - Adhere to the OWASP Input Validation Cheat Sheet and other relevant security standards.
- As an alternative approach, consider using a virtual file system or sandboxing techniques to isolate file operations from the main system.
Rule ID: WS-I013-JAVASCRIPT-00098
…arts at 1, SupportingDocumentCollection.Updated webhook, AccountHolderProjectSettingsNotEligibleRejection, accountId and conditional consentRedirectUrl, projectInfo scope
…mber 2026, removal on 31 December 2026
…h diagram, and relabel the mandate subgraph
…s, and the sidebar
…n's voice, plainer connectives, emoji-free tab labels
… Swan's voice, tidy list references
…s, and the footnote lead-in
…ejection, consent ordering semantics, exportUserData filters, addDigitalCards, retired idVerified and Authenticator.type, S2S consents query
…n-up confirmation step, deduplicated consent notification facts, placeholder-only Dashboard deactivation
| "react-dom": "^18.2.0" | ||
| }, | ||
| "devDependencies": { | ||
| "vitest": "3.2.7" |
There was a problem hiding this comment.
The following vulnerability impacts vitest versions <4.1.11: CVE-2026-84373.
It can be remediated by updating to version 4.1.11 or higher.
| "vitest": "3.2.7" | |
| "vitest": "4.1.11" |
No description provided.