"""Reproduce local-environment diagnostic access in QA only; no contents/credentials logged.""" from pathlib import Path import sys,json,re,time,hashlib sys.argv=['audit-http.py','promoter'];OUT=Path(__file__).resolve().parent;ROOT=OUT.parents[1] ns={'__file__':str(OUT/'audit-http.py')} exec((OUT/'audit-http.py').read_text(encoding='utf-8-sig').split("proof={'at':")[0],ns) plan=json.loads((ROOT/'storage/app/private/investmoz-v2/portal-audit/portal-stability-latest.json').read_text(encoding='utf-8-sig')) qa=Path(plan['source']);envfile=qa/'.env.stability-consumers';configfile=qa/'config/inertia.php';active=ROOT/'config/inertia.php' original_env=envfile.read_bytes();original_config=configfile.read_bytes();active_before=active.read_bytes() assert original_config==active_before assert qa.is_relative_to(ROOT/'storage/app/private/investmoz-v2/portal-audit') new_config=original_config.replace(b'return [',b"return [\n\n // Runtime diagnostics must not expose portal requests or private props.\n 'devtools' => ['enabled' => false],",1) assert new_config!=original_config proof={'target':ns['TARGET'],'base':ns['BASE'],'active_business_writes':0,'active_HTTP_requests':0,'browser_observed':False,'checks':{},'raw_response_bodies_recorded':False,'codes_secrets_cookies_recorded':False} def identity(s): status,_,body=s.request('GET','/_qa/runtime',check_target=False) assert status==200 and json.loads(body)['target']['database']=='stability_consumers_20261011_084534_test' try: # Only QA environment: reproduce the active default APP_ENV=local, preserving all other bytes. altered,n=re.subn(rb'(?m)^APP_ENV=[^\r\n]*',b'APP_ENV=local',original_env);assert n==1 envfile.write_bytes(altered);time.sleep(3);s=ns['Session']();identity(s) status,_,body=s.request('GET','/_inertia/devtools/entries?limit=1',accept='application/json') assert status==200;data=json.loads(body);assert isinstance(data,list) proof['checks']['before_anonymous_diagnostic_listing']={'status':status,'returned_entries':len(data),'no_authentication':True} # Record only the fact that data classes exist; discard all values without exporting them. proof['checks']['diagnostic_record_fields']=[key for key in ['http','propValues','route','componentPath'] if data and key in data[0]] configfile.write_bytes(new_config);time.sleep(3);s=ns['Session']();identity(s) for route in ['/_inertia/devtools/entries','/_inertia/devtools/entries/01ARZ3NDEKTSV4RRFFQ69G5FAV']: status,_,_=s.request('GET',route,accept='application/json');assert status==404 proof['checks'][route]={'after_status':status,'environment':'local','anonymous':True} # Authentication is exercised only with diagnostics already off: no code/password enters diagnostic evidence. a=ns['actors']['promoter'];assert s.request('GET','/login')[0]==200 assert s.request('POST','/login',{'email':a['email'],'password':a['password']},'application/json')[0] in [200,204,302] assert s.request('GET','/two-factor-challenge')[0]==200 if time.time()%30>26:time.sleep(4) assert s.request('POST','/two-factor-challenge',{'code':ns['otp'](a.get('totp_secret',a.get('secret')))},'application/json')[0] in [200,204,302] for route in ['/dashboard','/minhas-oportunidades/16/edit','/minhas-oportunidades/30/view']: status,_,body=s.request('GET',route);assert status==200 proof['checks'][route]={'status':status,'normal_MFA_session':True,'actor_id':ns['page'](body)['props']['auth']['user']['id']} assert s.request('POST','/logout',{},'application/json')[0] in [200,204,302] proof['result']='passed' except Exception as error:proof.update(result='stopped',error_type=type(error).__name__) finally: envfile.write_bytes(original_env) # Correction remains QA-only; if no positive test, preserve the prior QA configuration. if proof.get('result')!='passed':configfile.write_bytes(original_config) assert active.read_bytes()==active_before proof['QA_environment_restored']=envfile.read_bytes()==original_env proof['active_config_unchanged']=True;proof['active_config_sha256']=hashlib.sha256(active_before).hexdigest();proof['QA_config_sha256']=hashlib.sha256(configfile.read_bytes()).hexdigest() (OUT/'devtools-isolation-http.json').write_text(json.dumps(proof,ensure_ascii=False,indent=2),encoding='utf-8') print(json.dumps({'result':proof['result'],'checks':proof['checks'],'QA_environment_restored':proof['QA_environment_restored'],'active_config_unchanged':True})) sys.exit(0 if proof['result']=='passed' else 1)