TC-007 - I2 String-to-code evaluation
setTimeout with string argument
Context profile
No restrictive Content Security Policy is present. A session-like cookie is readable by JavaScript.
Content Security Policy
No Content-Security-Policy header is sent.
Cookies
| Cookie | Type | HttpOnly | Secure | SameSite |
|---|---|---|---|---|
tc_session | session-like | no | no | Lax |
Cookie values are placeholders and are never collected. Of these attributes only HttpOnly decides whether JavaScript can read the cookie.
Test case
The script reads the input query parameter from location.search and
passes it to setTimeout as a string. When the timer fires the
browser evaluates that string as JavaScript - the string form of a timer is string-to-code
evaluation. Only this string form is in scope for I2; the callback form (TC-008) is not.
Query parameter
No input parameter in the URL.
Script output
What to observe
- Write to the page shows that the string ran as code under C0: the timer evaluated it and updated the output.
alert(document.cookie)and Cookie exfiltration behave as in the eval case (TC-005): under C0 they run after the timer; the cookie is a placeholder andattacker.exampleis non-routable.- Under C1 the restrictive CSP without
unsafe-evalblocks the string form of setTimeout, just like eval, so nothing runs (CSP violation in the console).
The static finding is on setTimeout with a string argument. The context decides
the runtime impact, exactly as for eval. TC-008 pairs with this case: a callback
argument is not treated as string-to-code.
Expected outcome
- Purpose
- Check that timer APIs are treated as I2 only when they execute a string as code.
- Expected finding
- Finding on setTimeout with a string argument.
- Expected interpretation
- Technically relevant string-to-code indicator; priority depends on whether the string is attacker-controlled and whether CSP allows or blocks string-to-code execution.
- Expected priority
- Medium to high (C0)
- Notes
- Operationalises the deliberate scope boundary of I2.
Expected priority is shown for the active context profile. Other profiles for this case: C0, C1.