@@ -113,8 +113,6 @@ const TAG_PATTERN = createReferencePattern()
113113const E2B_JS_WRAPPER_LINES = 3
114114const E2B_PYTHON_WRAPPER_LINES = 1
115115const MAX_SANDBOX_OUTPUT_FILES = 20
116- const MAX_PRIVATE_RESOLVED_SECRET_NAMES = 10_000
117- const MAX_PRIVATE_RESOLVED_SECRET_NAMES_BYTES = 1024 * 1024
118116const MAX_PRIVATE_FILE_SECRET_MATCH_EVENTS = 1_000_000
119117const SANDBOX_RUNTIME_PAYLOAD_PATH_ENV = '__SIM_RUNTIME_PAYLOAD_PATH'
120118
@@ -984,7 +982,6 @@ interface FunctionRouteExecutionContext {
984982 resolvedSecretNames : Set < string >
985983 includePrivateResolvedSecretNames : boolean
986984 privateResolvedSecretNamesMetadataType ?: ResolvedSecretNamesMetadataType
987- outputProvenanceComplete : boolean
988985 outputSecretMatcher ?: ResolvedSecretMatcher
989986 outputSecretNamesByScanLiteral : Map < string , string [ ] >
990987 outputSecretPlaintextsByName : Map < string , string >
@@ -1193,7 +1190,10 @@ function activateOutputSecretProvenance(
11931190 body : unknown ,
11941191 context : FunctionRouteExecutionContext
11951192) : void {
1196- if ( ! context . outputSecretMatcher ) return
1193+ if ( ! context . outputSecretMatcher ) {
1194+ activateCompiledSecretProvenance ( context )
1195+ return
1196+ }
11971197
11981198 const matchedPlaintexts = new Set < string > ( )
11991199 const projection = projectResolvedSecretContent (
@@ -1205,7 +1205,7 @@ function activateOutputSecretProvenance(
12051205 }
12061206 )
12071207 if ( ! projection . safe ) {
1208- context . outputProvenanceComplete = false
1208+ activateCompiledSecretProvenance ( context )
12091209 return
12101210 }
12111211 for ( const plaintext of matchedPlaintexts ) {
@@ -1215,6 +1215,17 @@ function activateOutputSecretProvenance(
12151215 }
12161216}
12171217
1218+ /**
1219+ * Conservatively activates only secrets whose placeholders were compiled for this invocation.
1220+ * This fallback is used when the bounded output classifier cannot inspect a result; it never
1221+ * considers configured-but-unused environment values and never mutates the functional result.
1222+ */
1223+ function activateCompiledSecretProvenance ( context : FunctionRouteExecutionContext ) : void {
1224+ for ( const name of context . outputSecretPlaintextsByName . keys ( ) ) {
1225+ context . resolvedSecretNames . add ( name )
1226+ }
1227+ }
1228+
12181229/**
12191230 * True when this execution compiled a secret placeholder or received a mounted file with verified
12201231 * secret provenance. Ordinary mounts without a provenance envelope are user data, not evidence that
@@ -1267,7 +1278,6 @@ async function getOutputFileSecretProvenance(
12671278 MAX_PRIVATE_FILE_SECRET_MATCH_EVENTS
12681279 )
12691280 } catch {
1270- context . outputProvenanceComplete = false
12711281 return { status : 'unknown' }
12721282 }
12731283
@@ -1292,17 +1302,8 @@ async function getOutputFileSecretProvenance(
12921302 }
12931303}
12941304
1295- function getPrivateResolvedSecretNames ( context : FunctionRouteExecutionContext ) : string [ ] | null {
1296- if ( ! context . outputProvenanceComplete ) return null
1297- if ( context . resolvedSecretNames . size > MAX_PRIVATE_RESOLVED_SECRET_NAMES ) return null
1298-
1299- const names = Array . from ( context . resolvedSecretNames ) . sort ( )
1300- let bytes = 0
1301- for ( const name of names ) {
1302- bytes += Buffer . byteLength ( name , 'utf8' )
1303- if ( bytes > MAX_PRIVATE_RESOLVED_SECRET_NAMES_BYTES ) return null
1304- }
1305- return names
1305+ function getPrivateResolvedSecretNames ( context : FunctionRouteExecutionContext ) : string [ ] {
1306+ return Array . from ( context . resolvedSecretNames ) . sort ( )
13061307}
13071308
13081309async function appendResolvedSecretNames (
@@ -1326,21 +1327,17 @@ async function appendPrivateResolvedSecretNames(
13261327) : Promise < NextResponse > {
13271328 if ( ! names || ! metadataType ) return response
13281329
1329- try {
1330- const body = ( await response . clone ( ) . json ( ) ) as Record < string , unknown >
1331- const headers = new Headers ( response . headers )
1332- headers . delete ( 'content-length' )
1333- headers . set ( PRIVATE_TOOL_METADATA_RESPONSE_HEADER , metadataType )
1334- return NextResponse . json (
1335- {
1336- ...body ,
1337- [ RESOLVED_SECRET_NAMES_FIELD ] : names ,
1338- } ,
1339- { status : response . status , statusText : response . statusText , headers }
1340- )
1341- } catch {
1342- return response
1343- }
1330+ const body = ( await response . json ( ) ) as Record < string , unknown >
1331+ const headers = new Headers ( response . headers )
1332+ headers . delete ( 'content-length' )
1333+ headers . set ( PRIVATE_TOOL_METADATA_RESPONSE_HEADER , metadataType )
1334+ return NextResponse . json (
1335+ {
1336+ ...body ,
1337+ [ RESOLVED_SECRET_NAMES_FIELD ] : names ,
1338+ } ,
1339+ { status : response . status , statusText : response . statusText , headers }
1340+ )
13441341}
13451342
13461343/**
@@ -2025,7 +2022,6 @@ export const POST = withRouteHandler(async (req: NextRequest) => {
20252022 resolvedSecretNames : new Set < string > ( ) ,
20262023 includePrivateResolvedSecretNames,
20272024 privateResolvedSecretNamesMetadataType,
2028- outputProvenanceComplete : true ,
20292025 outputSecretNamesByScanLiteral : new Map ( ) ,
20302026 outputSecretPlaintextsByName : new Map ( ) ,
20312027 mountedFileSecretProvenanceScanner,
@@ -2078,7 +2074,7 @@ export const POST = withRouteHandler(async (req: NextRequest) => {
20782074 } ) )
20792075 )
20802076 } catch {
2081- routeContext . outputProvenanceComplete = false
2077+ activateCompiledSecretProvenance ( routeContext )
20822078 }
20832079 }
20842080 resolvedCode = compilation . code
0 commit comments