Courseiva

CCSP Cloud Application Security Practice Question

Which of the following is the best way to protect a web application from cross-site scripting (XSS) attacks?

⚠ Common exam trap

ISC2 often tests the misconception that a single security control (like output encoding or CSP alone) is sufficient, when the correct answer always requires a defense-in-depth combination of input validation, output encoding, and CSP.

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

✓

Use a combination of input validation, output encoding, and Content Security Policy.

Cross-site scripting (XSS) attacks exploit multiple vectors, and no single defense is sufficient. Input validation prevents malicious payloads from being stored or processed, output encoding ensures that any residual dangerous characters are rendered inert in the HTML context, and Content Security Policy (CSP) provides a robust, browser-enforced layer that can block inline scripts and restrict script sources even if other defenses fail. This defense-in-depth approach aligns with the OWASP XSS prevention cheat sheet and is the recommended strategy for cloud-hosted web applications.

Answer analysis

Option-by-option breakdown

For each option: why learners choose it and why it is or isn't the right answer here.

  • ✗

    Encode all output that is rendered in HTML.

    Why it's wrong here

    Output encoding neutralises injected markup at the point of rendering, but it fails when data reaches dangerous sinks such as JavaScript contexts, DOM APIs, or unquoted attributes where HTML-entity encoding is ineffective. It is the right control for reflected and stored XSS in HTML body context, yet it cannot alone address DOM-based XSS or context-specific injection.

  • ✗

    Implement a Content Security Policy (CSP) as the sole defense.

    Why it's wrong here

    A CSP restricts which scripts may execute, mitigating injection impact, but as the sole defence it leaves stored and reflected payloads intact in the response and does not sanitise data before it reaches the DOM. CSP is the correct primary control when browsers must be constrained against third-party script abuse, not as a replacement for output encoding.

  • ✓

    Use a combination of input validation, output encoding, and Content Security Policy.

    Why this is correct

    XSS arises from untrusted data reaching the browser as markup, so layered defences are needed: validation rejects malformed input, output encoding neutralises injected script, and Content Security Policy restricts what executes. No single control covers stored, reflected and DOM-based variants, satisfying the best-practice requirement.

  • ✗

    Validate all user input on the server side.

    Why it's wrong here

    Server-side input validation blocks malformed data entering the application, but XSS payloads are often syntactically valid strings that only become dangerous when rendered; validation cannot anticipate every output context. It is the right control for enforcing data type, length, and format at trust boundaries, not for neutralising markup at render time.

About these practice questions

Courseiva writes every CCSP question from scratch — 934 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 →

How Courseiva writes practice questions · Editorial policy

JA

Written by Johnson Ajibi, MSc IT Security

Senior Network & Security Engineer · founder of Courseiva

This CCSP practice question is part of Courseiva's free ISC2 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 CCSP exam.