Skip to content

Commit e94be9b

Browse files
Mossakaclaude
andauthored
fix: use secure temp directory in volume-mounts test (#765)
Replace predictable /tmp/secret-file-12345.txt path with fs.mkdtempSync to prevent symlink attacks (CodeQL alert #173). Co-authored-by: Claude Opus 4.6 <noreply@anthropic.com>
1 parent aa784eb commit e94be9b

1 file changed

Lines changed: 9 additions & 8 deletions

File tree

tests/integration/volume-mounts.test.ts

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -113,13 +113,14 @@ describe('Volume Mount Functionality', () => {
113113
}, 120000);
114114

115115
test('Test 4: Blanket mount removed with custom mounts', async () => {
116-
// Create a test file outside the custom mount
117-
const secretFile = '/tmp/secret-file-12345.txt';
118-
fs.writeFileSync(secretFile, 'Secret data');
116+
// Create a test file outside the custom mount in a secure temp directory
117+
const secretDir = fs.mkdtempSync(path.join(os.tmpdir(), 'awf-secret-'));
118+
const secretFile = path.join(secretDir, 'secret.txt');
119+
fs.writeFileSync(secretFile, 'Secret data', { mode: 0o600 });
119120

120121
try {
121122
const result = await runner.runWithSudo(
122-
'sh -c "cat /data/test.txt && cat /tmp/secret-file-12345.txt"',
123+
`sh -c "cat /data/test.txt && cat ${secretFile}"`,
123124
{
124125
allowDomains: ['github.com'],
125126
logLevel: 'debug',
@@ -129,13 +130,13 @@ describe('Volume Mount Functionality', () => {
129130
);
130131

131132
// First cat should fail (no file in /data)
132-
// Second cat should fail (no blanket mount, /tmp not accessible from host)
133+
// Second cat should fail (no blanket mount, host paths not accessible)
133134
expect(result).toFail();
134135
expect(result.stderr).toMatch(/No such file or directory/);
135136
} finally {
136-
// Cleanup secret file
137-
if (fs.existsSync(secretFile)) {
138-
fs.unlinkSync(secretFile);
137+
// Cleanup secret directory
138+
if (fs.existsSync(secretDir)) {
139+
fs.rmSync(secretDir, { recursive: true, force: true });
139140
}
140141
}
141142
}, 120000);

0 commit comments

Comments
 (0)