Skip to content

Commit efe6bca

Browse files
CopilotlpcoxCopilot
authored
fix: exclude Actions artifact token from agent container environment (#1915)
* Initial plan * fix: exclude Actions artifact token from agent container env Agent-Logs-Url: https://github.com/github/gh-aw-firewall/sessions/85d33716-5b2a-4d34-b637-903b051ff017 * Update src/docker-manager.ts Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> --------- Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com> Co-authored-by: Landon Cox <landon.cox@microsoft.com> Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
1 parent a90be4c commit efe6bca

2 files changed

Lines changed: 78 additions & 0 deletions

File tree

src/docker-manager.test.ts

Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1382,6 +1382,78 @@ describe('docker-manager', () => {
13821382
expect(env.ANOTHER_VAR).toBe('another_value');
13831383
});
13841384

1385+
it('should never pass ACTIONS_RUNTIME_TOKEN to agent container', () => {
1386+
const originalToken = process.env.ACTIONS_RUNTIME_TOKEN;
1387+
process.env.ACTIONS_RUNTIME_TOKEN = 'test-runtime-token-value';
1388+
1389+
try {
1390+
// Should not be passed in default mode
1391+
const result = generateDockerCompose(mockConfig, mockNetworkConfig);
1392+
const env = result.services.agent.environment as Record<string, string>;
1393+
expect(env.ACTIONS_RUNTIME_TOKEN).toBeUndefined();
1394+
} finally {
1395+
if (originalToken !== undefined) {
1396+
process.env.ACTIONS_RUNTIME_TOKEN = originalToken;
1397+
} else {
1398+
delete process.env.ACTIONS_RUNTIME_TOKEN;
1399+
}
1400+
}
1401+
});
1402+
1403+
it('should never pass ACTIONS_RESULTS_URL to agent container', () => {
1404+
const originalUrl = process.env.ACTIONS_RESULTS_URL;
1405+
process.env.ACTIONS_RESULTS_URL = 'https://results-receiver.actions.githubusercontent.com/';
1406+
1407+
try {
1408+
// Should not be passed in default mode
1409+
const result = generateDockerCompose(mockConfig, mockNetworkConfig);
1410+
const env = result.services.agent.environment as Record<string, string>;
1411+
expect(env.ACTIONS_RESULTS_URL).toBeUndefined();
1412+
} finally {
1413+
if (originalUrl !== undefined) {
1414+
process.env.ACTIONS_RESULTS_URL = originalUrl;
1415+
} else {
1416+
delete process.env.ACTIONS_RESULTS_URL;
1417+
}
1418+
}
1419+
});
1420+
1421+
it('should exclude ACTIONS_RUNTIME_TOKEN from env-all passthrough', () => {
1422+
const originalToken = process.env.ACTIONS_RUNTIME_TOKEN;
1423+
process.env.ACTIONS_RUNTIME_TOKEN = 'test-runtime-token-value';
1424+
1425+
try {
1426+
const configWithEnvAll = { ...mockConfig, envAll: true };
1427+
const result = generateDockerCompose(configWithEnvAll, mockNetworkConfig);
1428+
const env = result.services.agent.environment as Record<string, string>;
1429+
expect(env.ACTIONS_RUNTIME_TOKEN).toBeUndefined();
1430+
} finally {
1431+
if (originalToken !== undefined) {
1432+
process.env.ACTIONS_RUNTIME_TOKEN = originalToken;
1433+
} else {
1434+
delete process.env.ACTIONS_RUNTIME_TOKEN;
1435+
}
1436+
}
1437+
});
1438+
1439+
it('should exclude ACTIONS_RESULTS_URL from env-all passthrough', () => {
1440+
const originalUrl = process.env.ACTIONS_RESULTS_URL;
1441+
process.env.ACTIONS_RESULTS_URL = 'https://results-receiver.actions.githubusercontent.com/';
1442+
1443+
try {
1444+
const configWithEnvAll = { ...mockConfig, envAll: true };
1445+
const result = generateDockerCompose(configWithEnvAll, mockNetworkConfig);
1446+
const env = result.services.agent.environment as Record<string, string>;
1447+
expect(env.ACTIONS_RESULTS_URL).toBeUndefined();
1448+
} finally {
1449+
if (originalUrl !== undefined) {
1450+
process.env.ACTIONS_RESULTS_URL = originalUrl;
1451+
} else {
1452+
delete process.env.ACTIONS_RESULTS_URL;
1453+
}
1454+
}
1455+
});
1456+
13851457
it('should exclude system variables when envAll is enabled', () => {
13861458
const originalPath = process.env.PATH;
13871459
process.env.CUSTOM_HOST_VAR = 'test_value';

src/docker-manager.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -581,6 +581,12 @@ export function generateDockerCompose(
581581
'SUDO_USER', // Sudo metadata
582582
'SUDO_UID', // Sudo metadata
583583
'SUDO_GID', // Sudo metadata
584+
// GitHub Actions artifact service tokens — excluded from inherited environment
585+
// propagation to prevent agents from uploading arbitrary data as workflow artifacts
586+
// (potential data exfiltration vector). These tokens are only needed by the
587+
// Actions runner itself, not by the agent.
588+
'ACTIONS_RUNTIME_TOKEN',
589+
'ACTIONS_RESULTS_URL',
584590
]);
585591

586592
// When api-proxy is enabled, exclude API keys from agent environment

0 commit comments

Comments
 (0)