Courseiva
easyMultiple ChoiceObjective-mapped

CAS-004 Practice Question: A developer is implementing input validation for…

A developer is implementing input validation for a web application that accepts file uploads. Which of the following is the most secure method to prevent path traversal attacks?

⚠ Common exam trap

The exam often tests the misconception that input sanitization (like removing '../') is sufficient, but the trap here is that blacklist-based filtering is inherently bypassable, whereas storing files outside the web root is a secure architectural control that eliminates the attack surface entirely.

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

Storing files outside the web root directory

Storing uploaded files outside the web root directory (e.g., in a non-public directory like /var/uploads) prevents the attacker from directly accessing or executing files via URL manipulation, even if the filename contains path traversal sequences. This architectural control decouples file storage from the web server's document root, making path traversal attacks ineffective since the web server cannot serve files from outside its configured root.

Answer analysis

Option-by-option breakdown

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

  • Using a whitelist of allowed file extensions

    Why it's wrong here

    Whitelisting extensions only controls file type, not directory traversal.

  • Sanitizing the filename by removing '../' sequences

    Why it's wrong here

    Sanitization can be bypassed using encoding like URL encoding or double dots.

  • Storing files outside the web root directory

    Why this is correct

    Storing files outside web root ensures they cannot be accessed directly via path traversal even if validation fails.

  • Validating the file size before storage

    Why it's wrong here

    File size validation does not prevent path traversal.

About these practice questions

One of 968 original CAS-005 practice questions on Courseiva, each with a full explanation and wrong-answer analysis — not exam dumps or protected exam content. 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 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.