-
Notifications
You must be signed in to change notification settings - Fork 11
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
Cleaning #105
base: master
Are you sure you want to change the base?
Conversation
} | ||
private static pushScene(scene: Scene, type: keyof Events, target: Object3D): void { | ||
const sceneCache = this._events[scene.id] ?? (this._events[scene.id] = {}); | ||
const eventCache = sceneCache[type] ?? (sceneCache[type] = new Set()); |
Check warning
Code scanning / CodeQL
Prototype-polluting assignment Medium
library input
This assignment may alter Object.prototype if a malicious '__proto__' string is injected from
library input
This assignment may alter Object.prototype if a malicious '__proto__' string is injected from
library input
This assignment may alter Object.prototype if a malicious '__proto__' string is injected from
library input
This assignment may alter Object.prototype if a malicious '__proto__' string is injected from
library input
This assignment may alter Object.prototype if a malicious '__proto__' string is injected from
library input
This assignment may alter Object.prototype if a malicious '__proto__' string is injected from
library input
This assignment may alter Object.prototype if a malicious '__proto__' string is injected from
library input
Show autofix suggestion
Hide autofix suggestion
Copilot Autofix AI 12 days ago
To fix the problem, we need to ensure that the type
value cannot be used to modify Object.prototype
. This can be achieved by using a Map
object instead of a plain object for sceneCache
. Map
objects do not have the same prototype properties as plain objects, making them resilient to prototype pollution.
We will replace the plain object used for sceneCache
with a Map
object and update the relevant code to use Map
methods for setting and getting values.
-
Copy modified line R9 -
Copy modified lines R32-R41 -
Copy modified line R46 -
Copy modified line R48 -
Copy modified line R55 -
Copy modified line R57 -
Copy modified lines R62-R64 -
Copy modified lines R71-R73
@@ -8,3 +8,3 @@ | ||
private static _allowedEventsSet = new Set<keyof Events>(['viewportresize', 'beforeanimate', 'animate', 'afteranimate'] as (keyof MiscEvents)[]); | ||
private static _events: { [x: number]: SceneEventsCache } = {}; | ||
private static _events: Map<number, Map<keyof Events, Set<Object3D>>> = new Map(); | ||
|
||
@@ -31,4 +31,12 @@ | ||
private static pushScene(scene: Scene, type: keyof Events, target: Object3D): void { | ||
const sceneCache = this._events[scene.id] ?? (this._events[scene.id] = {}); | ||
const eventCache = sceneCache[type] ?? (sceneCache[type] = new Set()); | ||
let sceneCache = this._events.get(scene.id); | ||
if (!sceneCache) { | ||
sceneCache = new Map(); | ||
this._events.set(scene.id, sceneCache); | ||
} | ||
let eventCache = sceneCache.get(type); | ||
if (!eventCache) { | ||
eventCache = new Set(); | ||
sceneCache.set(type, eventCache); | ||
} | ||
eventCache.add(target); | ||
@@ -37,6 +45,5 @@ | ||
public static removeAll(target: Object3D): void { | ||
const sceneCache = this._events[target.scene?.id]; | ||
const sceneCache = this._events.get(target.scene?.id); | ||
if (sceneCache) { | ||
for (const key in sceneCache) { | ||
const eventCache = sceneCache[key]; | ||
for (const [key, eventCache] of sceneCache.entries()) { | ||
eventCache.delete(target); | ||
@@ -47,5 +54,5 @@ | ||
public static remove(type: keyof Events, target: Object3D): void { | ||
const sceneCache = this._events[target.scene?.id]; | ||
const sceneCache = this._events.get(target.scene?.id); | ||
if (sceneCache) { | ||
sceneCache[type]?.delete(target); | ||
sceneCache.get(type)?.delete(target); | ||
} | ||
@@ -54,5 +61,5 @@ | ||
public static dispatchEvent<K extends keyof MiscEvents>(scene: Scene, type: K, event?: Events[K]): void { | ||
const sceneCache = this._events[scene?.id]; | ||
if (sceneCache?.[type]) { | ||
for (const target of sceneCache[type]) { | ||
const sceneCache = this._events.get(scene?.id); | ||
if (sceneCache?.get(type)) { | ||
for (const target of sceneCache.get(type)) { | ||
target.__eventsDispatcher.dispatch(type, event); | ||
@@ -63,5 +70,5 @@ | ||
public static dispatchEventExcludeCameras<K extends keyof MiscEvents>(scene: Scene, type: K, event?: Events[K]): void { | ||
const sceneCache = this._events[scene?.id]; | ||
if (sceneCache?.[type]) { | ||
for (const target of sceneCache[type]) { | ||
const sceneCache = this._events.get(scene?.id); | ||
if (sceneCache?.get(type)) { | ||
for (const target of sceneCache.get(type)) { | ||
if (!(target as Camera).isCamera) { |
Quality Gate passedIssues Measures |
No description provided.