branch selector on git stack, with per-stack branch override
This commit is contained in:
12 files changed
+85
-457
No files matched your search
@@ -8,18 +8,13 @@
|
||||
*
|
||||
* 1. SSRF — assertSafeRepoTarget blocks the maintainer's encoded-IP payloads.
|
||||
* 2. RCE — assertSafeRepoUrl rejects the ext::/file:: transport denylist.
|
||||
* 3. Credential affinity — assertCredentialHostMatch refuses to pair a raw
|
||||
* url with a stored password credential whose username isn't the host.
|
||||
*
|
||||
* Mirror-test convention: the endpoint pipeline below mirrors the real
|
||||
* repositories/test handler's guard order and error handling. Keep in sync.
|
||||
*/
|
||||
|
||||
import { describe, expect, test } from 'bun:test';
|
||||
import {
|
||||
assertSafeRepoTarget,
|
||||
assertCredentialHostMatch
|
||||
} from '../src/lib/server/git-branch-lookup';
|
||||
import { assertSafeRepoTarget } from '../src/lib/server/git-branch-lookup';
|
||||
import { assertSafeRepoUrl } from '../src/lib/server/git-url-safety';
|
||||
|
||||
// =============================================================================
|
||||
@@ -60,28 +55,10 @@ describe('repositories/test RCE guard (assertSafeRepoUrl)', () => {
|
||||
});
|
||||
});
|
||||
|
||||
// =============================================================================
|
||||
// Credential affinity.
|
||||
// =============================================================================
|
||||
|
||||
describe('repositories/test credential affinity (assertCredentialHostMatch)', () => {
|
||||
test('rejects a single-label username for an attacker subdomain', () => {
|
||||
const c: any = { id: 1, name: 'github', authType: 'password', username: 'github', password: 'x' };
|
||||
expect(() => assertCredentialHostMatch('https://github.evil.com/x.git', c)).toThrow(/does not match/i);
|
||||
});
|
||||
test('allows a username that matches the full host', () => {
|
||||
const c: any = { id: 2, name: 'gh', authType: 'password', username: 'github.com', password: 'x' };
|
||||
expect(() => assertCredentialHostMatch('https://github.com/x.git', c)).not.toThrow();
|
||||
});
|
||||
});
|
||||
|
||||
// =============================================================================
|
||||
// Endpoint pipeline (mirror of POST /api/git/repositories/test).
|
||||
// =============================================================================
|
||||
|
||||
type StoredCred = { id: number; name: string; authType: string; username: string | null };
|
||||
const storedCreds = new Map<number, StoredCred>();
|
||||
|
||||
/**
|
||||
* Mirror of POST /api/git/repositories/test
|
||||
* (src/routes/api/git/repositories/test/+server.ts). Keeps only the
|
||||
@@ -104,17 +81,6 @@ async function postRepositoriesTest(
|
||||
return { status: 400, json: { success: false, error: e.message } };
|
||||
}
|
||||
|
||||
// Guard 2 (credential affinity).
|
||||
if (body.credentialId != null && body.credentialId !== undefined) {
|
||||
const credential = storedCreds.get(body.credentialId);
|
||||
if (!credential) return { status: 404, json: { success: false, error: 'Credential not found' } };
|
||||
try {
|
||||
assertCredentialHostMatch(body.url, credential as any);
|
||||
} catch (e: any) {
|
||||
return { status: 400, json: { success: false, error: e.message } };
|
||||
}
|
||||
}
|
||||
|
||||
// Stubbed: testRepositoryConfig (ls-remote + clone).
|
||||
return { status: 200, json: { success: true } };
|
||||
}
|
||||
@@ -137,24 +103,6 @@ describe('POST /api/git/repositories/test — pipeline', () => {
|
||||
expect(res.status).toBe(400);
|
||||
});
|
||||
|
||||
test('endpoint blocks a credential whose username does not match the host', async () => {
|
||||
storedCreds.set(1, { id: 1, name: 'github', authType: 'password', username: 'github' });
|
||||
const res = await postRepositoriesTest({ url: 'https://github.evil.com/x.git', credentialId: 1 });
|
||||
expect(res.status).toBe(400);
|
||||
expect(res.json.error).toMatch(/does not match/i);
|
||||
});
|
||||
|
||||
test('endpoint allows a host-matching credential', async () => {
|
||||
storedCreds.set(2, { id: 2, name: 'gh', authType: 'password', username: 'github.com' });
|
||||
const res = await postRepositoriesTest({ url: 'https://github.com/x.git', credentialId: 2 });
|
||||
expect(res.status).toBe(200);
|
||||
});
|
||||
|
||||
test('endpoint blocks an unknown credential (404)', async () => {
|
||||
const res = await postRepositoriesTest({ url: 'https://github.com/x.git', credentialId: 9999 });
|
||||
expect(res.status).toBe(404);
|
||||
});
|
||||
|
||||
test('endpoint allows a public URL with no credential', async () => {
|
||||
const res = await postRepositoriesTest({ url: 'https://github.com/x.git' });
|
||||
expect(res.status).toBe(200);
|
||||
|
||||
Reference in new issue
Block a user