SECURE CODING, SECRETS & LOGGING QUICK
REFERENCE | GITLAB CI/CD & SECURITY
CHECKLISTS
Final Exam Practice | 350 Questions with
Correct Answers & Detailed Rationales |
2026/2027
INTRODUCTION
This comprehensive practice exam is designed for students
preparing for the WGU D522 Python for IT Automation Final
Exam. The document contains 350 original practice questions
covering the core competency areas emphasized in the D522
security-focused exam blueprint: secure Python automation
against OWASP Top 10 vulnerabilities, secrets management and
,credential handling, structured logging and monitoring, GitLab
CI/CD security policies (SAST, DAST, dependency scanning), and
comprehensive security checklists for auditing automation
workflows .
Each question follows a four-option multiple-choice format
with a clearly identified correct answer and a detailed
rationale explaining why the correct choice reflects secure
coding and operational best practices, and why each distractor
represents a common but dangerous pattern. The questions
emphasize scenario-based application—diagnosing command
injection risks, configuring masked CI/CD variables,
implementing log redaction, and enforcing pipeline security
gates .
The guide is organized into seven sections: (1) Secure Python
Automation & OWASP Top 10 Mitigation; (2) Secrets
Management & Credential Handling; (3) Structured Logging,
Monitoring & Error Handling; (4) GitLab CI/CD Security Policies;
(5) Input Validation & Safe Command Execution; (6) Security
Checklists & Hardening Workflows; and (7) Integrated Scenarios
& Compliance.
SECTION 1: SECURE PYTHON AUTOMATION & OWASP TOP 10
MITIGATION
(Questions 1–60)
,Question 1
A Python automation script uses subprocess.run() with
shell=True to execute a user-supplied filename. Which
mitigation most effectively prevents command injection while
preserving functionality?
A) Validate the filename against a whitelist of allowed
characters
B) Use shlex.quote() to escape the filename before passing it to
the shell
C) Replace shell=True with a list of arguments and shell=False
D) Run the script with reduced privileges using a non-root user
Correct Answer: C
Rationale: Using shell=False with a list of arguments avoids
shell interpretation entirely, eliminating command injection.
Whitelisting (A) or quoting (B) may be bypassed by determined
attackers, and privilege reduction (D) does not prevent
injection—it only limits the damage after exploitation .
Question 2
A Python script constructs SQL queries by concatenating user
input. Which vulnerability does this introduce?
, A) Cross-site scripting (XSS)
B) SQL injection
C) Server-side request forgery (SSRF)
D) Insecure deserialization
Correct Answer: B
Rationale: Concatenating user input into SQL queries allows
attackers to inject malicious SQL, manipulating the query's
logic. Parameterized queries or prepared statements are the
correct mitigation .
Question 3
Which of the following is a primary risk of using pickle to
deserialize untrusted data in a Python automation script?
A) Pickle files are too large
B) Pickle can execute arbitrary code during deserialization
C) Pickle does not support dictionaries
D) Pickle cannot serialize strings
Correct Answer: B
Rationale: pickle deserialization can execute arbitrary code
embedded in the pickle data, making it a critical insecure
deserialization vulnerability. Untrusted data should never be
unpickled. JSON or other safe formats should be used instead .