Skip to content

support creating from rest logs#49

Open
ozkeisar wants to merge 2 commits intomainfrom
create-preset-from-logs
Open

support creating from rest logs#49
ozkeisar wants to merge 2 commits intomainfrom
create-preset-from-logs

Conversation

@ozkeisar
Copy link
Copy Markdown
Owner

No description provided.

});

fs.writeFileSync(
`${presetsPath + presetFolder.filename}.json`,

Check failure

Code scanning / CodeQL

Uncontrolled data used in path expression High

This path depends on a
user-provided value
.

Copilot Autofix

AI 9 months ago

To fix the issue, we need to ensure that presetFolder.filename is sanitized or validated before being used to construct the file path. Since the filename is expected to be a simple name without path components, we can use the sanitize-filename npm package to remove any special characters or path traversal sequences. This will ensure that the constructed file path remains within the intended directory.

Steps to fix:

  1. Install the sanitize-filename package if it is not already installed.
  2. Import the sanitize-filename package in src/backend/utils/presetHelpers.ts.
  3. Use sanitizeFilename to sanitize presetFolder.filename before constructing the file path in the savePresetFolder function.

Suggested changeset 2
src/backend/utils/presetHelpers.ts

Autofix patch

Autofix patch
Run the following command in your local git repository to apply this patch
cat << 'EOF' | git apply
diff --git a/src/backend/utils/presetHelpers.ts b/src/backend/utils/presetHelpers.ts
--- a/src/backend/utils/presetHelpers.ts
+++ b/src/backend/utils/presetHelpers.ts
@@ -4,2 +4,3 @@
 import fs from 'fs';
+import sanitizeFilename from 'sanitize-filename';
 import {
@@ -392,4 +393,5 @@
 
+  const sanitizedFilename = sanitizeFilename(presetFolder.filename);
   fs.writeFileSync(
-    `${presetsPath + presetFolder.filename}.json`,
+    `${presetsPath + sanitizedFilename}.json`,
     fileData,
EOF
@@ -4,2 +4,3 @@
import fs from 'fs';
import sanitizeFilename from 'sanitize-filename';
import {
@@ -392,4 +393,5 @@

const sanitizedFilename = sanitizeFilename(presetFolder.filename);
fs.writeFileSync(
`${presetsPath + presetFolder.filename}.json`,
`${presetsPath + sanitizedFilename}.json`,
fileData,
package.json
Outside changed files

Autofix patch

Autofix patch
Run the following command in your local git repository to apply this patch
cat << 'EOF' | git apply
diff --git a/package.json b/package.json
--- a/package.json
+++ b/package.json
@@ -154,3 +154,4 @@
     "uuidv4": "^6.2.13",
-    "zustand": "^4.5.1"
+    "zustand": "^4.5.1",
+    "sanitize-filename": "^1.6.3"
   },
EOF
@@ -154,3 +154,4 @@
"uuidv4": "^6.2.13",
"zustand": "^4.5.1"
"zustand": "^4.5.1",
"sanitize-filename": "^1.6.3"
},
This fix introduces these dependencies
Package Version Security advisories
sanitize-filename (npm) 1.6.3 None
Copilot is powered by AI and may make mistakes. Always verify output.
preset: Preset,
): void => {
if (!presetFolder.presetsHash) {
presetFolder.presetsHash = {};

Check warning

Code scanning / CodeQL

Prototype-polluting assignment Medium

This assignment may alter Object.prototype if a malicious '__proto__' string is injected from
user controlled input
.

Copilot Autofix

AI 9 months ago

To fix the issue, we need to prevent prototype pollution by ensuring that user-controlled keys cannot modify Object.prototype. This can be achieved by:

  1. Using a Map instead of a plain object for presetsHash, as Map does not inherit from Object.prototype and is immune to prototype pollution.
  2. Alternatively, creating a prototype-less object using Object.create(null) for presetsHash ensures that it does not inherit from Object.prototype.

The best approach here is to use Object.create(null) for presetsHash to minimize changes to the existing codebase while addressing the vulnerability.


Suggested changeset 1
src/backend/utils/presetHelpers.ts

Autofix patch

Autofix patch
Run the following command in your local git repository to apply this patch
cat << 'EOF' | git apply
diff --git a/src/backend/utils/presetHelpers.ts b/src/backend/utils/presetHelpers.ts
--- a/src/backend/utils/presetHelpers.ts
+++ b/src/backend/utils/presetHelpers.ts
@@ -404,3 +404,3 @@
   if (!presetFolder.presetsHash) {
-    presetFolder.presetsHash = {};
+    presetFolder.presetsHash = Object.create(null);
   }
EOF
@@ -404,3 +404,3 @@
if (!presetFolder.presetsHash) {
presetFolder.presetsHash = {};
presetFolder.presetsHash = Object.create(null);
}
Copilot is powered by AI and may make mistakes. Always verify output.
…ignment

Co-authored-by: Copilot Autofix powered by AI <62310815+github-advanced-security[bot]@users.noreply.github.com>
const newParent = createNewParent(parentPath);

if (!server.parentRoutesHash) {
server.parentRoutesHash = Object.create(null);

Check warning

Code scanning / CodeQL

Prototype-polluting assignment Medium

This assignment may alter Object.prototype if a malicious '__proto__' string is injected from
user controlled input
.

Copilot Autofix

AI 9 months ago

To fix the issue, we need to ensure that keys assigned to server.parentRoutesHash are sanitized to prevent prototype-polluting keys like __proto__, constructor, or prototype. This can be achieved by validating the newParent.id before using it as a key. If the key is invalid, we should throw an error or handle it appropriately.

The best approach is to add a utility function to validate keys and use it in the ensureParentExists function. This ensures that only safe keys are used in the assignment.


Suggested changeset 1
src/backend/utils/presetHelpers.ts

Autofix patch

Autofix patch
Run the following command in your local git repository to apply this patch
cat << 'EOF' | git apply
diff --git a/src/backend/utils/presetHelpers.ts b/src/backend/utils/presetHelpers.ts
--- a/src/backend/utils/presetHelpers.ts
+++ b/src/backend/utils/presetHelpers.ts
@@ -155,2 +155,6 @@
 
+const isValidKey = (key: string): boolean => {
+  return !['__proto__', 'constructor', 'prototype'].includes(key);
+};
+
 export const ensureParentExists = (
@@ -170,2 +174,7 @@
   }
+
+  if (!isValidKey(newParent.id)) {
+    throw new Error(`Invalid key detected: ${newParent.id}`);
+  }
+
   server.parentRoutesHash[newParent.id] = newParent;
EOF
@@ -155,2 +155,6 @@

const isValidKey = (key: string): boolean => {
return !['__proto__', 'constructor', 'prototype'].includes(key);
};

export const ensureParentExists = (
@@ -170,2 +174,7 @@
}

if (!isValidKey(newParent.id)) {
throw new Error(`Invalid key detected: ${newParent.id}`);
}

server.parentRoutesHash[newParent.id] = newParent;
Copilot is powered by AI and may make mistakes. Always verify output.
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