Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Spicerack #1612

Open
wants to merge 20 commits into
base: main
Choose a base branch
from
Open

Spicerack #1612

wants to merge 20 commits into from

Conversation

jperezlatimes
Copy link
Contributor

No description provided.

lib/index.js Outdated
preppedData.assets[normalizedAssetType][normalizedAssetName][ext] =
this.getStaticPath(path);
});
preppedData.assets[normalizedAssetType][normalizedAssetName][ext] =

Check warning

Code scanning / CodeQL

Prototype-polluting assignment Medium

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

Copilot Autofix AI 9 days ago

To fix the problem, we need to ensure that the keys used in the preppedData object cannot lead to prototype pollution. This can be achieved by:

  1. Validating the assetName and assetType to ensure they do not contain dangerous values like __proto__, constructor, or prototype.
  2. Using a Map object instead of a plain object for preppedData.assets to avoid prototype pollution.

The best way to fix the problem without changing existing functionality is to implement both of these measures. We will validate the keys and use a Map for preppedData.assets.

Suggested changeset 1
lib/index.js

Autofix patch

Autofix patch
Run the following command in your local git repository to apply this patch
cat << 'EOF' | git apply
diff --git a/lib/index.js b/lib/index.js
--- a/lib/index.js
+++ b/lib/index.js
@@ -308,3 +308,3 @@
     const preppedData = {
-      assets: {},
+      assets: new Map(),
       additionalData: []
@@ -361,7 +361,11 @@
 
-      if (!preppedData.assets[normalizedAssetType]) {
-        preppedData.assets[normalizedAssetType] = {};
+      if (['__proto__', 'constructor', 'prototype'].includes(normalizedAssetType) || ['__proto__', 'constructor', 'prototype'].includes(normalizedAssetName)) {
+        throw new Error('Invalid assetType or assetName');
       }
 
-      preppedData.assets[normalizedAssetType][normalizedAssetName] = {};
+      if (!preppedData.assets.has(normalizedAssetType)) {
+        preppedData.assets.set(normalizedAssetType, new Map());
+      }
+
+      preppedData.assets.get(normalizedAssetType).set(normalizedAssetName, new Map());
 
@@ -376,4 +380,3 @@
 
-        preppedData.assets[normalizedAssetType][normalizedAssetName][ext] =
-          this.getStaticPath(path);
+        preppedData.assets.get(normalizedAssetType).get(normalizedAssetName).set(ext, this.getStaticPath(path));
       });
EOF
@@ -308,3 +308,3 @@
const preppedData = {
assets: {},
assets: new Map(),
additionalData: []
@@ -361,7 +361,11 @@

if (!preppedData.assets[normalizedAssetType]) {
preppedData.assets[normalizedAssetType] = {};
if (['__proto__', 'constructor', 'prototype'].includes(normalizedAssetType) || ['__proto__', 'constructor', 'prototype'].includes(normalizedAssetName)) {
throw new Error('Invalid assetType or assetName');
}

preppedData.assets[normalizedAssetType][normalizedAssetName] = {};
if (!preppedData.assets.has(normalizedAssetType)) {
preppedData.assets.set(normalizedAssetType, new Map());
}

preppedData.assets.get(normalizedAssetType).set(normalizedAssetName, new Map());

@@ -376,4 +380,3 @@

preppedData.assets[normalizedAssetType][normalizedAssetName][ext] =
this.getStaticPath(path);
preppedData.assets.get(normalizedAssetType).get(normalizedAssetName).set(ext, this.getStaticPath(path));
});
Copilot is powered by AI and may make mistakes. Always verify output.
Positive Feedback
Negative Feedback

Provide additional feedback

Please help us improve GitHub Copilot by sharing more details about this comment.

Please select one or more of the options
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.

1 participant