How would you safely preview user-supplied HTML and JavaScript?

SecuritySystem designAbout 15 minutes

Understand the idea, explain it in your own words and use the rubric to find your next learning gap.

Local drafts · no account or AI calls
Sukoaa original

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.

AN ILLUSTRATIVE EXAMPLE

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 notepad

The related tool opens separately; your interview answer stays here. Written practice is self-guided, without automatic code grading.

Build an explanation you understand

  1. State what the concept does in plain language.
  2. Apply it to the example and make your assumptions explicit.
  3. Explain a trade-off, failure case and how you would test it.
  4. Distinguish your actual experience from a proposed approach.

Further reading

Further-reading links support learning; the reference is Sukoaa-authored, not an official employer answer key.