Courseiva
Web Application and Injection AttackseasyMultiple ChoiceObjective-mapped

CEH Web Application and Injection Attacks Practice Question

Which of the following is the BEST defense against Cross-Site Request Forgery (CSRF) attacks?

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

CSRF tokens

CSRF tokens are unique, unpredictable tokens that validate that requests originate from the legitimate site, effectively mitigating CSRF.

Answer analysis

Option-by-option breakdown

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

  • SameSite cookies

    Why it's wrong here

    SameSite cookies mitigate CSRF by restricting when browsers send cookies with cross-site requests. When set to 'Lax' or 'Strict', they prevent cookies from being sent with requests initiated from a different site, which can block many CSRF attacks. However, they are not the best defense because certain attack vectors, such as GET requests that perform state-changing operations or specific browser behaviors, can still bypass their protection, making them less robust than CSRF tokens.

  • Input validation

    Why it's wrong here

    Input validation is a security measure that ensures data submitted by a user conforms to expected formats, types, and ranges before processing. It is primarily effective against injection attacks like SQL injection or command injection, where malicious input attempts to alter database queries or system commands. However, input validation does not prevent CSRF because CSRF exploits the browser's automatic inclusion of legitimate user credentials (cookies) with a forged request, not the malicious content of the input itself.

  • Output encoding

    Why it's wrong here

    Output encoding, also known as HTML entity encoding, transforms potentially malicious characters in user-supplied data into their harmless entity equivalents before rendering them in a web page. This process is crucial for preventing Cross-Site Scripting (XSS) attacks, as it stops injected scripts from executing in the user's browser. However, output encoding offers no defense against CSRF, which manipulates a user's browser into sending an authenticated request to a vulnerable application, regardless of the content being displayed.

  • CSRF tokens

    Why this is correct

    CSRF tokens are unique, unpredictable, and secret values generated by the server and embedded into forms or URLs for state-changing operations. When a user submits a request, the server verifies that the token included in the request matches the one stored in the user's session. This mechanism effectively prevents CSRF attacks because an attacker cannot forge a valid request without knowing the user's unique, session-specific token, which is not accessible to them.

About these practice questions

Courseiva writes every CEH question from scratch — 870 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 CEH practice question is part of Courseiva's free EC-Council 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 CEH exam.