game engines/web frameworks: 27 CWE-407 defects + 3 CLEAN; 194 sites, 78 ecosystems
This commit is contained in:
parent
547a9f5738
commit
4d3fcc8e73
76 changed files with 6216 additions and 17 deletions
|
|
@ -0,0 +1,39 @@
|
|||
diff --git a/packages/core/scanner.ts b/packages/core/scanner.ts
|
||||
index xxxxxxx..xxxxxxx 100644
|
||||
--- a/packages/core/scanner.ts
|
||||
+++ b/packages/core/scanner.ts
|
||||
@@ -67,7 +67,7 @@ interface ModulesScanParameters {
|
||||
moduleDefinition: ModuleDefinition;
|
||||
scope?: Type<unknown>[];
|
||||
- ctxRegistry?: (ForwardReference | DynamicModule | Type<unknown>)[];
|
||||
+ ctxRegistry?: Set<ForwardReference | DynamicModule | Type<unknown>>;
|
||||
overrides?: ModuleOverride[];
|
||||
lazy?: boolean;
|
||||
}
|
||||
@@ -106,7 +106,7 @@ export class DependenciesScanner {
|
||||
public async scanForModules({
|
||||
moduleDefinition,
|
||||
lazy,
|
||||
scope = [],
|
||||
- ctxRegistry = [],
|
||||
+ ctxRegistry = new Set(),
|
||||
overrides = [],
|
||||
}: ModulesScanParameters): Promise<Module[]> {
|
||||
const { moduleRef: moduleInstance, inserted: moduleInserted } =
|
||||
@@ -123,7 +123,7 @@ export class DependenciesScanner {
|
||||
- ctxRegistry.push(moduleDefinition);
|
||||
+ // CWE-407 fix: Set.add() is O(1); was Array.push() feeding an O(n) .includes()
|
||||
+ ctxRegistry.add(moduleDefinition);
|
||||
|
||||
if (this.isForwardReference(moduleDefinition)) {
|
||||
moduleDefinition = (moduleDefinition as ForwardReference).forwardRef();
|
||||
@@ -152,7 +152,7 @@ export class DependenciesScanner {
|
||||
if (!innerModule) {
|
||||
throw new InvalidModuleException(moduleDefinition, index, scope);
|
||||
}
|
||||
- if (ctxRegistry.includes(innerModule)) {
|
||||
+ // CWE-407 fix: Set.has() is O(1); was Array.includes() = O(n) scan
|
||||
+ if (ctxRegistry.has(innerModule)) {
|
||||
continue;
|
||||
}
|
||||
const moduleRefs = await this.scanForModules({
|
||||
|
|
@ -0,0 +1,37 @@
|
|||
diff --git a/packages/common/module-utils/utils/get-injection-providers.util.ts b/packages/common/module-utils/utils/get-injection-providers.util.ts
|
||||
index xxxxxxx..xxxxxxx 100644
|
||||
--- a/packages/common/module-utils/utils/get-injection-providers.util.ts
|
||||
+++ b/packages/common/module-utils/utils/get-injection-providers.util.ts
|
||||
@@ -32,13 +32,19 @@ export function getInjectionProviders(
|
||||
providers: Provider[],
|
||||
tokens: FactoryProvider['inject'],
|
||||
): Provider[] {
|
||||
const result: Provider[] = [];
|
||||
+ // CWE-407 fix: companion Set for O(1) result-membership checks
|
||||
+ const resultSet = new Set<Provider>();
|
||||
+
|
||||
let search: InjectionToken[] = tokens!.map(mapInjectToTokens);
|
||||
+ // CWE-407 fix: companion Set for O(1) search-membership checks
|
||||
+ let searchSet = new Set<InjectionToken>(search);
|
||||
+
|
||||
while (search.length > 0) {
|
||||
const match = (providers ?? []).filter(
|
||||
p =>
|
||||
- !result.includes(p) && // this prevents circular loops and duplication
|
||||
- (search.includes(p as any) || search.includes((p as any)?.provide)),
|
||||
+ // CWE-407 fix: was Array.includes() = O(n); now Set.has() = O(1)
|
||||
+ !resultSet.has(p) &&
|
||||
+ (searchSet.has(p as any) || searchSet.has((p as any)?.provide)),
|
||||
);
|
||||
- result.push(...match);
|
||||
+ for (const p of match) { result.push(p); resultSet.add(p); }
|
||||
+
|
||||
// get injection tokens of the matched providers, if any
|
||||
search = match
|
||||
.filter(p => (p as any)?.inject)
|
||||
.flatMap(p => (p as FactoryProvider).inject!)
|
||||
.map(mapInjectToTokens);
|
||||
+ searchSet = new Set<InjectionToken>(search);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue