• Wrong document? Swap it for free
  • Written by students who passed
  • Immediately available after payment
  • Read online or as PDF
Sell
Where do you study
Your language
Document preview thumbnail
Preview 4 out of 40 pages
Exam (elaborations)

WGU D385 ZHN1 Task 2 – Software Security and Testing | Secure Coding, API Security Implementation, Python Vulnerability Remediation & Pytest Solutions | 2026/2027 Updated

Document preview thumbnail
Preview 4 out of 40 pages

WGU D385 ZHN1 Task 2 – Software Security and Testing | Secure Coding, API Security Implementation, Python Vulnerability Remediation & Pytest Solutions | 2026/2027 Updated

Content preview

WGU D385 ZHN1 Task 2 – Software Security and Testing | Secure
Coding, API Security Implementation, Python Vulnerability Remediation
& Pytest Solutions | 2026/2027 Updated 100 QUESTIONS
Actual Q&A – A+ Guarantee Format | WGU D385 Task 2 Secure Coding & API Security




1. A Flask endpoint accepts age = request.args.get('age') and later uses int(age)
without validation. What secure coding principle is violated and what is the fix?
A) Input validation; validate that age is digit and in range 0-120 before
conversion, return 400 if invalid
B) Least privilege; run app as root
C) Security by obscurity; hide endpoint URL
D) No validation needed because int() will handle it

Answer: A
<b>Rationale:</b> Option A is correct because all external input must be
validated for type, range, and format before use; int() on non-numeric raises
ValueError and on large values may cause logic errors, and unvalidated input
leads to injection. Option B is wrong because running as root increases
privilege, not a fix for input validation. Option C is wrong because obscurity
does not fix validation. Option D is wrong because int() alone does not
prevent crashes or logic abuse and raises unhandled exceptions.

2. A developer stores AWS credentials in config.py committed to Git. Which
secure coding practice prevents this?
A) Use environment variables or secret manager and add config.py to .gitignore,
scan repo with git-secrets
B) Commit credentials but make repo private
C) Base64 encode credentials in code
D) Share credentials via email instead

Answer: A
<b>Rationale:</b> Option A is correct because secrets must never be in
version control; env vars or secret managers allow rotation and restrict
access, and git-secrets prevents accidental commits. Option B is wrong
because private repos can still be breached or shared. Option C is wrong
because Base64 is reversible encoding not security. Option D is wrong

,because email is insecure channel and still leaves secret in code history.

3. Why should Python code avoid using os.system(user_input) and what is the
secure alternative?
A) os.system invokes shell and allows command injection; use subprocess.run
with shell=False and argument list with validation
B) os.system is faster so should be used
C) os.system prevents injection by default
D) Use eval() instead

Answer: A
<b>Rationale:</b> Option A is correct because os.system passes input to
shell, attacker can inject ; rm -rf /; subprocess with shell=False avoids shell
interpretation. Option B is wrong because speed does not justify injection
risk. Option C is wrong because os.system does not prevent injection. Option
D is wrong because eval is also remote code execution vulnerability.

4. A function builds a file path via open('/data/' + filename) where filename
comes from user. What vulnerability and fix?
A) Path traversal; use os.path.basename, validate against allowlist, and use
os.path.join with realpath check that resolved path starts with allowed base
directory
B) SQL injection; use parameterized queries
C) XSS; use html.escape
D) No vulnerability, concatenation is safe

Answer: A
<b>Rationale:</b> Option A is correct because ../../etc/passwd can escape
intended directory; basename and realpath containment prevents traversal.
Option B is wrong because this is filesystem not SQL. Option C is wrong
because XSS is for HTML output. Option D is wrong because concatenation
of user input into path is unsafe.

5. What does principle of least privilege mean for a Python API service
connecting to database?
A) Service account should have only SELECT, INSERT on needed tables, not
DROP or admin rights
B) Service should run as root with full DB admin

, C) All users should share same admin password
D) Least privilege means no authentication needed

Answer: A
<b>Rationale:</b> Option A is correct because limiting DB permissions
reduces blast radius if service is compromised. Option B is wrong because
root/admin violates least privilege. Option C is wrong because shared admin
password violates accountability. Option D is wrong because authentication
is still required.

6. A developer disables TLS certificate verification via requests.get(url,
verify=False) to fix development error. Why is this insecure for production?
A) Disables protection against man-in-the-middle attacks, allowing attacker to
intercept or modify data
B) It makes requests faster and is recommended
C) It only affects logging
D) It prevents SQL injection

Answer: A
<b>Rationale:</b> Option A is correct because verify=False skips certificate
chain validation, enabling MITM. Option B is wrong because speed gain is
insecure and not recommended. Option C is wrong because it affects TLS,
not logging. Option D is wrong because TLS verification does not relate to
SQL injection.

7. Which Python library should be used for generating cryptographically secure
random tokens for password reset links?
A) secrets module, e.g., secrets.token_urlsafe(32)
B) random module with random.randint()
C) Use current timestamp as token
D) Use hashlib.md5 with username

Answer: A
<b>Rationale:</b> Option A is correct because secrets uses OS CSPRNG
suitable for security tokens. Option B is wrong because random is predictable
Mersenne Twister not for security. Option C is wrong because timestamps
are guessable. Option D is wrong because MD5 is broken and deterministic.

, 8. What is defense in depth for a Python web app handling file uploads?
A) Multiple layers: validate extension and MIME type, check magic bytes, limit
size, store outside web root, scan with antivirus, randomize filename
B) Only check file extension
C) Only rely on client-side validation
D) Allow any file type to simplify code

Answer: A
<b>Rationale:</b> Option A is correct because layered controls prevent
bypass; extension alone can be spoofed, MIME can be spoofed, so magic
bytes and storage location and scanning provide defense. Option B is wrong
because extension check alone is easily bypassed. Option C is wrong
because client-side validation can be disabled. Option D is wrong because
allowing any type enables RCE via .py or .php upload.

9. A code review finds except Exception as e: print(e) and continues processing
payment. Why is this insecure?
A) Suppressing exception and continuing may process payment in inconsistent
state, hiding fraud or failure, should log, rollback transaction, and fail securely
B) Printing exception is always secure
C) Exceptions should never be logged
D) Payment should continue regardless of error

Answer: A
<b>Rationale:</b> Option A is correct because silent continuation violates
fail-secure principle; payment processing must be atomic and logged
securely. Option B is wrong because print may leak to stdout without
protection. Option C is wrong because exceptions should be logged securely
server-side. Option D is wrong because continuing on error can cause double
charging or data corruption.

10. Why should hardcoded encryption keys like AES_KEY =
b'1234567890123456' be avoided?
A) Key in source code can be extracted from repo or binary, cannot be rotated,
violates key management; use KMS or env var
B) Hardcoded keys are more secure because visible
C) Key length 16 is always secure regardless of storage

Document information

Uploaded on
November 2, 2026
Number of pages
40
Written in
2026/2027
Type
Exam (elaborations)
Contains
Questions & answers
$18.89

Wrong document? Swap it for free Within 14 days of purchase and before downloading, you can choose a different document. You can simply spend the amount again.
Written by students who passed
Immediately available after payment
Read online or as PDF

Seller avatar
Reputation scores are based on the amount of documents a seller has sold for a fee and the reviews they have received for those documents. There are three levels: Bronze, Silver and Gold. The better the reputation, the more your can rely on the quality of the sellers work.
GradeAchiver
3.5
(11)
Sold
68
Followers
3
Items
7841
Last sold
2 days ago



Why students choose Stuvia

Created by fellow students, verified by reviews

Quality you can trust: written by students who passed their tests and reviewed by others who've used these notes.

Didn't get what you expected? Choose another document

No worries! You can instantly pick a different document that better fits what you're looking for.

Pay as you like, start learning right away

No subscription, no commitments. Pay the way you're used to via credit card and download your PDF document instantly.

Student with book image

“Bought, downloaded, and aced it. It really can be that simple.”

Alisha Student

Working on your references?

Create accurate citations in APA, MLA and Harvard with our free citation generator.

Working on your references?

Frequently asked questions