diff --git a/backend/routes/clickTtHttpPageRoutes.js b/backend/routes/clickTtHttpPageRoutes.js index 62dd0b3d..73e84be1 100644 --- a/backend/routes/clickTtHttpPageRoutes.js +++ b/backend/routes/clickTtHttpPageRoutes.js @@ -98,21 +98,25 @@ function summarizeFormBody(body) { function summarizeInlineConfirmElements(html) { if (!html || typeof html !== 'string') return []; const matches = []; - const regex = /<(a|button|input|form)\b([^>]*?\bonclick\s*=\s*["'][^"']*confirm\([^"']*["'][^>]*?)>/gi; + const elementRegex = /<(a|button|input|form)\b([^>]*)>/gi; let match; - while ((match = regex.exec(html)) !== null && matches.length < 10) { + while ((match = elementRegex.exec(html)) !== null && matches.length < 10) { const tag = match[1]; const attrs = match[2] || ''; - const onclickMatch = attrs.match(/\bonclick\s*=\s*["']([^"']*confirm\([^"']*)["']/i); - const valueMatch = attrs.match(/\bvalue\s*=\s*["']([^"']*)["']/i); - const hrefMatch = attrs.match(/\bhref\s*=\s*["']([^"']*)["']/i); - const nameMatch = attrs.match(/\bname\s*=\s*["']([^"']*)["']/i); + const onclickMatch = attrs.match(/\bonclick\s*=\s*(["'])([\s\S]*?)\1/i); + const onclick = onclickMatch?.[2] || null; + if (!onclick || !/confirm\s*\(/i.test(onclick)) { + continue; + } + const valueMatch = attrs.match(/\bvalue\s*=\s*(["'])([\s\S]*?)\1/i); + const hrefMatch = attrs.match(/\bhref\s*=\s*(["'])([\s\S]*?)\1/i); + const nameMatch = attrs.match(/\bname\s*=\s*(["'])([\s\S]*?)\1/i); matches.push({ tag, - name: nameMatch?.[1] || null, - value: valueMatch?.[1] || null, - href: hrefMatch?.[1] || null, - onclick: onclickMatch?.[1] || null + name: nameMatch?.[2] || null, + value: valueMatch?.[2] || null, + href: hrefMatch?.[2] || null, + onclick }); } return matches; @@ -342,10 +346,11 @@ function injectProxyNavigationScript(html, proxyBaseUrl, pageBaseUrl, sid) { 'function shouldAllowInlineConfirm(element){', "var onclickValue=element&&element.getAttribute?element.getAttribute('onclick'):null;", 'if(!onclickValue)return true;', - "var match=onclickValue.match(/return\\s+confirm\\((['\"])([\\s\\S]*?)\\1\\)/i);", + "var match=onclickValue.match(/confirm\\((['\"])([\\s\\S]*?)\\1\\)/i);", + "try{console.log('[ClickTT Proxy] inline confirm inspect',{onclick:onclickValue,matched:!!match});}catch(e){}", 'if(!match)return true;', 'var confirmed=window.confirm(match[2]);', - "try{console.log('[ClickTT Proxy] inline confirm',{message:match[2],confirmed:confirmed});}catch(e){}", + "try{console.log('[ClickTT Proxy] inline confirm',{message:match[2],confirmed:confirmed,onclick:onclickValue});}catch(e){}", 'return confirmed;', '}', 'function logInlineConfirmElements(){', @@ -360,7 +365,7 @@ function injectProxyNavigationScript(html, proxyBaseUrl, pageBaseUrl, sid) { "text:(el.textContent||'').trim().slice(0,120)", '};', '});', - "console.log('[ClickTT Proxy] inline confirm elements',elements);", + "console.log('[ClickTT Proxy] inline confirm elements json',JSON.stringify(elements));", '}catch(e){}', '}', 'function getSubmitTarget(form, submitter){',