-
Notifications
You must be signed in to change notification settings - Fork 3
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
base: main
Are you sure you want to change the base?
Spicerack #1612
Conversation
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
library input
Show autofix suggestion
Hide autofix suggestion
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:
- Validating the
assetName
andassetType
to ensure they do not contain dangerous values like__proto__
,constructor
, orprototype
. - Using a
Map
object instead of a plain object forpreppedData.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
.
-
Copy modified line R309 -
Copy modified lines R362-R363 -
Copy modified lines R366-R370 -
Copy modified line R381
@@ -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)); | ||
}); |
# Conflicts: # lib/index.js
No description provided.