-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(increasing the accuracy of the client-side prototype pollution m…
…echanism): improvement It is unlikely that a native function can be used for prototype pollution. By determining whether a function is native, the code can avoid executing native functions that may result in unexpected behavior or errors. The toString() method returns a string representation of a function, including its source code, so determining whether the string representation contains '[native code]' allows the code to determine whether it is native.
- Loading branch information
1 parent
64b2ee2
commit a1cceb0
Showing
2 changed files
with
3 additions
and
46 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,50 +1,5 @@ | ||
<!DOCTYPE html> | ||
|
||
<html> | ||
<script> | ||
const types = [Object, String, Number, Array, Function, Boolean]; | ||
|
||
const prototypesPropertiesReducer = (acc, type) => ({ | ||
...acc, | ||
[type.name]: Object.getOwnPropertyNames(type.prototype), | ||
}); | ||
const intersectProtoPropNameReducer = (acc, type, prev, curr) => | ||
prev !== undefined && curr !== undefined | ||
? { | ||
...acc, | ||
[type.name]: curr[type.name].filter((protoPropName) => !prev[type.name].includes(protoPropName)), | ||
} | ||
: { ...acc }; | ||
|
||
const prototypePropertyNames = () => types.reduce(prototypesPropertiesReducer, {}); | ||
const intersectPropertyNames = (prev, curr) => | ||
types.reduce((acc, type) => intersectProtoPropNameReducer(acc, type, prev, curr), {}); | ||
</script> | ||
|
||
<script> | ||
const before = prototypePropertyNames(); | ||
</script> | ||
|
||
<script id="target"></script> | ||
|
||
<script> | ||
const after = prototypePropertyNames(); | ||
|
||
const result = intersectPropertyNames(before, after); | ||
|
||
const probe = () => | ||
Object.keys(result).reduce((acc, key) => { | ||
for (let propKey of result[key]) { | ||
const payload = `${key}.prototype.${propKey}`; | ||
try { | ||
if (typeof eval(payload) === 'function' && eval(payload).call() === window) { | ||
acc.push(payload); | ||
} | ||
} catch (e) { | ||
// Nothing to catch now. | ||
} | ||
} | ||
return acc; | ||
}, []); | ||
</script> | ||
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters