How would you safely preview user-supplied HTML and JavaScript?
Understand the idea, explain it in your own words and use the rubric to find your next learning gap.
The idea behind the question
A code preview is an execution boundary. Escaping strings, sanitizing HTML and isolating code solve different problems and must match the feature's needs.
A playground snippet tries to read the parent page, navigate it or transmit data to an arbitrary host.
A practical way to learn it
Threat-model a snippet that attempts parent access, navigation and an outbound request. Define a test for each.
Open online notepadThe related tool opens separately; your interview answer stays here. Written practice is self-guided, without automatic code grading.
Build an explanation you understand
- State what the concept does in plain language.
- Apply it to the example and make your assumptions explicit.
- Explain a trade-off, failure case and how you would test it.
- Distinguish your actual experience from a proposed approach.
How would you explain it?
Single-question timers reset on refresh. Full mock sessions can resume from this browser.
Strengthen your explanation
Compare reasoning, not identical wording. Reference answers describe a possible approach; replace hypothetical statements with truthful details from your own work.
One way to answer
I would choose a deliberately isolated origin or appropriately restricted sandboxed frame and verify its allowed capabilities. I would avoid combining privileges that undo isolation, restrict network and navigation where the product requires it, and validate the shape and origin of cross-window messages. Parent secrets would never be sent to the preview. I would handle infinite loops through an execution design that can be terminated where possible and enforce separate limits for remote code. I would test actual boundary escapes and never run untrusted code directly in the application's main context.
What a strong explanation should cover
Tick only the points your own answer addresses. This is self-assessment, not AI scoring.
0 / 3 points self-reportedWatch out for
- Treating HTML escaping as complete JavaScript isolation.
Now go one level deeper
- How would you let a preview call a permitted demo API?
- What can and cannot be stopped inside an iframe?
Further reading
Further-reading links support learning; the reference is Sukoaa-authored, not an official employer answer key.