diff --git a/backend/public/index.html b/backend/public/index.html index 7c19edd..9b85244 100644 --- a/backend/public/index.html +++ b/backend/public/index.html @@ -874,7 +874,7 @@ const controller = new AbortController(); const timer = setTimeout(() => controller.abort(), 6000); try { - const response = await fetch(url + '?_=' + Date.now(), { mode: 'no-cors', cache: 'no-store', redirect: 'error', signal: controller.signal }); + const response = await fetch(url + '?_=' + Date.now(), { mode: 'no-cors', cache: 'no-store', redirect: 'follow', credentials: 'omit', signal: controller.signal }); return { provider, ok: response.type === 'opaque' || response.ok }; } catch { return { provider, ok: false }; } finally { clearTimeout(timer); } diff --git a/backend/test/portal-access.test.js b/backend/test/portal-access.test.js index 11f37b2..2ad8763 100644 --- a/backend/test/portal-access.test.js +++ b/backend/test/portal-access.test.js @@ -19,7 +19,8 @@ async function portal({search,storage={},access={ok:true,authenticated:true,seco if(path==='/api/status/Ptest')return {ok:true,json:async()=>({status:'pending'})}; if(path==='/api/access/report')return {ok:true,json:async()=>({ok:true})}; if(path.startsWith('https://www.gstatic.com/') || path.startsWith('https://www.apple.com/')) { - assert.equal(options.mode,'no-cors');assert.equal(options.redirect,'error'); + // Fetch rejects no-cors requests unless redirect mode is follow, before any network traffic. + if(options.mode==='no-cors' && (options.redirect ?? 'follow')!=='follow')throw new TypeError('Invalid no-cors redirect mode'); if(!externalAvailable)throw new Error('Network unreachable'); return {type:'opaque',ok:false}; } @@ -74,7 +75,12 @@ test('client probes external services and reports observations without sending i const report=p.requests.find(r=>r.path==='/api/access/report');assert.ok(report); assert.equal(JSON.parse(report.options.body).results.every(r=>r.ok),externalAvailable); const external=p.requests.filter(r=>r.path.startsWith('https:'));assert.equal(external.length,2); - for(const r of external)assert.ok(!JSON.stringify(r).includes('secret-probe')); + for(const r of external){ + assert.ok(!JSON.stringify(r).includes('secret-probe')); + assert.equal(r.options.mode,'no-cors'); + assert.equal(r.options.redirect,'follow'); + assert.equal(r.options.credentials,'omit'); + } assert.match(p.elements.get('freeAccessProbe').textContent,externalAvailable?/alcançou/:/não foi possível confirmar/); } });