Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions apps/sim/app/api/guardrails/validate/route.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -244,6 +244,7 @@ describe('POST /api/guardrails/validate', () => {
expect(res.status).toBe(200)
expect(mockImportProvenance).toHaveBeenCalledWith(provenance, 'secret value', ['input'], {
trusted: true,
origin: 'guardrailsRoute.inputProvenance',
})
})

Expand Down
2 changes: 1 addition & 1 deletion apps/sim/app/api/guardrails/validate/route.ts
Original file line number Diff line number Diff line change
Expand Up @@ -267,7 +267,7 @@ export const POST = withRouteHandler(async (request: NextRequest) => {
provenanceInspection.value,
inputStr,
['input'],
{ trusted: true }
{ trusted: true, origin: 'guardrailsRoute.inputProvenance' }
)
).success
: true
Expand Down
1 change: 1 addition & 0 deletions apps/sim/app/api/mcp/serve/[serverId]/route.ts
Original file line number Diff line number Diff line change
Expand Up @@ -288,6 +288,7 @@ async function projectWorkflowMcpModelContent(
): Promise<unknown> {
const registry = new ResolvedSecretTraceRegistry([], scope)
const imported = await registry.importCrossingProvenance(privateProvenance, value, {
origin: 'mcpServe.workflowCrossing',
trusted: true,
})
if (!imported || !registry.isComplete()) {
Expand Down
5 changes: 4 additions & 1 deletion apps/sim/app/api/providers/route.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -208,7 +208,10 @@ describe('POST /api/providers', () => {
)

expect(res.status).toBe(200)
expect(mockImportProvenance).toHaveBeenCalledWith(provenance, { trusted: true })
expect(mockImportProvenance).toHaveBeenCalledWith(provenance, {
trusted: true,
origin: 'providersRoute.requestProvenance',
})
})

it('projects legacy private prompt provenance on the provider-facing copy', async () => {
Expand Down
2 changes: 1 addition & 1 deletion apps/sim/app/api/providers/route.ts
Original file line number Diff line number Diff line change
Expand Up @@ -272,7 +272,7 @@ export const POST = withRouteHandler(async (request: NextRequest) => {
const provenanceReady =
await providerRuntimeContext.resolvedSecretTraceRegistry.importProvenance(
provenanceInspection.value,
{ trusted: true }
{ trusted: true, origin: 'providersRoute.requestProvenance' }
)
if (!provenanceReady || !providerRuntimeContext.resolvedSecretTraceRegistry.isComplete()) {
return NextResponse.json(
Expand Down
5 changes: 4 additions & 1 deletion apps/sim/app/api/workflows/[id]/log/route.ts
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,10 @@ export const POST = withRouteHandler(
if (trustedProvenance === undefined) {
resolvedSecretTraceRegistry.markIncomplete()
} else {
await resolvedSecretTraceRegistry.importProvenance(trustedProvenance, { trusted: true })
await resolvedSecretTraceRegistry.importProvenance(trustedProvenance, {
trusted: true,
origin: 'workflowLogRoute.trustedProvenance',
})
}
loggingSession.setResolvedSecretTraceRegistry(resolvedSecretTraceRegistry)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -293,7 +293,7 @@ describe('MothershipBlockHandler', () => {
content: 'raw secret remains functional',
__resolvedSecretTraceProvenance: undefined,
}),
{ trusted: true }
{ trusted: true, origin: 'mothership.payloadCrossing' }
)
expect(registry.markIncomplete).not.toHaveBeenCalled()
expect(result).toMatchObject({ content: 'raw secret remains functional' })
Expand Down Expand Up @@ -519,7 +519,7 @@ describe('MothershipBlockHandler', () => {
error: 'secret-backed failure',
__resolvedSecretTraceProvenance: undefined,
}),
{ trusted: true }
{ trusted: true, origin: 'mothership.payloadCrossing' }
)
expect(context.errorResolvedSecretTraceRegistry).toBeDefined()
expect(context.errorResolvedSecretTraceRegistry).not.toBe(context.resolvedSecretTraceRegistry)
Expand Down Expand Up @@ -557,7 +557,7 @@ describe('MothershipBlockHandler', () => {
error: 'secret-backed failure',
__resolvedSecretTraceProvenance: undefined,
}),
{ trusted: true }
{ trusted: true, origin: 'mothership.payloadCrossing' }
)
expect(registry.markIncomplete).not.toHaveBeenCalled()
expect(context.errorResolvedSecretTraceRegistry).toBeDefined()
Expand Down Expand Up @@ -601,7 +601,7 @@ describe('MothershipBlockHandler', () => {
content: 'unchanged',
__resolvedSecretTraceProvenance: undefined,
}),
{ trusted: true }
{ trusted: true, origin: 'mothership.payloadCrossing' }
)
expect(registry.markIncomplete).not.toHaveBeenCalled()
expect(JSON.stringify(result.execution.output)).not.toContain('__resolvedSecretTraceProvenance')
Expand Down
5 changes: 4 additions & 1 deletion apps/sim/executor/handlers/mothership/mothership-handler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -378,7 +378,10 @@ async function consumeMothershipProvenance(

if (!registry) return false

const imported = await registry.importProvenanceForValue(provenance, payload, { trusted: true })
const imported = await registry.importProvenanceForValue(provenance, payload, {
trusted: true,
origin: 'mothership.payloadCrossing',
})
if (!imported) throw new Error('Mothership response provenance metadata is invalid')
return true
}
Expand Down
2 changes: 2 additions & 0 deletions apps/sim/executor/handlers/workflow/workflow-handler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -450,6 +450,7 @@ export class WorkflowBlockHandler implements BlockHandler {
await childResolvedSecretTraceRegistry.importProvenance(crossingProvenance, {
trusted: true,
anonymous: true,
origin: 'workflowHandler.childCrossing',
})
}
// Custom-block children authenticate internal tool calls as the source
Expand Down Expand Up @@ -711,6 +712,7 @@ export class WorkflowBlockHandler implements BlockHandler {
await ctx.resolvedSecretTraceRegistry.importProvenance(crossingProvenance, {
trusted: true,
anonymous: true,
origin: 'workflowHandler.parentCrossing',
})
}
return exposedOutput
Expand Down
29 changes: 29 additions & 0 deletions apps/sim/executor/utils/resolved-secret-projection-refusal.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -195,6 +195,35 @@ describe('refuseResolvedSecretProjection', () => {
expect(refusalRecords()).toHaveLength(3)
})

it('names the importer that condemned the run, through the fork and merge that hid it', async () => {
const parent = new ResolvedSecretTraceRegistry([], scope)
const fork = parent.forkForToolCall()
await fork.importCrossingProvenance(
{ version: 1, complete: false, entries: [], scope },
{ rows: [] },
{ trusted: true, origin: 'tool.table_query_rows' }
)
parent.mergeToolCallRegistry(fork)
mockLogger.error.mockClear()
mockLogger.warn.mockClear()

expect(() =>
refuseResolvedSecretProjection({
site: 'router.contextModelInput',
message: 'Router model input could not be safely projected',
registry: parent,
inputPath: 'context,routes',
})
).toThrow()

expect(refusalRecords()[0][1]).toEqual(
expect.objectContaining({
reason: 'source-provenance-incomplete',
origins: ['tool.table_query_rows'],
})
)
})

it('records no secret material', () => {
const registry = new ResolvedSecretTraceRegistry(
[{ name: 'API_KEY', plaintext: 'super-secret-value', encryptedValue: 'encrypted' }],
Expand Down
2 changes: 2 additions & 0 deletions apps/sim/executor/utils/resolved-secret-projection-refusal.ts
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,8 @@ function reportRefusal({ site, registry, inputPath }: ResolvedSecretProjectionRe
? {
reason: diagnostics.reasons[0],
reasons: diagnostics.reasons,
/** The importers that cost the run its completeness — who to go and look at. */
...(diagnostics.origins.length > 0 ? { origins: diagnostics.origins } : {}),
incompleteInputPathCount: diagnostics.incompleteInputPathCount,
activeEntryCount: diagnostics.activeEntryCount,
...(diagnostics.scopeWorkspaceId
Expand Down
34 changes: 34 additions & 0 deletions apps/sim/executor/utils/resolved-secret-trace-registry.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1562,6 +1562,40 @@ describe('incompleteness diagnostics', () => {
expect(registry.getIncompletenessDiagnostics()?.reasons[0]).toBe('constructed-incomplete')
})

it('attributes an untrustworthy bundle to the caller that imported it', async () => {
const registry = new ResolvedSecretTraceRegistry([], scope)

await registry.importProvenance(
{ version: 1, complete: false, entries: [], scope },
{ trusted: true, origin: 'workflowHandler.childCrossing' }
)

expect(registry.getIncompletenessDiagnostics()?.origins).toEqual([
'workflowHandler.childCrossing',
])
expect(mockLogger.warn).toHaveBeenCalledWith(
'Resolved secret registry marked incomplete',
expect.objectContaining({
reason: 'source-provenance-incomplete',
origin: 'workflowHandler.childCrossing',
})
)
})

it('bounds retained origins, which are caller-supplied rather than a closed union', async () => {
const registry = new ResolvedSecretTraceRegistry([], scope)

for (let index = 0; index < 20; index++) {
await registry.importProvenance(
{ version: 1, complete: false, entries: [], scope },
{ trusted: true, origin: `caller.${index}` }
)
}

expect(registry.getIncompletenessDiagnostics()?.origins).toHaveLength(8)
expect(registry.getIncompletenessDiagnostics()?.origins[0]).toBe('caller.0')
})

it('records no secret material alongside the reason', () => {
const registry = new ResolvedSecretTraceRegistry([], scope)

Expand Down
Loading
Loading