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:30:17 -05:00
parent 7f4d3c7543
commit 48ae151260
3 changed files with 305 additions and 37 deletions

View file

@ -1224,8 +1224,9 @@ describe.skipIf(!url)('authoritative research principals and budgets', () => {
});
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 data = walkForwardDataset(),
f = await fixture(4, true, data.dataset),
p = await provision(f, { maxActiveTrials: 4 });
const security = createWebApiSecurity(f.container, {
adminToken: operatorToken,
serviceToken: 'service-test-secret-123456789012345678901',
@ -1247,13 +1248,35 @@ describe.skipIf(!url)('authoritative research principals and budgets', () => {
...(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] }),
// Execute a real operator-owned chronological validation and its test holdout phase
const { validations } = createResearchServices(f.container);
const validationInput = {
backtestId: f.draft.id,
name: 'Operator chronological holdout',
grid: { fastPeriod: [1, 2] },
recipe: data.windows[0]!,
};
const prepared = await f.experiments.previewValidation(validationInput);
const train = await validations.submit(
{ ...validationInput, previewHash: prepared.previewHash },
receipt('operator')
);
const opRunId = required(opExp.trials[0]!.runId);
for (const trial of required(train.phases[0]?.experiment).trials) {
await f.execute(required(trial.runId));
}
const selected = await validations.select(
train.id,
{ previewHash: prepared.previewHash },
receipt('operator')
);
const holdoutPhase = required(
selected.validation.phases.find(phase => phase.phase === 'test')
);
const opRunId = required(required(holdoutPhase.experiment).trials[0]?.runId);
await f.execute(opRunId);
const holdoutDatasetHash = required(
prepared.partitions.find(partition => partition.phase === 'test')?.dataset.hash
);
const agentExp = await f.experiments.submit(
await preparation(f, 'Agent search', f.draft.id, { fastPeriod: [1] }),
@ -1262,13 +1285,13 @@ describe.skipIf(!url)('authoritative research principals and budgets', () => {
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
// Operator attaches the holdout phase 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',
body: 'Holdout Sharpe ratio from operator test phase',
evidence: [
{
runId: opRunId,
@ -1301,10 +1324,10 @@ describe.skipIf(!url)('authoritative research principals and budgets', () => {
'operator'
);
// Agent cannot read operator run results directly
// Agent cannot read operator holdout 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
// Agent cannot read the operator holdout 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}`,
@ -1314,13 +1337,16 @@ describe.skipIf(!url)('authoritative research principals and budgets', () => {
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);
expect(await denied.text()).not.toContain(holdoutDatasetHash);
}
}
}
// 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);
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 }[] }
@ -1339,11 +1365,11 @@ describe.skipIf(!url)('authoritative research principals and budgets', () => {
}
).artifact.latestRevision.evidence[0]?.runId
).toBe(agentRunId);
expect((await req(`/api/v2/analysis-artifacts/${agentFinding.id}/revisions`, p.token)).status).toBe(
200
);
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
// Agent cannot attach an operator-owned holdout run as evidence when creating an artifact
const forged = await req(
`/api/v2/research-projects/${p.project.id}/analysis-artifacts`,
p.token,
@ -1351,7 +1377,7 @@ describe.skipIf(!url)('authoritative research principals and budgets', () => {
{
kind: 'finding',
title: 'Attempted exfiltration',
body: 'Refers to operator run',
body: 'Refers to operator holdout run',
evidence: [
{
runId: opRunId,
@ -1363,16 +1389,21 @@ describe.skipIf(!url)('authoritative research principals and budgets', () => {
);
expect(forged.status).toBe(403);
// Operator retains full read access to the holdout finding, its revisions, and the full list
// Operator retains full read access to the holdout finding, its retained metric, and holdout dataset hash
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: {
latestRevision: {
evidence: { runId: string; datasetHash: string; value: number }[];
};
};
}
).artifact;
expect(opArtifact.latestRevision.evidence[0]?.runId).toBe(opRunId);
expect(opArtifact.latestRevision.evidence[0]?.datasetHash).toBe(f.dataset.manifest.hash);
expect(opArtifact.latestRevision.evidence[0]?.datasetHash).toBe(holdoutDatasetHash);
expect(Number.isFinite(opArtifact.latestRevision.evidence[0]?.value)).toBe(true);
expect(
(await req(`/api/v2/analysis-artifacts/${opFinding.id}/revisions`, operatorToken)).status
@ -1386,5 +1417,66 @@ describe.skipIf(!url)('authoritative research principals and budgets', () => {
expect(
((await opList.json()) as { artifacts: { id: string }[] }).artifacts.map(a => a.id)
).toEqual(expect.arrayContaining([opFinding.id, agentFinding.id, plainNote.id]));
// Mixed revision history: after operator revises the finding to reference only the agent's run,
// the latest revision becomes visible in the project list and by ID, while /revisions still fails closed (403)
await f.research.reviseArtifact(
opFinding.id,
{
title: 'Sanitized finding',
body: 'Replaced holdout reference with agent-owned run',
evidence: [
{
runId: agentRunId,
metricsVersion: 'canonical-analytics/v1',
metricPath: 'analytics.metrics.sharpeRatio',
},
],
},
'operator'
);
const agentListAfterRev = await req(
`/api/v2/research-projects/${p.project.id}/analysis-artifacts`,
p.token
);
expect(agentListAfterRev.status).toBe(200);
expect(
((await agentListAfterRev.json()) as { artifacts: { id: string }[] }).artifacts.map(a => a.id)
).toEqual(expect.arrayContaining([opFinding.id, agentFinding.id, plainNote.id]));
const agentItemAfterRev = await req(`/api/v2/analysis-artifacts/${opFinding.id}`, p.token);
expect(agentItemAfterRev.status).toBe(200);
const sanitizedText = await agentItemAfterRev.text();
expect(sanitizedText).not.toContain(holdoutDatasetHash);
expect(
(
JSON.parse(sanitizedText) as {
artifact: { latestRevision: { ordinal: number; evidence: { runId: string }[] } };
}
).artifact.latestRevision
).toMatchObject({ ordinal: 2, evidence: [{ runId: agentRunId }] });
const agentHistoryAfterRev = await req(
`/api/v2/analysis-artifacts/${opFinding.id}/revisions`,
p.token
);
expect(agentHistoryAfterRev.status).toBe(403);
expect(agentHistoryAfterRev.headers.get('cache-control')).toBe('no-store');
expect(await agentHistoryAfterRev.text()).not.toContain(holdoutDatasetHash);
const opHistoryAfterRev = await req(
`/api/v2/analysis-artifacts/${opFinding.id}/revisions`,
operatorToken
);
expect(opHistoryAfterRev.status).toBe(200);
const opRevisions = (
(await opHistoryAfterRev.json()) as {
revisions: { ordinal: number; evidence: { runId: string; datasetHash: string }[] }[];
}
).revisions;
expect(opRevisions).toHaveLength(2);
expect(opRevisions[0]?.evidence[0]?.datasetHash).toBe(holdoutDatasetHash);
expect(opRevisions[1]?.evidence[0]?.runId).toBe(agentRunId);
});
});