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

Cleaning #105

Open
wants to merge 10 commits into
base: master
Choose a base branch
from
Open

Cleaning #105

wants to merge 10 commits into from

Conversation

agargaro
Copy link
Owner

No description provided.

src/patch/Scene.ts Fixed Show fixed Hide fixed
src/patch/Scene.ts Fixed Show fixed Hide fixed
src/patch/Vector3.ts Fixed Show fixed Hide fixed
src/patch/Vector3.ts Fixed Show fixed Hide fixed
src/patch/Vector3.ts Fixed Show fixed Hide fixed
src/utils/IntersectionUtils.ts Fixed Show fixed Hide fixed
src/utils/IntersectionUtils.ts Fixed Show fixed Hide fixed
src/utils/IntersectionUtils.ts Fixed Show fixed Hide fixed
src/utils/IntersectionUtils.ts Fixed Show fixed Hide fixed
src/utils/IntersectionUtils.ts Fixed Show fixed Hide fixed
}
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

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
.
This assignment may alter Object.prototype if a malicious '__proto__' string is injected from
library input
.

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.

Suggested changeset 1
src/events/MiscEventsManager.ts

Autofix patch

Autofix patch
Run the following command in your local git repository to apply this patch
cat << 'EOF' | git apply
diff --git a/src/events/MiscEventsManager.ts b/src/events/MiscEventsManager.ts
--- a/src/events/MiscEventsManager.ts
+++ b/src/events/MiscEventsManager.ts
@@ -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) {
EOF
@@ -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) {
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
Copy link

sonarcloud bot commented Nov 15, 2024

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