T09 · Insecure Skill Coding Practices
- Location
SKILL.md:104- Finding
<![CDATA[Unescaped Values Are Interpolated into Browser-Executed JavaScript]]>
- Content
View full analysis
{ // 1. Fill in CAPTCHA const el=document.getElementById('w_code'); el.removeAttribute('onkeyup'); el.removeAttribute('onpaste'); el.removeAttribute('oncontextmenu'); el.value='{captcha}'; el.dispatchEvent(new Event('input',{bubbles:true})); // 2. Validate value const w=el.value; if(!w){return JSON.stringify({error:'CAPTCHA is empty; refresh the page and retry'});} // 3. Fill in phone number const s=Object.getOwnPropertyDescriptor(window.HTMLInputElement.prototype,'value').set; const el2=document.getElementById('phone'); s.call(el2,'{phone}'); el2.dispatchEvent(new Event('input',{bubbles:true})); el2.blur(); // 4. Trigger SMS document.getElementById('hq2').click(); return JSON.stringify({ w:document.getElementById('w_code').value, p:document.getElementById('phone').value, t:document.getElementById('Time')?.textContent?.trim() }); } ``` Additional vulnerable substitutions include: ```javascript s.call(pc,'{sms_code}'); s.call(sp,'{report_phone}'); ``` ```javascript document.getElementById('d241').value='{YYYY-MM-DD}'; document.getElementById('d242').value='{HH:mm}'; document.getElementById('d243').value='{long_time}'; ``` ```javascript ts.call(sc,'{来电描述}'); ``` ### Technical Analysis The Skill constructs browser-evaluation scripts by inserting CAPTCHA, phone, SMS code, reported number, date, time, enum, and free-text description values directly into single-quoted JavaScript string literals. It does not escape quotation marks, backslashes, line terminators, or other JavaScript syntax. Several values originate directly from user messages. In particular, the free-text call description can naturally contain arbitrary punctuation. If an attacker-controlled value contains a quote followed by JavaScript sy ...[truncated 1380 chars]- Remediation
View remediation
{ const captchaElement = document.getElementById('w_code'); captchaElement.value = captcha; captchaElement.dispatchEvent(new Event('input', { bubbles: true })); const setter = Object.getOwnPropertyDescriptor(HTMLInputElement.prototype, 'value').set; const phoneElement = document.getElementById('phone'); setter.call(phoneElement, phone); phoneElement.dispatchEvent(new Event('input', { bubbles: true })); } ``` - If structured arguments are unavailable, encode every substituted value with `JSON.stringify` and insert the resulting JSON literal without surrounding it with manually written quotes. - Apply strict allowlists before evaluation: - CAPTCHA and SMS code: expected character set and exact length. - Phone numbers: only formats accepted by the service. - Date and time: validated calendar and time formats. - Enum fields: exact predefined values. - Description: bounded length and normalized text. - Add tests containing quotes, backslashes, newlines, Unicode separators, and JavaScript-like payloads to verify that values remain data rather than executable source. ]]>
