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 22 commits into
base: main
Choose a base branch
from
Open

Spicerack #1612

wants to merge 22 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 22 days 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.
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