@davoodmehraban89 / VELYQOR / commits / ea4c1eb
Fork 0

Intelligence, Advanced Charting & Trading Platform

security(bale): verify recipient chat is private via getChat before any owner-only test send

davoodmehraban89 committed Oct 15, 2026 at 20:32 UTC ea4c1ebbbbd461f86735c635202bf826b17e8b55
1 file changed +7 -1
scripts/diagnostics/bale-one-message-test.mjs
+7 -1
@@ -29,7 +29,7 @@ export function safeSummary(result,httpStatus,expectedChat){
29 return {status:'Bale_API_ACCEPTED_NOT_READ_CONFIRMED',httpStatus,messageId:msg};
30 }
31 export async function postMethod(method,body,{token,transport=fetch}){
32 - if(!tokenOK(token)||!['getUpdates','sendMessage'].includes(method))
32 + if(!tokenOK(token)||!['getUpdates','getChat','sendMessage'].includes(method))
33 throw Error('Invalid Bale request inputs');
34 const response=await transport(HOST+'/bot'+token+'/'+method,{
35 method:'POST',
@@ -72,6 +72,12 @@ export async function singleTest({mode='--dry-run',env=process.env,transport=fet
72 throw Error('Explicit BALE_TEST_CONSENT required');
73 const chatId=env.BALE_CHAT_ID;
74 if(!chatOK(chatId))throw Error('BALE_CHAT_ID missing or malformed');
75 + // Never send to a group/channel even if supplied ID is a positive integer.
76 + const preflight=await postMethod('getChat',{chat_id:chatId},{token,transport});
77 + if(preflight.status!==200||preflight.data?.ok!==true||
78 + preflight.data?.result?.type!=='private'||
79 + String(preflight.data?.result?.id)!==chatId)
80 + return {status:'FAILED',reason:'private_chat_preflight_failed_redacted'};
81 const text='[ChartNova] پیام آزمایشی کانال بله. این یک آزمون ارتباطی است؛ هشدار قیمت یا توصیه مالی نیست.';
82 const r=await postMethod('sendMessage',{chat_id:chatId,text},{token,transport});
83 return safeSummary(r.data,r.status,chatId);