T-4: M0.4b — Close sb-research.* holdout leak: 403 on dataset /export and ungranted project GETs
This commit is contained in:
parent
420e77f837
commit
7f4d3c7543
4 changed files with 383 additions and 30 deletions
|
|
@ -1222,4 +1222,169 @@ describe.skipIf(!url)('authoritative research principals and budgets', () => {
|
|||
expect((await req('/api/v2/strategies/not-a-uuid', p.token)).status).toBe(403);
|
||||
expect((await req('/api/v2/strategy-versions/not-a-uuid', p.token)).status).toBe(403);
|
||||
});
|
||||
|
||||
test('granted project artifacts cannot leak foreign holdout run evidence to research agents while preserving operator access', async () => {
|
||||
const f = await fixture(4),
|
||||
p = await provision(f);
|
||||
const security = createWebApiSecurity(f.container, {
|
||||
adminToken: operatorToken,
|
||||
serviceToken: 'service-test-secret-123456789012345678901',
|
||||
environment: 'test',
|
||||
});
|
||||
const app = createRoutes(f.container, security);
|
||||
const req = (
|
||||
path: string,
|
||||
token: string,
|
||||
method: 'GET' | 'HEAD' | 'POST' = 'GET',
|
||||
body?: unknown
|
||||
) =>
|
||||
app.request(path, {
|
||||
method,
|
||||
headers: {
|
||||
Authorization: `Bearer ${token}`,
|
||||
...(body === undefined ? {} : { 'Content-Type': 'application/json' }),
|
||||
},
|
||||
...(body === undefined ? {} : { body: JSON.stringify(body) }),
|
||||
});
|
||||
|
||||
// Execute an operator-owned holdout run and an agent-owned run on the shared template
|
||||
const opExp = await f.experiments.submit(
|
||||
await preparation(f, 'Operator holdout', f.draft.id, { fastPeriod: [2] }),
|
||||
receipt('operator')
|
||||
);
|
||||
const opRunId = required(opExp.trials[0]!.runId);
|
||||
await f.execute(opRunId);
|
||||
|
||||
const agentExp = await f.experiments.submit(
|
||||
await preparation(f, 'Agent search', f.draft.id, { fastPeriod: [1] }),
|
||||
receipt(p.agent.id)
|
||||
);
|
||||
const agentRunId = required(agentExp.trials[0]!.runId);
|
||||
await f.execute(agentRunId);
|
||||
|
||||
// Operator attaches the holdout run's Sharpe ratio to a finding in the agent's granted project
|
||||
const opFinding = await f.research.createArtifact(
|
||||
p.project.id,
|
||||
{
|
||||
kind: 'finding',
|
||||
title: 'Operator holdout finding',
|
||||
body: 'Holdout Sharpe ratio from operator run',
|
||||
evidence: [
|
||||
{
|
||||
runId: opRunId,
|
||||
metricsVersion: 'canonical-analytics/v1',
|
||||
metricPath: 'analytics.metrics.sharpeRatio',
|
||||
},
|
||||
],
|
||||
},
|
||||
'operator'
|
||||
);
|
||||
const agentFinding = await f.research.createArtifact(
|
||||
p.project.id,
|
||||
{
|
||||
kind: 'finding',
|
||||
title: 'Agent finding',
|
||||
body: 'Sharpe ratio from agent-owned run',
|
||||
evidence: [
|
||||
{
|
||||
runId: agentRunId,
|
||||
metricsVersion: 'canonical-analytics/v1',
|
||||
metricPath: 'analytics.metrics.sharpeRatio',
|
||||
},
|
||||
],
|
||||
},
|
||||
p.agent.id as `agent:${string}`
|
||||
);
|
||||
const plainNote = await f.research.createArtifact(
|
||||
p.project.id,
|
||||
{ kind: 'note', title: 'Shared note', body: 'No run evidence', evidence: [] },
|
||||
'operator'
|
||||
);
|
||||
|
||||
// Agent cannot read operator run results directly
|
||||
expect((await req(`/api/v2/runs/${opRunId}/results`, p.token)).status).toBe(403);
|
||||
|
||||
// Agent cannot read the operator finding or its revisions via GET or HEAD
|
||||
for (const method of ['GET', 'HEAD'] as const) {
|
||||
for (const path of [
|
||||
`/api/v2/analysis-artifacts/${opFinding.id}`,
|
||||
`/api/v2/analysis-artifacts/${opFinding.id}/revisions`,
|
||||
]) {
|
||||
const denied = await req(path, p.token, method);
|
||||
expect(denied.status).toBe(403);
|
||||
expect(denied.headers.get('cache-control')).toBe('no-store');
|
||||
if (method === 'GET') {
|
||||
expect(await denied.text()).not.toContain(f.dataset.manifest.hash);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Agent project-list omits the operator holdout finding while keeping owned/non-evidence artifacts
|
||||
const agentList = await req(`/api/v2/research-projects/${p.project.id}/analysis-artifacts`, p.token);
|
||||
expect(agentList.status).toBe(200);
|
||||
const agentArtifactIds = (
|
||||
(await agentList.json()) as { artifacts: { id: string }[] }
|
||||
).artifacts.map(a => a.id);
|
||||
expect(agentArtifactIds).toContain(agentFinding.id);
|
||||
expect(agentArtifactIds).toContain(plainNote.id);
|
||||
expect(agentArtifactIds).not.toContain(opFinding.id);
|
||||
|
||||
// Agent can still read its own finding and revisions
|
||||
const ownItem = await req(`/api/v2/analysis-artifacts/${agentFinding.id}`, p.token);
|
||||
expect(ownItem.status).toBe(200);
|
||||
expect(
|
||||
(
|
||||
(await ownItem.json()) as {
|
||||
artifact: { latestRevision: { evidence: { runId: string }[] } };
|
||||
}
|
||||
).artifact.latestRevision.evidence[0]?.runId
|
||||
).toBe(agentRunId);
|
||||
expect((await req(`/api/v2/analysis-artifacts/${agentFinding.id}/revisions`, p.token)).status).toBe(
|
||||
200
|
||||
);
|
||||
|
||||
// Agent cannot attach an operator-owned run as evidence when creating an artifact
|
||||
const forged = await req(
|
||||
`/api/v2/research-projects/${p.project.id}/analysis-artifacts`,
|
||||
p.token,
|
||||
'POST',
|
||||
{
|
||||
kind: 'finding',
|
||||
title: 'Attempted exfiltration',
|
||||
body: 'Refers to operator run',
|
||||
evidence: [
|
||||
{
|
||||
runId: opRunId,
|
||||
metricsVersion: 'canonical-analytics/v1',
|
||||
metricPath: 'analytics.metrics.sharpeRatio',
|
||||
},
|
||||
],
|
||||
}
|
||||
);
|
||||
expect(forged.status).toBe(403);
|
||||
|
||||
// Operator retains full read access to the holdout finding, its revisions, and the full list
|
||||
const opItem = await req(`/api/v2/analysis-artifacts/${opFinding.id}`, operatorToken);
|
||||
expect(opItem.status).toBe(200);
|
||||
const opArtifact = (
|
||||
(await opItem.json()) as {
|
||||
artifact: { latestRevision: { evidence: { runId: string; datasetHash: string }[] } };
|
||||
}
|
||||
).artifact;
|
||||
expect(opArtifact.latestRevision.evidence[0]?.runId).toBe(opRunId);
|
||||
expect(opArtifact.latestRevision.evidence[0]?.datasetHash).toBe(f.dataset.manifest.hash);
|
||||
|
||||
expect(
|
||||
(await req(`/api/v2/analysis-artifacts/${opFinding.id}/revisions`, operatorToken)).status
|
||||
).toBe(200);
|
||||
|
||||
const opList = await req(
|
||||
`/api/v2/research-projects/${p.project.id}/analysis-artifacts`,
|
||||
operatorToken
|
||||
);
|
||||
expect(opList.status).toBe(200);
|
||||
expect(
|
||||
((await opList.json()) as { artifacts: { id: string }[] }).artifacts.map(a => a.id)
|
||||
).toEqual(expect.arrayContaining([opFinding.id, agentFinding.id, plainNote.id]));
|
||||
});
|
||||
});
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue