Skip to content

Commit

Permalink
fix: potential prototype pollution attacks (#10455)
Browse files Browse the repository at this point in the history
Prevent event listeners of type "__proto__" to pollute the global Object
prototype. This is fixed by creating objects with null prototype so they
don't have a "__proto__" property.
  • Loading branch information
matias-la authored and satya164 committed Nov 27, 2022
1 parent cdf1b72 commit aa062f0
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 5 deletions.
4 changes: 3 additions & 1 deletion packages/core/src/useEventEmitter.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,9 @@ export default function useEventEmitter<T extends Record<string, any>>(
listenRef.current = listen;
});

const listeners = React.useRef<Record<string, Record<string, Listeners>>>({});
const listeners = React.useRef<Record<string, Record<string, Listeners>>>(
Object.create(null)
);

const create = React.useCallback((target: string) => {
const removeListener = (type: string, callback: (data: any) => void) => {
Expand Down
10 changes: 6 additions & 4 deletions packages/core/src/useKeyedChildListeners.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,12 @@ export default function useKeyedChildListeners() {
string,
KeyedListenerMap[K] | undefined
>;
}>({
getState: {},
beforeRemove: {},
});
}>(
Object.assign(Object.create(null), {
getState: {},
beforeRemove: {},
})
);

const addKeyedListener = React.useCallback(
<T extends keyof KeyedListenerMap>(
Expand Down

0 comments on commit aa062f0

Please sign in to comment.