T-4: M0.4b — Close sb-research.* holdout leak: 403 on dataset /export and ungranted project GETs

This commit is contained in:
Studio 2026-11-27 01:16:52 -05:00
parent 13eb8352f3
commit 420e77f837
17 changed files with 788 additions and 1123 deletions

View file

@ -18,6 +18,8 @@ const options = {
origins: ['http://ui.test'],
};
const agentId = 'agent:00000000-0000-4000-8000-000000000001';
const grantedProjectId = '11111111-1111-4111-8111-111111111111';
const ungrantedProjectId = '22222222-2222-4222-8222-222222222222';
const token = 'sb-research.server-composition-fixture';
const bearer = (value = token) => ({ Authorization: `Bearer ${value}` });
@ -28,10 +30,27 @@ function fixture(disabled = false, supplied = false) {
return {
rows:
values?.[0] === createHash('sha256').update(token).digest('hex')
? [{ id: agentId, enabled, policy: { allowedProjectIds: [] } }]
? [{ id: agentId, enabled, policy: { allowedProjectIds: [grantedProjectId] } }]
: [],
};
}
if (sql === 'SELECT * FROM research_projects WHERE id=$1' && values?.[0] === grantedProjectId) {
return {
rows: [
{
id: grantedProjectId,
title: 'Granted project',
description: '',
revision: 1,
owner_principal: 'operator',
updated_by: 'operator',
archived_at: null,
created_at: '2026-01-01T00:00:00Z',
updated_at: '2026-01-01T00:00:00Z',
},
],
};
}
if (sql.startsWith('SELECT a.*,(SELECT count(*)::integer FROM runs')) {
return {
rows: [
@ -205,3 +224,34 @@ test('web composition preserves token, environment, origin and browser-session v
expect(preflight.headers.get('access-control-allow-origin')).toBe('http://ui.test');
expect(f.query).not.toHaveBeenCalled();
});
test('web security denies agent dataset export and ungranted project reads before touching storage', async () => {
const f = fixture();
const hash = 'a'.repeat(64);
for (const method of ['GET', 'HEAD']) {
const exported = await f.app.request(`/api/v2/datasets/canonical/${hash}/export`, {
method,
headers: bearer(),
});
expect(exported.status).toBe(403);
expect(exported.headers.get('cache-control')).toBe('no-store');
const ungranted = await f.app.request(`/api/v2/research-projects/${ungrantedProjectId}`, {
method,
headers: bearer(),
});
expect(ungranted.status).toBe(403);
expect(ungranted.headers.get('cache-control')).toBe('no-store');
}
expect(
f.query.mock.calls.every(call =>
String(call[0]).startsWith('SELECT id,enabled,policy FROM research_agents WHERE token_hash=')
)
).toBe(true);
const granted = await f.app.request(`/api/v2/research-projects/${grantedProjectId}`, {
headers: bearer(),
});
expect(granted.status).toBe(200);
expect(await granted.json()).toMatchObject({ project: { id: grantedProjectId } });
});