Files
TORCH/test/governance-security.test.mjs
T
google-labs-jules[bot]andPR0M3TH3AN bdd3ed8c8f fix(security): prevent command injection in governance service and fix build errors
- Mitigate command injection in `src/services/governance/index.js` by using explicit array arguments with `execFileSync` and adding a security comment.
- Add regression test `test/governance-security.test.mjs` verifying the fix against simulated exploit attempts.
- Fix CI build failures by resolving circular dependencies and duplicate declarations in `src/lock-utils.mjs`, `src/lock-ops.mjs`, `src/lock-publisher.mjs`, and `src/relay-health.mjs`.
- Resolve linting errors in tests and implementation files.

Co-authored-by: PR0M3TH3AN <[email protected]>
2026-02-21 19:35:31 +00:00

26 lines
1.2 KiB
JavaScript

import { test } from 'node:test';
import { execFileSync } from 'node:child_process';
import path from 'node:path';
import { fileURLToPath } from 'node:url';
import assert from 'node:assert';
const __dirname = path.dirname(fileURLToPath(import.meta.url));
const implPath = path.join(__dirname, 'governance-security-impl.mjs');
test('Governance Service Security: Command Injection Prevention', (_t) => {
// We run the implementation in a separate process to ensure process.cwd() isolation
// and to verify that the dynamic import picks up the correct paths.
try {
const output = execFileSync(process.execPath, [implPath], { encoding: 'utf8' });
// If we reach here, the process exited with code 0 (success)
// We can optionally check the output for specific messages if needed,
// but the implementation script asserts internally.
assert.ok(output.includes('Verification passed: Commit message contains payload.'), 'Output should confirm verification passed');
} catch (err) {
console.error('Test implementation failed.');
if (err.stdout) console.error('STDOUT:', err.stdout);
if (err.stderr) console.error('STDERR:', err.stderr);
assert.fail(`Security test failed with exit code ${err.status}: ${err.message}`);
}
});