Skip to content

Commit b7c61c9

Browse files
authored
Refactor: exclude transient CI configuration files from workspace context (#28216)
1 parent 27a3da3 commit b7c61c9

2 files changed

Lines changed: 29 additions & 3 deletions

File tree

packages/core/src/utils/workspaceContext.test.ts

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -523,6 +523,21 @@ describe('WorkspaceContext with optional directories', () => {
523523
}
524524
});
525525

526+
it('should reject GitHub Actions Workload Identity credentials', () => {
527+
const workspaceContext = new WorkspaceContext(cwd);
528+
529+
const sensitivePaths = [
530+
path.join(cwd, 'gha-creds-12345.json'),
531+
path.join(cwd, 'gha-creds-abcde.json'),
532+
path.join(cwd, 'GHA-CREDS-abcde.JSON'), // Case-insensitivity check
533+
path.join(cwd, 'subfolder', 'gha-creds-12345.json'), // Nested
534+
];
535+
536+
for (const p of sensitivePaths) {
537+
expect(workspaceContext.isPathWithinWorkspace(p)).toBe(false);
538+
}
539+
});
540+
526541
it('should allow standard non-sensitive paths', () => {
527542
const workspaceContext = new WorkspaceContext(cwd);
528543

@@ -531,6 +546,8 @@ describe('WorkspaceContext with optional directories', () => {
531546
path.join(cwd, '.gitignore'),
532547
path.join(cwd, '.env.example'),
533548
path.join(cwd, 'package.json'),
549+
path.join(cwd, 'tsconfig.json'),
550+
path.join(cwd, 'gha-creds.json'), // Doesn't match the pattern
534551
];
535552

536553
for (const p of safePaths) {

packages/core/src/utils/workspaceContext.ts

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -191,9 +191,18 @@ export class WorkspaceContext {
191191
const clean = trimTrailingSpacesAndDots(
192192
segment.split(':')[0],
193193
).toLowerCase();
194-
return (
195-
clean === '.git' || clean === '.env' || clean === 'node_modules'
196-
);
194+
if (
195+
clean === '.git' ||
196+
clean === '.env' ||
197+
clean === 'node_modules'
198+
) {
199+
return true;
200+
}
201+
// Block GitHub Actions Workload Identity credentials
202+
if (clean.startsWith('gha-creds-') && clean.endsWith('.json')) {
203+
return true;
204+
}
205+
return false;
197206
});
198207
if (hasBlockedSegment) {
199208
return false;

0 commit comments

Comments
 (0)