Treasury & Bank Transfer Management System — سامانه مدیریت خزانه‌داری و حواله‌های بانکی

fix: narrow optional SQL prefix under TypeScript strict mode

davoodmehraban89 committed Oct 15, 2026 at 20:46 UTC c0e83a6735e82d4dbddab614ce74f147598831fd
1 file changed +4 -2
src/platform/integration/read-only-query.ts
+4 -2
@@ -62,8 +62,10 @@ export function prepareReadOnlySql(input:string):string {
62 for(const word of tokens)if(FORBIDDEN.has(word.toUpperCase()))
63 unsafe('FORBIDDEN_OPERATION','Disallowed SQL operation: '+word.toUpperCase());
64 if(/\b(?:xp_|sp_)\w*/i.test(masked))unsafe('PROCEDURE_FORBIDDEN','Stored procedure references are not supported');
65 - const prefix=/^SELECT\s+(?:(?:DISTINCT|ALL)\s+)?/i.exec(query)?.[0];
66 - if(!prefix||!/^SELECT\s+(?:(?:DISTINCT|ALL)\s+)?$/i.test(masked.slice(0,prefix.length)))
65 + const prefixMatch=/^SELECT\s+(?:(?:DISTINCT|ALL)\s+)?/i.exec(query);
66 + if(!prefixMatch)throw new UnsafeReadOnlySqlError('SELECT_ONLY','Unexpected SQL prefix');
67 + const prefix=prefixMatch[0];
68 + if(!/^SELECT\s+(?:(?:DISTINCT|ALL)\s+)?$/i.test(masked.slice(0,prefix.length)))
69 unsafe('SELECT_ONLY','Unexpected SQL prefix');
70 const remaining=query.slice(prefix.length);
71 const top=/^TOP\s*(?:\(\s*(\d+)\s*\)|(\d+)\b)/i.exec(remaining);