
































Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
This page cannot be seen from the preview
Don't miss anything!

































EXAM INFORMATION
Subject: Software Security & Testing Questions: 50 | Format: Multiple choice Duration: 3 hours Passing score: 95%
ABOUT THIS EXAM
This exam assesses advanced understanding of static analysis, Python logging, assertions, exception handling, and remediation strategies as covered in the WGU D385 Task 1 curriculum. It emphasizes practical application, secure coding principles, and integration of security testing into the software development lifecycle.
WHAT THIS COVERS
Detailed Explanations
Q A security engineer runs Bandit on a Python module and receives a B608 warning for a SQL query constructed with string concatenation. Which remediation most effectively eliminates the vulnerability while preserving functionality?
A (^) Replace concatenation with an f-string using input validation.
B (^) Use parameterized queries with a database driver that supports placeholders.
CORRECT
C (^) Escape all single quotes in the user input before concatenation.
D (^) Apply a web application firewall (WAF) rule to block SQL injection patterns.
EXPLANATION Parameterized queries separate SQL logic from data, preventing injection regardless of input content. Escaping quotes or using f-strings with validation can be bypassed and do not address the root cause. A WAF is a defense-in-depth measure, not a remediation.
Detailed Explanations
Q Consider the following Python code snippet:
assert user.is_authenticated, "User not authenticated"Which statement accurately describes a security implication of using this assertion for access control?
A Assertions are optimized away when Python runs with -O, potentially bypassing the check.
CORRECT
B Assertions raise AssertionError, which is a subclass of Exception and can be caught.
C Assertions should be used for input validation because they provide clear error messages.
D Assertions are thread-safe and cannot be disabled at runtime.
EXPLANATION When Python is run with the -O flag, assert statements are removed, so security checks based on assertions can be silently skipped. Assertions are intended for debugging, not for enforcing security controls. The other options misstate assertion behavior.
Detailed Explanations
Q A developer writes a custom exception class that inherits from Exception but does not call super().init(). What is the most likely consequence when this exception is raised and logged?
A (^) The exception message will be empty when str() is called on the instance.
CORRECT
B (^) The exception will not be caught by except Exception clauses.
C (^) The traceback will not include the original exception context.
D (^) The exception will be automatically converted to a SystemExit.
EXPLANATION Without calling super().init(), the base Exception class does not receive the message argument, so str(exception) returns an empty string. The exception is still catchable and traceback behavior is unaffected. It is not converted to SystemExit.
Detailed Explanations
Q Which Python logging practice best supports the principle of least privilege when handling sensitive data?
A (^) Log all user input at DEBUG level for troubleshooting.
B (^) Use a filter to redact credit card numbers and passwords before logging.
CORRECT
C (^) Store logs in a world-readable directory for easy access.
D (^) Include full stack traces with local variables in error logs.
EXPLANATION Redacting sensitive data via a logging filter prevents exposure while maintaining useful logs. Logging all input or including local variables can leak secrets. World-readable logs violate confidentiality.
Detailed Explanations
Q A team uses a static analysis tool that reports a high number of false positives. What is the most effective approach to improve the signal-to-noise ratio without missing critical vulnerabilities?
A (^) Disable all rules that produce false positives.
B (^) Tune rule thresholds and add suppressions with justifications for known false positives.
CORRECT
C (^) Only run the tool on changed files in pull requests.
D (^) Replace the tool with a dynamic analysis tool.
EXPLANATION Tuning rules and documenting suppressions reduces noise while preserving detection of real issues. Disabling rules outright may miss vulnerabilities. Running only on changed files may miss context. Dynamic analysis complements but does not replace static analysis.
Detailed Explanations
Q A security analyst reviews a Python application and finds that it uses the pickle module to deserialize data from untrusted sources. Which remediation is most appropriate?
A (^) Use a restricted unpickler that only allows safe classes.
B (^) Replace pickle with a safe serialization format like JSON and validate the schema.
CORRECT
C (^) Encrypt the pickled data before transmission.
D (^) Add a digital signature to the pickled data and verify it before deserialization.
EXPLANATION Pickle is inherently unsafe for untrusted data; using JSON with schema validation eliminates the risk. Restricted unpicklers are complex and error-prone. Encryption and signatures do not prevent malicious payloads if the key is compromised or the signature is not verified properly.
Detailed Explanations
Q Which of the following best describes the role of assertions in a secure software development lifecycle?
A (^) Assertions should be used to enforce security invariants in production code.
B (^) Assertions are primarily for internal consistency checks during development and testing.
CORRECT
C (^) Assertions should replace exception handling for critical errors.
D (^) Assertions are the preferred method for input validation in public APIs.
EXPLANATION Assertions are designed for debugging and internal sanity checks, not for enforcing security in production because they can be disabled. They should not replace exception handling or input validation, which must always be active.
Detailed Explanations
Q A logging configuration uses logging.basicConfig(level=logging.INFO) and later a module calls logging.getLogger(__name__).debug('x'). Why does the debug message not appear even though the module logger inherits from root?
A Child loggers do not inherit level from root; they default to WARNING.
B (^) The effective level of the child logger is computed from its own level (NOTSET) walking up to root's INFO, so DEBUG is below the effective threshold and the record is dropped at the logger before reaching handlers.
CORRECT
C (^) basicConfig only configures the root handler, not the logger hierarchy, so child loggers are silently disabled.
D DEBUG records are always filtered by the logging.lastResort handler regardless of configuration.
EXPLANATION Effective level is resolved by walking the hierarchy when a logger's level is NOTSET; root is INFO, so the child's DEBUG call is filtered at the logger. Handlers also have levels, but the drop here occurs at the logger. Options A and C misstate inheritance; D confuses lastResort, which only applies when no handlers exist.
Detailed Explanations
Q In a pytest suite, assert response.json()['user']['id'] == expected fails with a KeyError rather than an assertion failure. Which remediation best preserves test intent and diagnosability?
A (^) Wrap the call in try/except KeyError: pytest.fail() with no message.
B (^) Replace with assert response.json().get('user', {}).get('id') == expected so a missing key yields a clean assertion diff.
CORRECT
C (^) Add pytestmark = pytest.mark.filterwarnings('ignore') to suppress the error.
D (^) Convert to assert expected in response.json() to avoid indexing.
EXPLANATION Using .get chains converts a missing-key crash into a boolean assertion whose diff shows actual vs expected, preserving intent and diagnostics. Option A discards the value diff, C is unrelated to exceptions, and D weakens the assertion so it no longer verifies the id value.
Detailed Explanations
Q A SAST tool reports a taint path from request.args['q'] to cursor.execute('SELECT ... WHERE name = ' + q). The team argues parameterization is unnecessary because they escape single quotes. Which reasoning is correct?
A (^) Escaping single quotes is sufficient because SQL injection requires quote termination.
B (^) Parameterization is required because escaping is dialect- and encoding-dependent and fails against numeric contexts, LIKE clauses, and second-order injection.
CORRECT
C (^) Parameterization is only needed for INSERT/UPDATE, not SELECT.
D (^) Escaping is equivalent to parameterization when using an ORM.
EXPLANATION Manual escaping is fragile across dialects, character sets, and contexts (numeric, LIKE, ORDER BY), and does not prevent second-order injection; parameterization binds values out-of-band. Options A, C, and D each misstate the threat model or the equivalence claim.
Detailed Explanations
Q Which combination of Python assert misuse creates a security vulnerability in production?
A (^) Using assert for type narrowing inside a function body.
B (^) Using assert user.is_admin as an authorization gate, because assert statements are stripped when Python runs with -O.
CORRECT
C (^) Using assert inside unit tests to validate outputs.
D (^) Using assert to validate constant invariants at import time.
EXPLANATION assert is removed under python -O, so authorization checks silently vanish in optimized deployments, enabling privilege escalation. Options A, C, and D are legitimate uses that do not create production security gaps.
Detailed Explanations
Q Which statement about logger.exception() versus logger.error() inside an except block is most accurate for security incident forensics?
A (^) They are identical; both include the traceback.
B (^) logger.exception() automatically includes the active exception traceback, while logger.error() includes it only if exc_info=True is passed.
CORRECT
C (^) logger.error() includes the traceback; logger.exception() does not.
D (^) Neither includes the traceback; traceback.print_exc() is required.
EXPLANATION logger.exception is shorthand for logger.error(..., exc_info=True), capturing the traceback for forensic reconstruction. Options A, C, and D misstate this behavior and would degrade incident analysis.
Detailed Explanations
Q A SAST baseline is introduced mid-project. The team wants to prevent new high-severity findings without blocking on legacy debt. Which approach best matches modern secure-SDLC practice?
A (^) Suppress all high-severity findings with # nosec comments.
B (^) Fail the build only on findings not present in the committed baseline, while tracking baseline burn-down separately.
CORRECT
C (^) Disable the SAST tool in CI and run it only quarterly.
D (^) Set the severity threshold to LOW so everything is visible and blocking.
EXPLANATION Baseline gating prevents regression while allowing incremental remediation of legacy debt, a standard secure-SDLC pattern. Option A hides issues, C removes continuous feedback, and D blocks all progress with pre-existing noise.