@davoodmehraban89 / Factor-easy / commits / 99b0b54
Fork 0

سامانه صدور فاکتور و حسابداری

Harden integration endpoint validation

davoodmehraban89 committed Sep 29, 2026 at 22:31 UTC 99b0b549c0bdc25ed4479559041b67525f9144a3
1 file changed +4 -1
js/phase5-enterprise.js
+4 -1
@@ -96,8 +96,11 @@ function p5ApplyRestore(){
96 const p=window.p5PendingRestore;if(!p||!currentUser||!requireWrite())return;if(!confirm('فایل اعتبارسنجی شده با داده‌های حساب شما ادغام شود؟ سابقه قطعی موجود بازنویسی نمی‌شود.'))return;
97 try{const n=absorbRecords(p);datastore.importBatches.push({id:p5Id('IMP'),ownerUserId:currentUser.id,companyId:afCompanyId(),fileName:'validated-backup.json',mode:'merge',counts:{records:n},status:'applied',createdAt:new Date().toISOString()});p5Audit('restore','backup','merge',null,{records:n});saveDatastore();window.p5PendingRestore=null;refreshAllSurfaces();alert(n.toLocaleString('fa-IR')+' رکورد با موفقیت ادغام شد.')}catch(e){alert('بازگردانی انجام نشد: '+e.message)}
98 }
99 +function p5ValidateIntegrationEndpoint(raw){
100 + const value=String(raw||'').trim();if(!value)return '';let u;try{u=new URL(value)}catch(_){throw new Error('نشانی اتصال معتبر نیست.')}if(u.protocol!=='https:')throw new Error('نشانی اتصال باید HTTPS باشد.');if(u.username||u.password)throw new Error('قرار دادن نام کاربری/رمز در URL اتصال مجاز نیست.');const h=u.hostname.toLowerCase(),privateHost=h==='localhost'||h==='::1'||h.endsWith('.local')||/^127\./.test(h)||/^10\./.test(h)||/^192\.168\./.test(h)||/^169\.254\./.test(h)||/^172\.(1[6-9]|2\d|3[01])\./.test(h);if(privateHost)throw new Error('Endpoint شبکه خصوصی/محلی برای اتصال خارجی مجاز نیست.');return u.href;
101 +}
102 function p5SaveIntegration(){
100 - const cid=p5Need();if(!cid)return;const name=document.getElementById('p5-int-name').value.trim(),kind=document.getElementById('p5-int-kind').value,endpoint=document.getElementById('p5-int-endpoint').value.trim();if(!name)return alert('نام اتصال الزامی است.');if(endpoint&&!/^https:\/\//i.test(endpoint))return alert('نشانی اتصال باید HTTPS باشد.');const r={id:p5Id('INT'),ownerUserId:currentUser.id,companyId:cid,name,kind,endpoint,active:true,secretStored:false,createdAt:new Date().toISOString()};datastore.integrationConnections.push(r);p5Audit('create','integrationConnection',r.id,null,r);saveDatastore();p5RenderIntegrations();
103 + const cid=p5Need();if(!cid)return;const name=document.getElementById('p5-int-name').value.trim(),kind=document.getElementById('p5-int-kind').value;let endpoint='';try{endpoint=p5ValidateIntegrationEndpoint(document.getElementById('p5-int-endpoint').value)}catch(e){return alert(e.message)}if(!name)return alert('نام اتصال الزامی است.');const r={id:p5Id('INT'),ownerUserId:currentUser.id,companyId:cid,name,kind,endpoint,active:true,secretStored:false,createdAt:new Date().toISOString()};datastore.integrationConnections.push(r);p5Audit('create','integrationConnection',r.id,null,r);saveDatastore();p5RenderIntegrations();
104 }
105 function p5QueueEvent(connectionId,eventType){
106 const cid=p5Need(),c=getMyIntegrationConnections().find(x=>x.id===connectionId);if(!cid||!c)return;const r={id:p5Id('OUT'),ownerUserId:currentUser.id,companyId:cid,connectionId,eventType,payload:{companyId:cid,generatedAt:new Date().toISOString()},status:'pending',attempts:0,createdAt:new Date().toISOString()};datastore.integrationOutbox.push(r);p5Audit('queue','integrationOutbox',r.id,null,r);saveDatastore();p5RenderIntegrations();