Skip to content

Conversation

@jperezlatimes
Copy link
Contributor

No description provided.

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 about 1 year ago

To fix the problem, we need to ensure that the assetName and assetType values cannot be used to modify Object.prototype. This can be achieved by adding checks to prevent these values from being __proto__, constructor, or prototype. Additionally, we can use a Map object to store the assets, which is resilient to prototype pollution.

  • Add checks to ensure assetName and assetType are not __proto__, constructor, or prototype.
  • Use a Map object to store the assets instead of a plain object.
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: [],
@@ -357,7 +357,10 @@
 
-      if (!preppedData.assets[normalizedAssetType]) {
-        preppedData.assets[normalizedAssetType] = {};
+      if (normalizedAssetName === '__proto__' || normalizedAssetName === 'constructor' || normalizedAssetName === 'prototype') {
+        throw new Error(`Invalid assetName: ${normalizedAssetName}`);
+      }
+      if (!preppedData.assets.has(normalizedAssetType)) {
+        preppedData.assets.set(normalizedAssetType, new Map());
       }
 
-      preppedData.assets[normalizedAssetType][normalizedAssetName] = {};
+      preppedData.assets.get(normalizedAssetType).set(normalizedAssetName, new Map());
 
@@ -372,4 +375,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: [],
@@ -357,7 +357,10 @@

if (!preppedData.assets[normalizedAssetType]) {
preppedData.assets[normalizedAssetType] = {};
if (normalizedAssetName === '__proto__' || normalizedAssetName === 'constructor' || normalizedAssetName === 'prototype') {
throw new Error(`Invalid assetName: ${normalizedAssetName}`);
}
if (!preppedData.assets.has(normalizedAssetType)) {
preppedData.assets.set(normalizedAssetType, new Map());
}

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

@@ -372,4 +375,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.
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