mediumMultiple ChoiceObjective-mapped
CAS-004 Practice Question: A security architect is designing a secure coding…
A security architect is designing a secure coding standard for a web application. Which of the following should be prioritized to mitigate cross-site scripting (XSS) risks?
⚠ Common exam trap
CompTIA often tests the misconception that input validation is the best defense against XSS, when in fact output encoding is the definitive control because it addresses the root cause — untrusted data being interpreted as code — regardless of input filtering.
Answer choices
Why each option matters
Answer the question above first, then reveal the full breakdown to understand why each option is right or wrong.
Correct answer & explanation
✓
Output encoding
Output encoding is the primary defense against cross-site scripting (XSS) because it neutralizes injected scripts by converting special characters (e.g., <, >, &, ") into their HTML entity equivalents (e.g., < > & ") before the data is rendered in the browser. This ensures that user-supplied data is treated as text, not executable code, regardless of how it entered the application. Input validation alone is insufficient because it can be bypassed via alternate encodings or allowed characters that are still dangerous in certain contexts.
Answer analysis
Option-by-option breakdown
For each option: why learners choose it and why it is or isn't the right answer here.
- ✗
Input validation
Why it's wrong here
Input validation can reduce XSS but is less effective than output encoding because it can be bypassed or incomplete.
- ✓
Output encoding
Why this is correct
Output encoding converts special characters to HTML entities, preventing script execution in the browser.
- ✗
Secure cookies
Why it's wrong here
Secure cookies protect against session hijacking, not XSS injection.
- ✗
Parameterized queries
Why it's wrong here
Parameterized queries prevent SQL injection, not XSS.
Go deeper
Related to this question
About these practice questions
Courseiva writes every CAS-005 question from scratch — 968 in total, each with an explanation and a wrong-answer breakdown. None are copied from real exams or dumps. Learn why practice questions differ from exam dumps →
JA
Written by Johnson Ajibi, MSc IT Security
Senior Network & Security Engineer · founder of Courseiva
This CAS-005 practice question is part of Courseiva's free CompTIA certification practice question bank. Courseiva provides original exam-style practice questions with explanations, topic-based practice, mock exams, readiness tracking, and study analytics to help learners prepare for the CAS-005 exam.