selectOne('SELECT current_database() AS database, inet_server_port() AS port'); if ($target !== ['database'=>'stability_consumers_20261011_084534_test','port'=>55441]) { throw new RuntimeException('QA isolation required.'); } $proofPath = __DIR__.'/case56-resources-readonly-20261015.json'; if (is_file($proofPath)) { throw new RuntimeException('Preserve evidence.'); } $db->beginTransaction(); $db->statement('SET TRANSACTION READ ONLY'); try { $access = app(App\Services\PortalProfileAccess::class); $record = App\Models\Opportunity::findOrFail(56); $actor = App\Models\User::findOrFail(21); $documents = []; $inspect = function ($doc) { $disk = Illuminate\Support\Facades\Storage::disk('local'); $result = ['document_id'=>$doc->id,'file_name'=>$doc->file_name,'media_type'=>$doc->media_type, 'status'=>$doc->status,'scan'=>$doc->malware_scan_status, 'scanned_hash_matches'=>hash_equals(trim($doc->sha256), trim((string)$doc->malware_scanned_sha256)), 'file_exists'=>$disk->exists($doc->storage_key),'deleted'=>$doc->deleted_at !== null]; if ($result['file_exists']) { try { $bytes = $disk->get($doc->storage_key); if (($doc->storage_encryption ?? null) === 'laravel') { $bytes = Illuminate\Support\Facades\Crypt::decryptString($bytes); } $result['plaintext_hash_matches'] = hash_equals(trim($doc->sha256), hash('sha256',$bytes)); $result['detected_mime'] = (new finfo(FILEINFO_MIME_TYPE))->buffer($bytes); $result['size_bytes'] = strlen($bytes); if (str_starts_with($doc->media_type, 'image/')) { $im = @imagecreatefromstring($bytes); $result['image_decodes'] = $im !== false; if ($im !== false) { $result['dimensions'] = [imagesx($im), imagesy($im)]; $corner = imagecolorsforindex($im,imagecolorat($im,0,0)); $result['corner_rgb'] = [$corner['red'],$corner['green'],$corner['blue']]; imagedestroy($im); } } unset($bytes); } catch (Throwable $error) { $result['read_error_type'] = get_class($error); } } return $result; }; foreach (['images','documents'] as $kind) { foreach ($db->table('opportunity_'.$kind)->where('opportunity_id',56)->whereNull('deleted_at')->get() as $resource) { $doc = $db->table('documents')->where('id',$resource->document_id)->first(); if (! $doc) { $documents[] = ['kind'=>$kind,'resource_id'=>$resource->id,'document_missing'=>true]; continue; } $row = ['kind'=>$kind,'resource_id'=>$resource->id,'original'=>$inspect($doc), 'download_url'=>'https://portal-investidor.test:18445/minhas-oportunidades/56/resources/'.$kind.'/'.$resource->id.'/download']; $payload = json_decode($resource->payload,true,512,JSON_THROW_ON_ERROR); foreach ($payload['derivatives'] ?? [] as $derived) { $derivedDoc = $db->table('documents')->where('id',$derived['document_id'])->first(); $row['derivatives'][] = $derivedDoc ? $inspect($derivedDoc) : ['document_missing'=>true]; } $documents[] = $row; } } $denials = $db->select("SELECT created_at,actor_user_id,after_data->>'path' AS path,after_data->>'status' AS http_status FROM audit_events WHERE source_system='portal-profiles-v1' AND action='request_denied' AND after_data->>'path' LIKE 'minhas-oportunidades/56/resources/%' AND created_at >= '2026-10-15 00:00:00+00'::timestamptz ORDER BY created_at DESC LIMIT 12"); $proof = ['at'=>gmdate('c'),'target'=>$target,'SQL_read_only'=>true,'case'=>56,'state'=>$access->state($record), 'QA21_can_view'=>$access->canView($actor,$record),'resources'=>$documents,'recent_resource_denials'=>$denials, 'user_report'=>'Recursos listados; imagem mostra apenas fundo referido como ver; documentos não abrem. Responsável esclareceu: todos.', 'HTTP_downloads_not_tested'=>true,'browser_visual_not_verified'=>true,'credentials_or_sessions_read'=>false, 'QA_database_changes'=>0,'active_changes'=>0]; file_put_contents($proofPath,json_encode($proof,JSON_PRETTY_PRINT|JSON_UNESCAPED_UNICODE|JSON_UNESCAPED_SLASHES|JSON_THROW_ON_ERROR).PHP_EOL); echo json_encode($proof,JSON_UNESCAPED_UNICODE|JSON_UNESCAPED_SLASHES|JSON_THROW_ON_ERROR).PHP_EOL; } finally { $db->rollBack(); }