Skip to content

Commit edfadb2

Browse files
committed
fix(security): round-5o scope descents count toward depth cap
1 parent 6a1d83e commit edfadb2

2 files changed

Lines changed: 24 additions & 1 deletion

File tree

‎apps/web/security-integrity-find-installed-roots.test.ts‎

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -134,6 +134,27 @@ describe('security-integrity-find-installed-roots', () => {
134134
});
135135
});
136136

137+
it('throws when a scope chain exceeds the depth cap', () => {
138+
// Scope descents count toward depth-8 like every other descent.
139+
let dir = join(fixture, 'node_modules');
140+
for (let level = 0; level < 10; level += 1) {
141+
dir = join(dir, `@deep${level}`);
142+
mkdirSync(dir, { recursive: true });
143+
}
144+
mkdirSync(join(dir, 'dup'), { recursive: true });
145+
writeFileSync(
146+
join(dir, 'dup', 'package.json'),
147+
JSON.stringify({ name: 'dup', version: '0.0.0' })
148+
);
149+
expect(() => findInstalledRoots('@deep9/dup', fixture)).toThrow(
150+
/depth-8 recursion cap/
151+
);
152+
rmSync(join(fixture, 'node_modules', '@deep0'), {
153+
recursive: true,
154+
force: true,
155+
});
156+
});
157+
137158
it('throws when the upward walk hits the 12-level cap', () => {
138159
// A nonexistent 12-deep start dir never reaches the workspace
139160
// marker, so the walk exhausts its level budget.

‎apps/web/security-integrity-find-installed-roots.ts‎

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -192,7 +192,9 @@ export function findInstalledRoots(
192192
}
193193
}
194194
if (entry.name.startsWith('@')) {
195-
scan(full, depth, true);
195+
// Depth increments here too, so the depth-8 cap bounds every
196+
// descent shape, not just node_modules nesting.
197+
scan(full, depth + 1, true);
196198
} else {
197199
const nested = join(full, 'node_modules');
198200
if (existsSync(nested)) {

0 commit comments

Comments
 (0)