Skip to content

Commit 7662e6a

Browse files
committed
security: fix CodeQL command injection and URL sanitization issues
- Add '--' separator in git clone to prevent flag injection via repo names - Validate SSH host key paths to prevent command injection in ssh-keygen - Use strict equality for GitHub/GitLab hostname checks to prevent subdomain spoofing - Add .gitignore entry for test/.ssh/ directory Fixes CodeQL security alerts: - Second order command injection (2 instances) - Incomplete URL substring sanitization (2 instances) - Uncontrolled command line (1 instance)
1 parent bfed68a commit 7662e6a

File tree

4 files changed

+14
-3
lines changed

4 files changed

+14
-3
lines changed

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -272,10 +272,12 @@ website/.docusaurus
272272

273273
# Test SSH keys (generated during tests)
274274
test/keys/
275+
test/.ssh/
275276

276277
# VS COde IDE
277278
.vscode/settings.json
278279

279280
# Generated from testing
280281
/test/fixtures/test-package/package-lock.json
281282
.ssh/
283+

src/proxy/processors/push-action/PullRemoteSSH.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ export class PullRemoteSSH extends PullRemoteBase {
5959
await new Promise<void>((resolve, reject) => {
6060
const gitProc = spawn(
6161
'git',
62-
['clone', '--depth', '1', '--single-branch', sshUrl, action.repoName],
62+
['clone', '--depth', '1', '--single-branch', '--', sshUrl, action.repoName],
6363
{
6464
cwd: action.proxyGitPath,
6565
env: {

src/proxy/ssh/GitProtocol.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -194,9 +194,9 @@ async function executeRemoteGitCommand(
194194
errorMessage += ` 1. Verify your SSH key is loaded in ssh-agent:\n`;
195195
errorMessage += ` $ ssh-add -l\n\n`;
196196
errorMessage += ` 2. Add your SSH public key to ${remoteHost}:\n`;
197-
if (remoteHost.includes('github.com')) {
197+
if (remoteHost === 'github.com') {
198198
errorMessage += ` https://github.com/settings/keys\n\n`;
199-
} else if (remoteHost.includes('gitlab.com')) {
199+
} else if (remoteHost === 'gitlab.com') {
200200
errorMessage += ` https://gitlab.com/-/profile/keys\n\n`;
201201
} else {
202202
errorMessage += ` Check your Git hosting provider's SSH key settings\n\n`;

src/proxy/ssh/hostKeyManager.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,15 @@ export interface HostKeyConfig {
3535
export function ensureHostKey(config: HostKeyConfig): Buffer {
3636
const { privateKeyPath, publicKeyPath } = config;
3737

38+
// Validate paths to prevent command injection
39+
// Only allow alphanumeric, dots, slashes, underscores, hyphens
40+
const safePathRegex = /^[a-zA-Z0-9._\-\/]+$/;
41+
if (!safePathRegex.test(privateKeyPath) || !safePathRegex.test(publicKeyPath)) {
42+
throw new Error(
43+
`Invalid SSH host key path: paths must contain only alphanumeric characters, dots, slashes, underscores, and hyphens`,
44+
);
45+
}
46+
3847
// Check if the private key already exists
3948
if (fs.existsSync(privateKeyPath)) {
4049
console.log(`[SSH] Using existing proxy host key: ${privateKeyPath}`);

0 commit comments

Comments
 (0)