






















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!























Question 1: What is the primary defense against log injection attacks? A. Encrypting all log files B. Sanitizing outbound log messages C. Restricting access to log files D. Using a centralized logging server Correct Answer: B. Sanitizing outbound log messages Rationale: The primary defense against log injection attacks is to sanitize or validate all data before it is written to logs. This prevents attackers from injecting malicious characters or commands into log entries, which could forge severity text or insert newline characters to manipulate the audit trail. While encryption (A) and access control (C) are important for protecting logs, they do not prevent the injection itself. A centralized logging server (D) improves log management but does not address the injection vulnerability. Source: WGU D385 V2 Software Security and Testing Master Study Guide
Question 2: Which Python logging configuration ensures that log messages capture the correct timestamp, severity level, and message content? A. logging.basicConfig(level=logging.DEBUG) B. logging.basicConfig(format='%(asctime)s - %(levelname)s - %(message)s') C. logging.basicConfig(filename='app.log') D. logging.basicConfig(level=logging.INFO) Correct Answer: B. logging.basicConfig(format='%(asctime)s - %(levelname)s - % (message)s') Rationale: The format parameter in logging.basicConfig uses placeholders to define the structure of log messages. %(asctime)s captures the timestamp, % (levelname)s captures the severity level, and %(message)s captures the actual log message. This format ensures that all critical information is captured in each log entry, which is essential for security auditing and debugging. Options A, C, and D configure other aspects of logging but do not specify the format attributes. Source: WGU D385 Software Security and Testing - Full Course Bank Question 3: What is the purpose of assertions in defensive programming? A. To handle runtime errors B. To verify that assumptions about the program state are correct C. To encrypt sensitive data D. To log user activity Correct Answer: B. To verify that assumptions about the program state are correct Rationale: Assertions document conditions the developer expects to be true after external data has been validated. The sample asserts that the caller supplied a username object and that a validated rental total is positive. Assertions improve developer feedback by failing close to an invalid internal state. However, assertions are intentionally not used as the sole protection against hostile input because Python can remove assert statements when executed with optimization. Options A, C, and D describe other programming mechanisms. Source: WGU D385 Task 1 Performance Assessment
Question 6: What is the purpose of the logging.basicConfig() function? A. To create a new logger instance B. To configure the root logger with basic settings C. To define custom log levels D. To filter log messages by severity Correct Answer: B. To configure the root logger with basic settings Rationale: logging.basicConfig() configures the root logger with default settings including level, format, filename, and stream. It should be called once at the module top level. This function provides a simple way to set up logging for applications without configuring individual loggers. Options A, C, and D describe other logging operations that require different approaches. Source: WGU D385 Software Security and Testing - Full Course Bank Question 7: Which placeholder in the logging format string captures the severity level of a log message? A. %(asctime)s B. %(levelname)s C. %(message)s D. %(name)s Correct Answer: B. %(levelname)s Rationale: The %(levelname)s placeholder captures the severity level (DEBUG, INFO, WARNING, ERROR, CRITICAL) of the log message. This is essential for log analysis and security monitoring, as it allows filtering and prioritizing log entries. %(asctime)s captures the timestamp, %(message)s captures the message content, and %(name)s captures the logger name. Source: WGU D385 Software Security and Testing - Full Course Bank
Question 8: What format should log messages follow in Task 1 to meet the requirements? A. [LEVEL] - [MESSAGE] B. EVENT: [event] | ACTION: [action] C. [TIMESTAMP] [LEVEL] [MESSAGE] D. [LOGGER] [LEVEL] [MESSAGE] Correct Answer: B. EVENT: [event] | ACTION: [action] Rationale: Task 1 requires that log messages follow the format EVENT: [event] | ACTION: [action]. This structured format ensures consistency and makes logs easier to parse and analyze. The format captures both what happened (the event) and what was done (the action), providing a complete audit trail for security monitoring and debugging. Source: WGU D385 Software Security and Testing - Full Course Bank Question 9: What is the default log level for logging.basicConfig()? A. DEBUG B. INFO C. WARNING D. ERROR Correct Answer: C. WARNING Rationale: The default log level for logging.basicConfig() is WARNING. This means that DEBUG and INFO messages will not be captured unless the level is explicitly set to DEBUG or INFO. In Task 1, the logging level should be set to INFO to capture informational messages required for B1. Understanding the default level is important for configuring appropriate log verbosity. Source: WGU D385 Software Security and Testing - Full Course Bank Question 10: What is a log injection attack? A. Encrypting log files without authorization B. Inserting malicious characters or commands into log entries
level and providing safe user-facing messages without stack traces or PII. Options B, C, and D mischaracterize the security concern. Source: WGU D385 Task 1 Performance Assessment Question 12: Which exception handling pattern is recommended for security-sensitive applications? A. except Exception: pass B. except: continue C. except (KeyError, TypeError, ValueError) as e: logging.warning(...) D. except: logging.error(...) Correct Answer: C. except (KeyError, TypeError, ValueError) as e: logging.warning(...) Rationale: The recommended pattern is to catch specific exception types and log them at the appropriate level. This prevents hiding unexpected errors (which could indicate attacks) while still handling anticipated failures gracefully. Options A and B use bare except clauses that catch all exceptions. Option D uses a bare except with logging, which still catches everything and could hide security-relevant errors. Source: WGU D385 Task 1 Performance Assessment Question 13: What information should NOT be included in user-facing error messages? A. A generic error description B. Stack traces and internal implementation details C. A request ID for tracking D. Instructions for contacting support Correct Answer: B. Stack traces and internal implementation details Rationale: User-facing error messages should not include stack traces, internal paths, package names, source lines, data shapes, or internal control flow. These details could disclose architecture information that helps attackers understand the system. Instead, errors should be converted to safe
responses with generic messages, while detailed logging preserves operational visibility. Options A, C, and D are appropriate elements for user- facing error messages. Source: WGU D385 Task 1 Performance Assessment Question 14: What is the security implication of logging stack traces in production? A. It improves debugging efficiency B. It discloses architecture and implementation details to potential attackers C. It increases log file size D. It slows down application performance Correct Answer: B. It discloses architecture and implementation details to potential attackers Rationale: Logging stack traces in production can disclose paths, package names, source lines, data shapes, and internal control flow. This information helps attackers understand the system architecture and identify potential attack vectors. While stack traces are useful for debugging in development, production error responses should provide safe messages while detailed errors are logged internally with appropriate access controls. Options A, C, and D are not the primary security concern. Source: WGU D385 Task 1 Performance Assessment Question 15: What logging level should be used for anticipated failures that were successfully recovered from? A. DEBUG B. INFO C. WARNING D. CRITICAL Correct Answer: C. WARNING Rationale: The WARNING level should be used for anticipated failures that were successfully recovered from. Task 1 requires one ERROR log entry and
Rationale: Secure exception handling catches specific anticipated exceptions such as KeyError, TypeError, ValueError, and AssertionError. This allows the application to handle expected failures gracefully while allowing unexpected errors (which may indicate security issues) to propagate for investigation. Catching all exceptions with bare except (B) hides defects, while catching only SystemExit (A) or custom exceptions (D) misses common error types. Source: WGU D385 Task 1 Performance Assessment Question 18: How does exception handling contribute to defense in depth? A. By providing multiple layers of input validation B. By preventing raw tracebacks from becoming an architecture-discovery channel C. By encrypting sensitive data at rest D. By authenticating users before processing requests Correct Answer: B. By preventing raw tracebacks from becoming an architecture-discovery channel Rationale: Exception handling contributes to defense in depth by preventing raw tracebacks from being exposed to users, which could disclose architecture information. Converting anticipated failures to safe responses reduces information exposure while structured internal logging preserves operational visibility. This is one layer in a comprehensive security strategy. Options A, C, and D describe other security controls. Source: WGU D385 Task 1 Performance Assessment Question 19: In Task 1, what is required for the exception handling component (B2)? A. One try/except block B. Two try/except blocks, each handling a different runtime error C. Three try/except blocks D. No exception handling is required
Correct Answer: B. Two try/except blocks, each handling a different runtime error Rationale: Task 1 requires B2 try/except handling of two runtime errors, with one ERROR log entry and one WARNING log entry. This demonstrates the ability to handle different types of exceptions appropriately and log them at the correct severity levels. The two exceptions should be distinct to show understanding of different error scenarios. Source: WGU D385 Software Security and Testing - Full Course Bank Question 20: What is the risk of using except: pass in production code? A. It improves code readability B. It silently swallows all errors, including security-relevant ones C. It reduces the number of log entries D. It improves application performance Correct Answer: B. It silently swallows all errors, including security- relevant ones Rationale: Using except: pass silently swallows all exceptions without logging or handling them. This can hide attack indicators, mask defects, and allow the program to continue in an invalid state. Security-relevant errors that should trigger alerts may go unnoticed. The remediation is to catch specific exceptions and log them at the appropriate level. Options A, C, and D describe outcomes that do not address the security risk. Source: WGU D385 Task 1 Performance Assessment
Question 21: What is the purpose of assertions in Python?
Question 23: What should an assertion check after external data has been validated? A. That the user has correct permissions B. That the validated data meets internal invariants C. That the network connection is secure D. That the database is accessible Correct Answer: B. That the validated data meets internal invariants Rationale: After external data has been validated, assertions should check that the validated data meets internal invariants. For example, asserting that a validated rental total is positive or that a username object is not None. These assertions document the developer's expectations about program state and help catch programming errors early. Options A, C, and D describe other system checks that are not the purpose of assertions. Source: WGU D385 Task 1 Performance Assessment Question 24: What is the relationship between assertions and input validation? A. Assertions replace input validation B. Input validation replaces assertions C. Assertions document conditions after validation establishes preconditions D. They are unrelated concepts Correct Answer: C. Assertions document conditions after validation establishes preconditions Rationale: The relationship is that assertions document conditions the developer expects to be true after external data has been validated. Boundary validation remains mandatory because Python can remove assert statements. The design uses normal conditional checks for security decisions and assertions only after validation establishes the relevant preconditions. Options A and B incorrectly suggest replacement, while D ignores their complementary relationship. Source: WGU D385 Task 1 Performance Assessment
Question 25: In Task 1, what is required for the assertions component (B3)? A. One assertion with an INFO log entry B. Two assertions, each proven by an INFO entry C. Three assertions without logging D. No assertions are required Correct Answer: B. Two assertions, each proven by an INFO entry Rationale: Task 1 requires B3 two assertions, each proven by an INFO entry. This demonstrates the ability to use assertions appropriately and to verify that they execute as expected. Each assertion should be accompanied by an INFO log entry that documents the assertion's success, providing evidence that the assertion was reached and evaluated. Source: WGU D385 Software Security and Testing - Full Course Bank Question 26: What happens to assertions when Python is run with the -O optimization flag? A. They execute faster B. They are removed from the code C. They generate more detailed error messages D. They are converted to warnings Correct Answer: B. They are removed from the code Rationale: When Python is run with the -O (optimize) flag, assert statements are removed from the compiled bytecode. This is why assertions should never be used as the sole security control. Any security-critical validation must use normal conditional checks that remain active regardless of optimization settings. Options A, C, and D incorrectly describe the behavior of assertions under optimization. Source: WGU D385 Task 1 Performance Assessment Question 27: What is the correct syntax for an assertion with a custom error message?
Question 29: Which of the following is an example of an appropriate assertion? A. assert user_input == "valid" B. assert total > 0, "validated rental totals must be positive" C. assert password == "secret123" D. assert request.method == "GET" Correct Answer: B. assert total > 0, "validated rental totals must be positive" Rationale: An appropriate assertion checks an internal invariant after validation has occurred. The sample code uses assert total > 0, "validated rental totals must be positive" after the total has been validated. Options A and D check external input directly, which should be validated with conditional checks. Option C is a security vulnerability as it hardcodes a password. Source: WGU D385 Task 1 Performance Assessment Question 30: What is the difference between an assertion and exception handling? A. Assertions handle runtime errors; exception handling documents invariants B. Assertions document and test internal invariants; exception handling recovers from anticipated failures C. They are the same mechanism D. Assertions are for production; exception handling is for development Correct Answer: B. Assertions document and test internal invariants; exception handling recovers from anticipated failures Rationale: Assertions document and test internal invariants that the developer expects to be true, while exception handling recovers from anticipated failures. Assertions are for developer feedback during development and testing, while exception handling provides graceful recovery in production. Assertions may be disabled with optimization; exception handling must remain active. Options A, C, and D incorrectly describe their roles. Source: WGU D385 Task 1 Performance Assessment
Question 31: What is static code analysis? A. Testing code by executing it with various inputs B. Analyzing code without executing it to find potential issues C. Monitoring code performance in production D. Documenting code functionality Correct Answer: B. Analyzing code without executing it to find potential issues Rationale: Static code analysis examines source code without executing it to identify potential security vulnerabilities, coding errors, and style issues. This contrasts with dynamic analysis, which requires running the code. Static analysis tools like Bandit and flake8 can quickly scan large codebases and are especially useful in continuous integration pipelines. Options A, C, and D describe other testing and analysis approaches. Source: WGU D385 Final Exam Questions and Answers Question 32: What is an advantage of static code analysis? A. It finds runtime vulnerabilities B. It requires no understanding of how to write software C. It provides fast turnaround time, especially when tools are used D. It eliminates all false positives Correct Answer: C. It provides fast turnaround time, especially when tools are used