A web application stores user comments and shows them to other users, and stored scripts now run in readers' browsers. Input is already checked for type and length. Which practice BEST addresses the root cause?
Show the answer
Correct answerB. Context-sensitive output encoding when rendering comments
AWhy not this: Encryption at rest protects stored data from disclosure, but the app decrypts and renders the script anyway.
BWhy this is right: Encoding on output makes the browser treat stored comment text as data, not executable script, which removes the cause.
CWhy not this: Rate limiting slows abuse of the endpoint but does not change how stored content is rendered.
DWhy not this: Shorter limits do not stop injection, because a short script tag still fits and runs.
The script runs because stored data is written into the page as markup. Encoding output for its HTML context makes the browser treat it as text. Length limits only restrict size, and a short script payload still runs.