code-sink
Code run from text the source doesn't show: setTimeout(text) and setInterval(text) in a browser, an event handler attribute (setAttribute("onclick", text), or an attribute whose name isn't a constant), script.text, script.textContent and script.src, new Worker(url), new SharedWorker(url), navigator.serviceWorker.register(url), a worklet's addModule(url), import(specifier), and in Node vm.runInThisContext, runInNewContext, runInContext, compileFunction, new vm.Script, child_process.fork(module), new Worker(file) of node:worker_threads, module.register(specifier).
Why: the text runs with everything the program can do. A field that reaches one of these from a request, a message or storage runs whatever a user put there, and no check of the text makes it safe: code is the one kind with no constructor to call.
✕ Rejectedcode-sink
ts
import { Worker } from "node:worker_threads";
export function startJob(script: string): Worker {
return new Worker(script);
}✅ Accepted: the code the source shows, and the data as data
✓ Accepted0 diagnostics
ts
import { Worker } from "node:worker_threads";
export function startJob(job: string): Worker {
return new Worker(new URL("./job-worker.ts", import.meta.url), { workerData: job });
}Accepted: a constant the source shows (a literal, a const of one, a template of those), what whoever runs the program gives it, where the code shows it (process.argv, process.env, a name readdir returned, a function returning one; past that, a FromOperator), a module or worker named by a path or a URL made of constants and of where the module is (new URL("./w.ts", import.meta.url), path.join(import.meta.dirname, "w.ts"), pathToFileURL(...).href, import.meta.resolve("./w.ts")), an imported const bound to one, a number, a value of a literal type, and a function where a timer takes one (setTimeout(() => tick(), 10)).
An attribute name the source doesn't show is judged by its written type: a string may be onclick, so the value must be code the source shows; a type whose every name is no sink's (a union of literals, or template literal types whose start no sink name can follow) leaves the value alone, and "href" | "title" makes it a URL (url-sink).
❌ Rejected: any name, so possibly an event handler
✕ Rejectedcode-sink
ts
export function setAria(el: Element, name: string, value: string): void {
el.setAttribute(name, value);
}✅ Accepted: the names the type allows are aria-* and data-*
✓ Accepted0 diagnostics
ts
type DataName = `aria-${string}` | `data-${string}`;
export function setAria(el: Element, name: DataName, value: string): void {
el.setAttribute(name, value);
}eval(text), new Function(...) and Function(...) are sinks too (the language's map lists them), but oxlint's no-eval and no-new-func, which the SAFE-TS preset turns on, report every call of them in the same gate, so this rule leaves them alone. What those oxlint rules miss, and this rule reports: a string given to a timer (oxlint's no-implied-eval sees setTimeout("...") written out, not setTimeout(text)), an event handler attribute, a <script>'s text or src, a worker's or a worklet's script URL, import() of a computed specifier, and Node's vm, fork, worker_threads and module.register.
What the rule can't see: a function made some other way that runs text (a library's template compiler, (async () => {}).constructor), code fetched and run by a library, and WebAssembly modules made from bytes. The list of members is data (Libraries: Sinks).