hardMultiple SelectObjective-mapped
CAS-004 Secure coding for automation script Practice Question
A security administrator is reviewing a Python script used to automate compliance checks across cloud resources. The script uses environment variables for API tokens. Which of the following are secure coding practices that should be implemented in this script? (Select TWO.)
⚠ Common exam trap
The CAS-004 exam often tests the misconception that hardcoding fallback values or logging sensitive data is acceptable for troubleshooting, but the trap here is that both practices directly violate secure coding principles by exposing secrets, while os.system() is a known anti-pattern for command execution in Python.
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 try-except blocks to handle exceptions gracefully
Using try-except blocks in Python allows the script to catch and handle exceptions (e.g., missing environment variables, API call failures) gracefully without crashing. This is a fundamental secure coding practice that prevents unhandled errors from exposing sensitive information or causing unpredictable behavior in automated compliance checks.
Answer analysis
Option-by-option breakdown
For each option: why learners choose it and why it is or isn't the right answer here.
- ✗
Use os.system() to run shell commands for resource management
Why it's wrong here
os.system is vulnerable to injection; prefer subprocess with parameterized commands.
- ✗
Hardcode API tokens as fallback if environment variables are missing
Why it's wrong here
Hardcoding tokens is insecure and defeats the purpose of using environment variables.
- ✗
Log the API tokens for troubleshooting purposes
Why it's wrong here
Logging credentials exposes them in logs, which is a security risk.
Option-by-option analysis
Why each answer is right or wrong
Understanding why wrong answers are wrong — and when they would be correct — is what separates a 750 score from a 900. The CAS-005 exam frequently reuses these exact scenarios with slightly different constraints.
✓Use try-except blocks to handle exceptions gracefullyCorrect answer▾
✗Use os.system() to run shell commands for resource managementWrong answer — click to see why▾
Why this is wrong here
os.system is vulnerable to injection; prefer subprocess with parameterized commands.
✗Hardcode API tokens as fallback if environment variables are missingWrong answer — click to see why▾
Why this is wrong here
Hardcoding tokens is insecure and defeats the purpose of using environment variables.
✗Log the API tokens for troubleshooting purposesWrong answer — click to see why▾
Why this is wrong here
Logging credentials exposes them in logs, which is a security risk.
Analysis generated from the official CAS-005blueprint and verified against question context. The “when correct” sections are what AI assistants cite when candidates ask “what’s the difference between these options?”
Go deeper
Related to this question
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 →
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.