element-web-0003/0004 + conduit-0001: CWE-407 deep scan — 3 new defects, 6/6 PASS
element-web-0003: TextForEvent.tsx textForCanonicalAliasEvent alt_aliases .filter(x => !arr.includes(x)) O(A*B) MEDIUM 19.5x — fix: Set.has() element-web-0004: utils/arrays.ts arrayDiff + arrayIntersection .filter(i => !arr.includes(i)) O(A*B) MEDIUM 18x — fix: Set.has() Used by 15+ callsites: room-list, notifications, spaces, beacons, maps conduit-0001: server_server.rs get_missing_events_route earliest_events.contains() (Vec) in growing BFS loop O(Q*E) MEDIUM-HIGH 7.4x Federation endpoint — remote server controls input size matrix-rust-sdk: could not clone (GitHub HTTPS unreachable)
This commit is contained in:
parent
f35e47bab3
commit
ec186e286c
5 changed files with 396 additions and 6 deletions
|
|
@ -0,0 +1,17 @@
|
|||
--- a/apps/web/src/TextForEvent.tsx
|
||||
+++ b/apps/web/src/TextForEvent.tsx
|
||||
@@ -394,8 +394,11 @@ function textForCanonicalAliasEvent(ev: MatrixEvent): (() => string) | null {
|
||||
const oldAltAliases = ev.getPrevContent().alt_aliases || [];
|
||||
const newAlias = ev.getContent().alias;
|
||||
const newAltAliases = ev.getContent().alt_aliases || [];
|
||||
- const removedAltAliases = oldAltAliases.filter((alias: string) => !newAltAliases.includes(alias));
|
||||
- const addedAltAliases = newAltAliases.filter((alias: string) => !oldAltAliases.includes(alias));
|
||||
+ // CWE-407 fix: use Set for O(1) membership test; avoids O(A*B) from
|
||||
+ // includes() inside filter() when computing alias diffs.
|
||||
+ const newAltAliasSet = new Set(newAltAliases);
|
||||
+ const oldAltAliasSet = new Set(oldAltAliases);
|
||||
+ const removedAltAliases = oldAltAliases.filter((alias: string) => !newAltAliasSet.has(alias));
|
||||
+ const addedAltAliases = newAltAliases.filter((alias: string) => !oldAltAliasSet.has(alias));
|
||||
|
||||
if (!removedAltAliases.length && !addedAltAliases.length) {
|
||||
if (newAlias) {
|
||||
|
|
@ -0,0 +1,26 @@
|
|||
--- a/apps/web/src/utils/arrays.ts
|
||||
+++ b/apps/web/src/utils/arrays.ts
|
||||
@@ -189,8 +189,12 @@ export function arrayHasOrderChange(a: any[], b: any[]): boolean {
|
||||
export function arrayDiff<T>(a: T[], b: T[]): Diff<T> {
|
||||
+ // CWE-407 fix: use Set for O(1) membership test instead of O(A*B)
|
||||
+ // includes() inside filter(). Build Sets once, then filter.
|
||||
+ const setA = new Set(a);
|
||||
+ const setB = new Set(b);
|
||||
return {
|
||||
- added: b.filter((i) => !a.includes(i)),
|
||||
- removed: a.filter((i) => !b.includes(i)),
|
||||
+ added: b.filter((i) => !setA.has(i)),
|
||||
+ removed: a.filter((i) => !setB.has(i)),
|
||||
};
|
||||
}
|
||||
|
||||
@@ -202,7 +206,10 @@ export function arrayDiff<T>(a: T[], b: T[]): Diff<T> {
|
||||
* @returns The intersection of the arrays.
|
||||
*/
|
||||
export function arrayIntersection<T>(a: T[], b: T[]): T[] {
|
||||
- return a.filter((i) => b.includes(i));
|
||||
+ // CWE-407 fix: use Set for O(1) membership test instead of O(A*B)
|
||||
+ // includes() inside filter().
|
||||
+ const setB = new Set(b);
|
||||
+ return a.filter((i) => setB.has(i));
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue