const {app,BrowserWindow}=require('electron'); const fs=require('node:fs'),path=require('node:path'),assert=require('node:assert/strict'); fs.writeFileSync(path.join(process.env.SAFETYNET_SMOKE_ARTIFACTS,'smoke-entry.txt'),'Electron JavaScript started.\n'); app.setPath('userData',process.env.SAFETYNET_SMOKE_USERDATA); app.disableHardwareAcceleration(); require('../apps/browser/main.cjs'); const wait=ms=>new Promise(r=>setTimeout(r,ms)); const log=message=>fs.appendFileSync(path.join(process.env.SAFETYNET_SMOKE_ARTIFACTS,'smoke-entry.txt'),message+'\n'); app.whenReady().then(async()=>{ try{ fs.appendFileSync(path.join(process.env.SAFETYNET_SMOKE_ARTIFACTS,'smoke-entry.txt'),'Electron ready.\n'); let win; for(let n=0;n<100;n++){win=BrowserWindow.getAllWindows()[0];if(win&&!win.webContents.isLoading()&&win.webContents.getURL().endsWith('index.html'))break;await wait(100);} await wait(300); log('Reading initial shell state: '+win.webContents.getURL()); const initial=await win.webContents.executeJavaScript('window.safetynet.state()');assert.equal(initial.data.ready,false); assert.equal((await win.webContents.executeJavaScript('window.safetynet.vaultCreate("fixture-master-password-only")')).ok,false,'Unenrolled vault access was allowed'); log('Starting enrollment'); const input={server:process.env.SAFETYNET_SMOKE_SERVER,code:process.env.SAFETYNET_SMOKE_CODE}; const result=await win.webContents.executeJavaScript(`window.safetynet.enroll(${JSON.stringify(input)})`);assert.equal(result.ok,true,result.error);assert.equal(result.data.ready,true);assert.equal(result.data.brand.name,'Acme Secure Browser'); await wait(600); log('Enrollment passed; testing managed page'); const page=win.contentView.children.find(v=>v.webContents!==win.webContents).webContents; log('Managed page URL: '+page.getURL()); const url=process.env.SAFETYNET_SMOKE_SINK; const publicResult=await page.executeJavaScript(`fetch(${JSON.stringify(url+'/sink')},{method:'POST',body:'Public information'}).then(r=>r.text()).catch(e=>({error:e.message}))`); log('Public request: '+JSON.stringify(publicResult));assert.equal(publicResult,'received'); const blocked=await page.executeJavaScript(`fetch(${JSON.stringify(url+'/sink')},{method:'POST',body:'Secret Roadmap'}).then(()=>false).catch(()=>true)`);assert.equal(blocked,true); const counts=await (await fetch(url+'/count')).json();assert.equal(counts.posts,1,'Secret payload reached the destination'); log('Request blocking passed'); // Use the already attached privileged page guard; no additional debugging port. const fileAuditHeaders={authorization:`Bearer ${process.env.SAFETYNET_SMOKE_ADMIN}`}; const filePriorIds=new Set((await (await fetch(`${process.env.SAFETYNET_SMOKE_SERVER}/api/admin/overview`,{headers:fileAuditHeaders})).json()).events.map(e=>e.id)); await page.executeJavaScript('(()=>{const input=document.createElement("input");input.type="file";input.id="native-upload-fixture";document.body.append(input);})()'); const fileDocument=await page.debugger.sendCommand('DOM.getDocument'); const fileNode=await page.debugger.sendCommand('DOM.querySelector',{nodeId:fileDocument.root.nodeId,selector:'#native-upload-fixture'}); async function nativeFileUpload(file){await page.debugger.sendCommand('DOM.setFileInputFiles',{nodeId:fileNode.nodeId,files:[file]});return page.executeJavaScript(`(()=>{const data=new FormData();data.append('file',document.getElementById('native-upload-fixture').files[0]);return fetch(${JSON.stringify(url+'/file-upload-sink')},{method:'POST',body:data}).then(r=>r.text()).catch(()=>false);})()`);} const fileBefore=(await (await fetch(url+'/count')).json()).fileUploadRequests; assert.equal(await nativeFileUpload(process.env.SAFETYNET_SMOKE_PUBLIC_UPLOAD),'file received','Clean native file upload was blocked'); const fileAfter=(await (await fetch(url+'/count')).json());assert.equal(fileAfter.fileUploadRequests,fileBefore+1);assert.equal(fileAfter.fileUploadExact,true,'Actual file bytes differed at receiver'); assert.equal(await nativeFileUpload(process.env.SAFETYNET_SMOKE_SECRET_UPLOAD),false,'Confidential native file upload escaped'); assert.equal((await (await fetch(url+'/count')).json()).fileUploadRequests,fileBefore+1,'Blocked native file upload reached receiver'); let fileEvents;await clipboardWait(async()=>{fileEvents=(await (await fetch(`${process.env.SAFETYNET_SMOKE_SERVER}/api/admin/overview`,{headers:fileAuditHeaders})).json()).events.filter(e=>!filePriorIds.has(e.id));return fileEvents.some(e=>e.kind==='upload.authorized')&&fileEvents.some(e=>e.kind==='upload.block'&&e.metadata.ruleId==='secret-roadmap');}); const fileAuditText=JSON.stringify(fileEvents),fileCrypto=require('node:crypto'); for(const fixture of [process.env.SAFETYNET_SMOKE_PUBLIC_UPLOAD,process.env.SAFETYNET_SMOKE_SECRET_UPLOAD]){const bytes=fs.readFileSync(fixture);assert.equal(fileAuditText.includes(bytes.toString('utf8').trim()),false,'File contents entered ordinary audit');assert.equal(fileAuditText.includes(fileCrypto.createHash('sha256').update(bytes).digest('hex')),false,'File hash entered ordinary request audit');bytes.fill(0);} fs.writeFileSync(path.join(process.env.SAFETYNET_SMOKE_ARTIFACTS,'native-file-upload-proof.json'),JSON.stringify({actualElectron:true,cleanFileReceivedExactlyOnce:true,exactFileBytesPreserved:true,secretFileNeverReachedReceiver:true,contentsAndHashesAbsentFromAudit:true,traceIds:fileEvents.map(e=>e.metadata.traceId).filter(Boolean)},null,2)); await page.executeJavaScript('document.getElementById("native-upload-fixture").remove()'); log('Managed native file upload receiver and confidentiality proof passed'); // Native Chromium header inspection must run before the dedicated receiver sees bytes. const headerAuditHeaders={authorization:`Bearer ${process.env.SAFETYNET_SMOKE_ADMIN}`}; const headerPriorIds=new Set((await (await fetch(`${process.env.SAFETYNET_SMOKE_SERVER}/api/admin/overview`,{headers:headerAuditHeaders})).json()).events.map(e=>e.id)); const headerBefore=(await (await fetch(url+'/count')).json()).headerRequests; assert.equal(await page.executeJavaScript(`fetch(${JSON.stringify(url+'/header-sink')},{headers:{'X-SafetyNet-Test':'Secret Roadmap'}}).then(()=>false).catch(()=>true)`),true,'Secret custom header escaped inspection'); assert.equal((await (await fetch(url+'/count')).json()).headerRequests,headerBefore,'Blocked header request reached receiver'); assert.equal(await page.executeJavaScript(`fetch(${JSON.stringify(url+'/header-sink')},{headers:{'X-SafetyNet-Test':'Public header fixture'}}).then(r=>r.text())`),'header received','Clean custom header was blocked'); assert.equal((await (await fetch(url+'/count')).json()).headerRequests,headerBefore+1,'Clean header request did not arrive exactly once'); let headerEvents,headerDecision; await clipboardWait(async()=>{headerEvents=(await (await fetch(`${process.env.SAFETYNET_SMOKE_SERVER}/api/admin/overview`,{headers:headerAuditHeaders})).json()).events;headerDecision=headerEvents.find(e=>!headerPriorIds.has(e.id)&&e.kind==='dlp.block'&&e.metadata.ruleId==='secret-roadmap'&&(!process.env.SAFETYNET_TEST_OTLP_ENDPOINT||e.metadata.traceId));return !!headerDecision;}); assert.equal(JSON.stringify(headerEvents).includes('Secret Roadmap'),false,'Header secret appeared in audit'); assert.equal(JSON.stringify(headerEvents).includes('Public header fixture'),false,'Allowed header value appeared in audit'); assert.equal(JSON.stringify(headerEvents).includes('X-SafetyNet-Test'),false,'Header name appeared in audit'); fs.writeFileSync(path.join(process.env.SAFETYNET_SMOKE_ARTIFACTS,'request-headers-native-proof.json'),JSON.stringify({actualElectron:true,blockedHeaderNeverReachedReceiver:true,cleanHeaderReceivedOnce:true,headerNamesAndValuesAbsentFromAudit:true,traceId:headerDecision.metadata.traceId},null,2)); log('Native custom header DLP blocks before transmission and preserves clean requests'); // Real Chromium gestures and the Windows clipboard: never execute fixture commands. const {clipboard}=require('electron'); const originalClipboardText=await clipboard.readText(); const clipboardSentinel='SafetyNet public clipboard fixture'; async function clipboardKey(key,shift=false){page.focus();page.sendInputEvent({type:'keyDown',keyCode:key,modifiers:shift?['shift']:['control']});page.sendInputEvent({type:'keyUp',keyCode:key,modifiers:shift?['shift']:['control']});await wait(800);await clipboardWait(async()=>!(await win.webContents.executeJavaScript('window.safetynet.state()')).data.clipboardPending);} async function clipboardWait(predicate,stage='Native fixture'){for(let attempt=0;attempt<200;attempt++){if(await predicate())return;await wait(100);}throw Error(`${stage} operation timed out`);} async function selectClipboardText(text){await page.executeJavaScript(`(()=>{let node=document.getElementById('clipboard-source');if(!node){node=document.createElement('pre');node.id='clipboard-source';document.body.append(node)}node.textContent=${JSON.stringify(text)};const range=document.createRange();range.selectNodeContents(node);const selection=getSelection();selection.removeAllRanges();selection.addRange(range);})()`);} try{ await clipboard.writeText(clipboardSentinel); await selectClipboardText('Public code example');await clipboardKey('C'); await clipboardWait(async()=>await clipboard.readText()==='Public code example'); assert.equal(await clipboard.readText(),'Public code example','Allowed native copy failed'); await clipboard.writeText(clipboardSentinel);await selectClipboardText('Secret Roadmap');await clipboardKey('C'); assert.equal(await clipboard.readText(),clipboardSentinel,'Blocked secret reached OS clipboard'); await selectClipboardText('powershell -NoProfile -EncodedCommand VABFAFMAVAA=');await clipboardKey('C'); assert.equal(await clipboard.readText(),clipboardSentinel,'ClickFix command reached OS clipboard'); await selectClipboardText('SAFETYNET_BLOCK_TEST');await clipboardKey('C'); assert.equal(await clipboard.readText(),clipboardSentinel,'YARA-blocked clipboard text reached OS clipboard'); await page.executeJavaScript("document.addEventListener('copy',event=>{event.clipboardData.setData('text/plain','Secret Roadmap');event.preventDefault()},{once:true})"); await selectClipboardText('Public selection despite hostile copy handler');await clipboardKey('C'); assert.equal((await clipboard.readText()).includes('Secret Roadmap'),false,'Page copy handler bypassed inspection'); await clipboard.writeText(clipboardSentinel); await page.executeJavaScript("(()=>{const e=document.getElementById('public-input');e.value='';e.focus()})()");await clipboardKey('V'); await clipboardWait(async()=>await page.executeJavaScript('document.getElementById("public-input").value')===clipboardSentinel); assert.equal(await page.executeJavaScript('document.getElementById("public-input").value'),clipboardSentinel,'Allowed native paste failed'); await clipboard.writeText('Secret Roadmap');await clipboardKey('V'); assert.equal(await page.executeJavaScript('document.getElementById("public-input").value'),clipboardSentinel,'Secret was inserted by native paste'); await page.executeJavaScript("(()=>{const e=document.getElementById('public-input');e.value='Secret Roadmap';e.focus();e.select()})()");await clipboard.writeText(clipboardSentinel);await clipboardKey('X'); assert.equal(await clipboard.readText(),clipboardSentinel,'Blocked cut wrote OS clipboard');assert.equal(await page.executeJavaScript('document.getElementById("public-input").value'),'Secret Roadmap','Blocked cut deleted source'); await page.executeJavaScript("(()=>{const e=document.getElementById('public-input');e.value='Public cut sample';e.focus();e.select()})()");await clipboardKey('Delete',true); assert.equal(await clipboard.readText(),'Public cut sample','Allowed Shift+Delete cut failed');assert.equal(await page.executeJavaScript('document.getElementById("public-input").value'),'','Allowed cut preserved deleted selection'); await clipboardKey('Insert',true); assert.equal(await page.executeJavaScript('document.getElementById("public-input").value'),'Public cut sample','Allowed Shift+Insert paste failed'); await clipboard.writeText(clipboardSentinel); // Programmatic legacy copy must not acquire the native user gesture capability. await selectClipboardText('Secret Roadmap');await page.executeJavaScript("document.execCommand('copy')",true);await wait(250); assert.equal(await clipboard.readText(),clipboardSentinel,'Legacy scripted copy bypassed clipboard gate'); const clipboardEvents=(await (await fetch(`${process.env.SAFETYNET_SMOKE_SERVER}/api/admin/overview`,{headers:{authorization:`Bearer ${process.env.SAFETYNET_SMOKE_ADMIN}`}})).json()).events.filter(event=>event.kind.startsWith('clipboard.')); assert.ok(clipboardEvents.some(event=>event.kind==='clipboard.block'),'Clipboard blocks were not centrally audited'); assert.equal(JSON.stringify(clipboardEvents).includes('Secret Roadmap'),false,'Clipboard contents appeared in audit records'); assert.equal(JSON.stringify(clipboardEvents).includes('VABFAFMAVAA='),false,'Command contents appeared in audit records'); log('Native clipboard: safe copy/paste allowed, confidential copy/paste/cut held, ClickFix execution command and hostile copy handler blocked'); }finally{await clipboard.writeText(originalClipboardText);await page.executeJavaScript("document.getElementById('clipboard-source')?.remove();document.getElementById('public-input').value=''");} const connection=await win.webContents.executeJavaScript('window.safetynet.agentConnection()');assert.equal(connection.ok,true,connection.error); const agentRequest=path.join(process.env.SAFETYNET_SMOKE_USERDATA,'agent-request.json'); let agentWindowStarted=Date.now(),agentCalls=0; async function localAgent(body){ if(++agentCalls>20){const remaining=Math.max(0,61000-(Date.now()-agentWindowStarted));await wait(Math.min(remaining,30000));if(remaining>30000)await wait(remaining-30000);agentWindowStarted=Date.now();agentCalls=1;} fs.writeFileSync(agentRequest,JSON.stringify(body)); const child=require('node:child_process').spawn(process.execPath,['scripts/agent-client.cjs','--connection',connection.data.credentialPath,'--request',agentRequest],{stdio:['ignore','pipe','pipe'],windowsHide:true});let output='',errors='';child.stdout.on('data',c=>output+=c);child.stderr.on('data',c=>errors+=c); const exit=await new Promise((resolve,reject)=>{child.on('exit',resolve);child.on('error',reject);});return {exit,output,errors}; } const sessionResult=await localAgent({action:'sessions'});assert.equal(sessionResult.exit,0,sessionResult.errors);const sessionId=JSON.parse(sessionResult.output).result[0].id;assert.match(sessionId,/^[0-9a-f-]{36}$/i);assert.equal(sessionId,(await win.webContents.executeJavaScript('window.safetynet.state()')).data.activeTabId); const readResult=await localAgent({action:'read',args:{sessionId}});assert.equal(readResult.exit,0,readResult.errors);assert.equal(readResult.output.includes('never-export-this'),false); const typeResult=await localAgent({action:'type',args:{sessionId,selector:'#public-input',text:'Agent typed public text'}});assert.equal(typeResult.exit,0,typeResult.errors);assert.equal(await page.executeJavaScript('document.getElementById("public-input").value'),'Agent typed public text'); const deniedType=await localAgent({action:'type',args:{sessionId,selector:'#private-input',text:'forbidden'}});assert.equal(deniedType.exit,1); const inspectResult=await localAgent({action:'inspect',args:{sessionId}});assert.equal(inspectResult.exit,0,inspectResult.errors);const inspected=JSON.parse(inspectResult.output).result;assert.ok(inspected.controls.some(control=>control.selector==='#public-input'&&control.value==='Agent typed public text'));assert.equal(inspectResult.output.includes('never-export-this'),false); const scrollResult=await localAgent({action:'scroll',args:{sessionId,x:0,y:100}});assert.equal(scrollResult.exit,0,scrollResult.errors); log('Authenticated agent sessions, sanitized read, type and sensitive-field denial passed'); let structuredAgentEvents; await clipboardWait(async()=>{structuredAgentEvents=(await (await fetch(`${process.env.SAFETYNET_SMOKE_SERVER}/api/admin/overview`,{headers:{authorization:`Bearer ${process.env.SAFETYNET_SMOKE_ADMIN}`}})).json()).events.filter(e=>e.metadata.agent);return structuredAgentEvents.some(e=>e.metadata.agent.action==='read'&&e.metadata.agent.outcome==='completed')&&structuredAgentEvents.some(e=>e.metadata.agent.action==='type'&&e.kind==='agent.denied'&&['denied','failed'].includes(e.metadata.agent.outcome));},'Structured agent audit'); const completedRead=structuredAgentEvents.find(e=>e.metadata.agent.action==='read'&&e.metadata.agent.outcome==='completed'); assert.equal(completedRead.metadata.agent.scope,'browser:read');assert.equal(completedRead.metadata.agent.sessionId,sessionId); assert.equal(await page.executeJavaScript('document.getElementById("private-input").value'),'never-export-this','Blocked agent changed a sensitive field'); const blockedType=structuredAgentEvents.find(e=>e.metadata.agent.action==='type'&&e.kind==='agent.denied'&&['denied','failed'].includes(e.metadata.agent.outcome)); const serializedAgentEvents=JSON.stringify(structuredAgentEvents); for(const privateValue of ['Agent typed public text','never-export-this','forbidden'])assert.equal(serializedAgentEvents.includes(privateValue),false,'Agent arguments reached durable audit'); assert.ok(structuredAgentEvents.every(e=>!Object.hasOwn(e.metadata.agent,'principalId')),'Shared capability fabricated individual identity'); fs.writeFileSync(path.join(process.env.SAFETYNET_SMOKE_ARTIFACTS,'structured-agent-audit-native-proof.json'),JSON.stringify({actualElectron:true,completedReadHasScopeAndSession:true,blockedActionRecorded:true,blockedActionOutcome:blockedType.metadata.agent.outcome,sensitiveFieldUnchanged:true,noArgumentsOrFabricatedIdentity:true,traceId:completedRead.metadata.traceId,eventId:completedRead.id},null,2)); async function agentApp(action,args={}){const response=await localAgent({action,args});assert.equal(response.exit,0,response.errors);return JSON.parse(response.output).result;} await agentApp('select',{sessionId,selector:'#public-select',value:'two'});assert.equal(await page.executeJavaScript('document.getElementById("public-select").value'),'two'); const lockedSelect=await localAgent({action:'select',args:{sessionId,selector:'#public-select',value:'locked'}});assert.equal(lockedSelect.exit,1); await agentApp('check',{sessionId,selector:'#public-checkbox',checked:true});assert.equal(await page.executeJavaScript('document.getElementById("public-checkbox").checked'),true); await agentApp('check',{sessionId,selector:'#public-checkbox',checked:false});assert.equal(await page.executeJavaScript('document.getElementById("public-checkbox").checked'),false); await agentApp('navigate',{sessionId,url:url+'/history-second'});assert.ok(page.getURL().endsWith('/history-second')); await agentApp('back',{sessionId});assert.equal(new URL(page.getURL()).pathname,'/'); await agentApp('forward',{sessionId});assert.ok(page.getURL().endsWith('/history-second')); await agentApp('reload',{sessionId});assert.ok(page.getURL().endsWith('/history-second')); await agentApp('back',{sessionId});assert.equal(new URL(page.getURL()).pathname,'/'); log('PQ agent history back/forward and same-URL reload passed'); const appStatus=await agentApp('application:state');assert.equal(appStatus.activeTabId,sessionId); await agentApp('settings:update',{appearance:{mode:'dark'}});assert.equal((await agentApp('settings:get')).appearance.mode,'dark'); const library=await agentApp('bookmarks:list');const bookmark={id:'agent-native-proof',title:'Public fixture bookmark',url:url+'/'}; await agentApp('bookmarks:mutate',{action:'add',bookmark,expectedRevision:library.personal.revision,policyVersion:library.policyVersion}); const updatedLibrary=await agentApp('bookmarks:list');assert.equal(updatedLibrary.personal.items.some(item=>item.id===bookmark.id),true); await agentApp('bookmarks:mutate',{action:'delete',id:bookmark.id,expectedRevision:updatedLibrary.personal.revision,policyVersion:updatedLibrary.policyVersion}); const createdTab=await agentApp('tabs:create',{group:'Agent proof'});assert.notEqual(createdTab.sessionId,sessionId); await agentApp('tabs:group',{sessionId:createdTab.sessionId,group:'Public work'}); await agentApp('tabs:activate',{sessionId});await agentApp('tabs:close',{sessionId:createdTab.sessionId}); assert.equal((await agentApp('application:state')).activeTabId,sessionId); log('First-class agent settings, centrally revisioned bookmarks and native tab controls passed'); const fixtureMaster='fixture-master-password-for-smoke-only'; assert.equal((await win.webContents.executeJavaScript(`window.safetynet.vaultCreate(${JSON.stringify(fixtureMaster)})`)).ok,true); const generated=await win.webContents.executeJavaScript('window.safetynet.vaultGenerate()');assert.equal(generated.ok,true);assert.equal(generated.data.length,32); const login={origin:'https://vault-login.test',label:'Fixture login',username:'fixture-user',password:generated.data}; const saved=await win.webContents.executeJavaScript(`window.safetynet.vaultSave(${JSON.stringify(login)})`);assert.equal(saved.ok,true); const listed=await win.webContents.executeJavaScript('window.safetynet.vaultList()');assert.equal(listed.ok,true);assert.equal(listed.data[0].password,undefined); const encryptedVault=fs.readFileSync(path.join(process.env.SAFETYNET_SMOKE_USERDATA,'password-vault.json'),'utf8');assert.equal(encryptedVault.includes(login.password),false);assert.equal(encryptedVault.includes(login.username),false);assert.equal(encryptedVault.includes(fixtureMaster),false); assert.equal((await win.webContents.executeJavaScript(`window.safetynet.vaultFill(${JSON.stringify(saved.data.id)})`)).ok,false,'HTTP page accepted vault fill'); // Protocol fixture exercises Chromium's actual isolated DOM fill; production TLS remains mandatory. await page.session.protocol.handle('https',request=>{if(new URL(request.url).origin!==login.origin)throw Error('Unexpected fixture origin');return new Response('
Secret Roadmap
';document.body.append(frame)})()");await wait(350); const childCapabilities=await page.executeJavaScript("(()=>{const child=document.getElementById('clipboard-child').contentWindow;return [typeof child.require,typeof child.process,typeof child.safetynet]})()"); assert.deepEqual(childCapabilities,['undefined','undefined','undefined'],'Child frame obtained Node or browser bridge capabilities'); assert.equal(page.getLastWebPreferences().sandbox,true,'Managed renderer sandbox was disabled'); await page.executeJavaScript("(()=>{const frame=document.getElementById('clipboard-child');try{const child=frame.contentWindow,d=child.document;if(!d.getElementById('selected'))return;const r=d.createRange();r.selectNodeContents(d.getElementById('selected'));child.getSelection().removeAllRanges();child.getSelection().addRange(r);child.focus();d.execCommand('copy')}catch{}finally{frame.remove()}})()",true);await wait(200); assert.equal(await clipboard.readText(),clipboardSentinel,'Child frame legacy copy bypassed clipboard protection'); await page.executeJavaScript("(()=>{const frame=document.createElement('iframe');document.body.append(frame);try{const child=frame.contentWindow,d=child.document;d.body.textContent='Secret Roadmap';const r=d.createRange();r.selectNodeContents(d.body);child.getSelection().removeAllRanges();child.getSelection().addRange(r);child.focus();d.execCommand('copy')}finally{frame.remove()}})()",true);await wait(200); assert.equal(await clipboard.readText(),clipboardSentinel,'Immediate about:blank child copy bypassed clipboard protection'); const childReset=await page.executeJavaScript("(()=>{const frame=document.createElement('iframe');document.body.append(frame);try{const child=frame.contentWindow,d=child.document;d.open();d.write('Secret Roadmap
');d.close();const r=d.createRange();r.selectNodeContents(d.body);child.getSelection().removeAllRanges();child.getSelection().addRange(r);child.focus();d.execCommand('copy');return 'reset-completed'}catch(error){return error.name}finally{frame.remove()}})()",true);await wait(200); assert.equal(childReset,'SecurityError','Child document replacement was not blocked'); assert.equal(await clipboard.readText(),clipboardSentinel,'Document reset bypassed child clipboard protection'); const mainReset=await page.executeJavaScript("(()=>{try{document.open();document.write('Secret Roadmap
');document.close();const r=document.createRange();r.selectNodeContents(document.body);getSelection().removeAllRanges();getSelection().addRange(r);document.execCommand('copy');return 'reset-completed'}catch(error){return error.name}})()",true);await wait(200); assert.equal(mainReset,'SecurityError','Main document replacement was not blocked'); assert.equal(await clipboard.readText(),clipboardSentinel,'Document reset bypassed main-frame clipboard protection'); assert.equal((await win.webContents.executeJavaScript('window.safetynet.navigate("https://vault-login.test/login")')).ok,true); }finally{await clipboard.writeText(beforeScriptedClipboard);} assert.equal((await win.webContents.executeJavaScript(`window.safetynet.vaultFill(${JSON.stringify(saved.data.id)})`)).ok,true,'Exact HTTPS origin fill failed'); assert.equal(await page.executeJavaScript('document.getElementById("login-user").value'),login.username);assert.equal(await page.executeJavaScript('document.getElementById("login-password").value'),login.password); assert.equal(await page.executeJavaScript('typeof window.safetynet'),'undefined','Remote site obtained vault bridge'); await page.executeJavaScript('document.querySelector("form").action="https://different-origin.test/capture"'); assert.equal((await win.webContents.executeJavaScript(`window.safetynet.vaultFill(${JSON.stringify(saved.data.id)})`)).ok,false,'Cross-origin form accepted password'); }finally{await page.session.protocol.unhandle('https');await win.webContents.executeJavaScript(`window.safetynet.navigate(${JSON.stringify(url)})`);} await win.webContents.executeJavaScript('document.getElementById("passwords").click()');await wait(200); assert.equal(await win.webContents.executeJavaScript('document.getElementById("vault").hidden'),false); try{fs.writeFileSync(path.join(process.env.SAFETYNET_SMOKE_ARTIFACTS,'browser-vault.png'),(await win.webContents.capturePage()).toPNG());}catch{log('Vault screenshot unavailable');} win.emit('blur');await wait(100);const blurVaultStatus=await win.webContents.executeJavaScript('window.safetynet.vaultStatus()');if(!blurVaultStatus.ok){const failedState=(await win.webContents.executeJavaScript('window.safetynet.state()')).data;log('Vault status denial: '+JSON.stringify({error:blurVaultStatus.error,ready:failedState.ready,message:failedState.message,policyVersion:failedState.policyVersion}));}assert.equal(blurVaultStatus.ok,true,blurVaultStatus.error);assert.equal(blurVaultStatus.data.locked,true); assert.equal((await win.webContents.executeJavaScript('window.safetynet.vaultList()')).ok,false); assert.equal((await win.webContents.executeJavaScript('window.safetynet.vaultUnlock("wrong-fixture-password-only")')).ok,false); assert.equal((await win.webContents.executeJavaScript(`window.safetynet.vaultUnlock(${JSON.stringify(fixtureMaster)})`)).ok,true); assert.equal((await win.webContents.executeJavaScript('window.safetynet.vaultList()')).data.length,1); await win.webContents.executeJavaScript('document.getElementById("vault-close").click()');await wait(100); log('Real local vault: native ML-KEM, DPAPI, encrypted storage, masked metadata, isolated exact-HTTPS fill, hostile form denial, blur lock and reopen passed'); const {dialog}=require('electron'),originalSave=dialog.showSaveDialog;let saveCalls=0; dialog.showSaveDialog=async(_win,options)=>{saveCalls++;return {canceled:false,filePath:path.join(process.env.SAFETYNET_SMOKE_USERDATA,path.basename(options.defaultPath))};}; try{ await page.executeJavaScript('document.getElementById("safe-download").click()'); const safeFile=path.join(process.env.SAFETYNET_SMOKE_USERDATA,'safe.bin');for(let n=0;n<600;n++){if(fs.existsSync(safeFile)&&fs.statSync(safeFile).size===5)break;await wait(100);} assert.equal(fs.existsSync(safeFile),true,'Scanned benign download was not released');assert.deepEqual(fs.readFileSync(safeFile),Buffer.from([0,1,2,3,255]));assert.equal(saveCalls,1); await clipboardWait(async()=>{const completed=(await win.webContents.executeJavaScript('window.safetynet.state()')).data;return completed.ready&&completed.message==='Download scanned and saved.';}); await page.executeJavaScript('document.getElementById("blocked-download").click()'); for(let n=0;n<300;n++){const s=await win.webContents.executeJavaScript('window.safetynet.state()');if(s.data.message.startsWith('Download blocked:'))break;await wait(100);} assert.equal(fs.existsSync(path.join(process.env.SAFETYNET_SMOKE_USERDATA,'blocked.bin')),false);assert.equal(saveCalls,1,'Blocked download reached save dialog'); log('Real YARA download gate: safe binary saved; blocked file never reaches save dialog/filesystem'); const evidenceHeaders={authorization:`Bearer ${process.env.SAFETYNET_SMOKE_ADMIN}`};let recorded; await clipboardWait(async()=>{recorded=(await (await fetch(`${process.env.SAFETYNET_SMOKE_SERVER}/api/admin/overview`,{headers:evidenceHeaders})).json()).events.filter(e=>e.kind==='evidence.recorded');return recorded.length>=2;}); const captured=[];for(const event of recorded){const response=await fetch(`${process.env.SAFETYNET_SMOKE_SERVER}/api/admin/evidence/${event.metadata.evidenceId}?reason=investigation`,{headers:evidenceHeaders});assert.equal(response.status,200);captured.push((await response.json()).payload);} assert.ok(captured.some(p=>p.decision==='allow'&&p.name==='safe.bin'&&p.bytes===5&&p.sourceUrl===url+'/download-safe')); assert.ok(captured.some(p=>p.decision==='block'&&p.name==='blocked.bin'&&p.sourceUrl===url+'/download-blocked')); assert.ok(captured.every(p=>!p.content&&!p.data&&!p.filePath)); fs.writeFileSync(path.join(process.env.SAFETYNET_SMOKE_ARTIFACTS,'download-evidence-native-proof.json'),JSON.stringify({actualElectron:true,allowedDownloadCaptured:true,blockedDownloadCaptured:true,noFileContents:true,protectedAccessAudited:true,eventIds:recorded.map(e=>e.metadata.sourceEventId)},null,2)); log('Native allowed/blocked download metadata captured in encrypted evidence with audited analyst access'); }finally{dialog.showSaveDialog=originalSave;} const sample=path.join(process.env.SAFETYNET_SMOKE_USERDATA,'secret-sample.docx'); const runtime=path.resolve('.runtime/windows/python/python.exe'); if(fs.existsSync(runtime)){ const create=require('node:child_process').spawnSync(runtime,['-c','import sys,zipfile; z=zipfile.ZipFile(sys.argv[1],"w"); z.writestr("word/document.xml",\'