Courseiva
Web Application and Injection AttackseasyMultiple ChoiceObjective-mapped

CEH Web Application and Injection Attacks Practice Question

Which of the following is the primary purpose of using a CSRF token in a web application?

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

Prevent cross-site request forgery

CSRF tokens are unique, unpredictable values embedded in forms or requests that validate the request originated from the legitimate application, preventing cross-site request forgery attacks.

Answer analysis

Option-by-option breakdown

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

  • Prevent cross-site request forgery

    Why this is correct

    Cross-Site Request Forgery (CSRF) attacks trick authenticated users into submitting unintended requests to a web application, leveraging their existing session. CSRF tokens are unique, unpredictable, and secret values generated by the server and embedded within forms or request headers. Upon submission, the server validates the token, ensuring the request originated from the legitimate application and user, thereby preventing an attacker's forged request from being processed.

  • Prevent session hijacking

    Why it's wrong here

    Session hijacking involves an attacker gaining unauthorized access to a user's active session, typically by stealing or predicting their session ID. While CSRF tokens protect against forged requests *within* an active session, they do not prevent the initial compromise of the session itself. Robust session hijacking prevention relies on secure cookie attributes (HttpOnly, Secure, SameSite), strong session ID generation, regular session regeneration, and mandatory use of HTTPS to encrypt all communication and protect session tokens in transit.

  • Prevent XSS

    Why it's wrong here

    Cross-Site Scripting (XSS) attacks involve injecting malicious scripts into web pages viewed by other users, typically exploiting vulnerabilities in input validation or output encoding. CSRF tokens, designed to validate the authenticity of a request's origin, do not mitigate XSS. Effective XSS prevention relies on strict input sanitization, context-aware output encoding of all user-supplied data, and Content Security Policy (CSP) headers to restrict script execution.

  • Prevent SQL injection

    Why it's wrong here

    SQL injection attacks exploit vulnerabilities in an application's database queries, allowing attackers to inject malicious SQL code to manipulate or extract data. CSRF tokens operate at the application layer to verify user intent for state-changing requests and have no direct mechanism to prevent the manipulation of database queries. The primary defense against SQL injection is the use of parameterized queries or prepared statements, which separate SQL code from user-supplied data, preventing malicious input from being interpreted as executable commands.

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.