Invental/Review lessons/Trust boundaries the server must hold

Trust boundaries the server must hold

Detached DOM nodes still fetch their src

“Detached” is not “inert”: an <img> created in the live document fetches its src immediately, so build untrusted HTML in a separate document (<template> content or DOMParser) before you set any URL.

01 · Before and afterThe pattern

TypeScript
// before: request fires here, before the node is ever attached
const img = document.createElement("img");
img.src = untrustedUrl;
template.content.append(img);
// after: create in the template's inert document
const inert = template.content.ownerDocument;
const img = inert.createElement("img");
img.setAttribute("src", untrustedUrl);   // no network request

02 · Run it on your appThe check

Does your app ever set src on an element built from someone else's HTML before sanitising it, even off-screen?

If the honest answer is no or not sure, this is worth a look before it reaches production.

Want this checked on your code?

Tell us what you are building and what worries you. We match a senior reviewer to your code and confirm scope before anything starts.

— Get in touch
hi@invental.co ↗
— Or
— What to include

A link or short description of the code or system, what you want checked, your stack, and when you need the answer. No repository access is needed until scope is agreed.

— Or leave a note
We reply within one business day.