
















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: Which Python statement is used to verify that a condition is true during development and raises an AssertionError if false? A. validate() B. assert C. check() D. require() Correct Answer: B. assert Rationale: The assert statement is Python's built-in defensive programming tool that tests a condition; if false, it raises AssertionError. It is intended for catching programmer errors during development, not for handling runtime user input errors. No built-in Python function named validate() exists for this purpose; validation logic must be manually implemented. check() is not a Python keyword or standard function for condition verification. require() is not a Python built-in; some frameworks use similar names, but it is not part of core defensive programming in Python. Source: WGU D385: Software Security & Testing Original Practice Exam Package (2026 Edition)
Question 2: What is the PRIMARY purpose of defensive programming? A. To make code run faster B. To assume errors will occur and guard against them C. To reduce the number of lines of code D. To eliminate the need for testing Correct Answer: B. To assume errors will occur and guard against them Rationale: Defensive programming anticipates failures (invalid input, edge cases, system errors) and implements safeguards like input validation, assertions, and error handling to maintain stability. Performance optimization is separate from defensive design; defensive code may even add slight overhead. Defensive programming often increases code volume due to added checks. Testing remains essential; defensive programming complements but does not replace testing. Source: WGU D385: Software Security & Testing Original Practice Exam Package (2026 Edition) Question 3: Which scenario BEST illustrates a violation of the "fail-fast" principle? A. A function validates input at the start and raises an exception immediately if invalid B. A function continues processing with null values, causing errors 10 layers deep in the call stack C. A function logs a warning but proceeds with default values D. A function retries a failed network request three times Correct Answer: B. A function continues processing with null values, causing errors 10 layers deep in the call stack Rationale: Fail-fast means detecting and reporting errors as early as possible. Delaying error detection until deep in execution makes debugging harder and increases risk of data corruption. Option A follows fail-fast by validating early. Option C may be appropriate for non-critical warnings but is not a fail-fast violation per se. Option D is a resilience pattern, not inherently opposed to fail-fast. Source: WGU D385: Software Security & Testing Original Practice Exam Package (2026 Edition)
Question 6: What is a "precondition" in defensive programming? A. A condition that must be true before a function executes B. A condition that must be true after a function executes C. A condition that is always false D. A condition that is never checked Correct Answer: A. A condition that must be true before a function executes Rationale: Preconditions are conditions that must be true before a function executes. They verify that input data is valid before function execution. Postconditions are conditions that must be true after a function executes. Both are common defensive coding techniques. Source: WGU D385 Package Deal – Software Security and Testing Practice Test Questions Question 7: What are two common defensive coding techniques? A. Check functional preconditions and postconditions B. Encrypt passwords and email submissions C. Adjust length and encoding of messages D. Develop code with exceptions to find errors Correct Answer: A. Check functional preconditions and postconditions Rationale: Functional preconditions and postconditions are common defensive coding techniques. Preconditions verify that input data is valid before function execution, while postconditions ensure expected outcomes are achieved. Source: WGU D385 Package Deal – Software Security and Testing Practice Test Questions
Question 8: When Python runs with the -O optimization flag, what happens to assert statements? A. They execute faster B. They are removed from the compiled bytecode C. They generate more detailed error messages D. They are converted to warnings Correct Answer: B. They are removed from the compiled bytecode Rationale: When Python runs 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. Source: WGU D385: Software Security & Testing Original Practice Exam Package (2026 Edition)
Question 9: 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 outbound log messages. This prevents attackers from injecting malicious characters or commands into log entries. Validating outbound log messages ensures that user input cannot alter the structure or content of the audit trail.
Question 12: Which logging level should be used to record a runtime error that was successfully handled by exception handling? A. DEBUG B. INFO C. WARNING D. ERROR Correct Answer: D. ERROR Rationale: The ERROR level should be used to log runtime errors that were caught and handled. The ERROR level indicates a serious problem that occurred but was handled. WARNING indicates a potential issue that was handled. Source: WGU D385 Software Security and Testing | Python Secure-Coding Practice Workbook Question 13: What should be avoided when writing log messages to prevent sensitive data exposure? A. Including timestamps B. Including raw user input C. Including severity levels D. Including the logger name Correct Answer: B. Including raw user input Rationale: Log messages should avoid including raw user input because it may contain sensitive information such as passwords, personal data, or malicious characters. Including raw input in logs can expose sensitive data to anyone with log access and can facilitate log injection attacks. Source: WGU D385 Software Security and Testing | Python Secure-Coding Practice Workbook Question 14: 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. Source: WGU D385 Software Security and Testing | Python Secure-Coding Practice Workbook Question 15: What is a log injection attack? A. Encrypting log files without authorization B. Inserting malicious characters or commands into log entries C. Deleting log files to hide evidence D. Accessing log files without permission Correct Answer: B. Inserting malicious characters or commands into log entries Rationale: A log injection attack involves inserting malicious characters or commands into log entries through user-controlled input. This can forge severity text, insert newline characters to create fake log entries, or inject terminal escape sequences. The defense is to sanitize all outbound log messages. Source: WGU D385 Software Security and Testing | Python Secure-Coding Practice Workbook
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 Software Security and Testing | Python Secure-Coding Practice Workbook Question 18: 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. Source: WGU D385 Software Security and Testing | Python Secure-Coding Practice Workbook Question 19: 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. Source: WGU D385 Software Security and Testing | Python Secure-Coding Practice Workbook Question 20: 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. WARNING indicates a potential issue that was handled, while ERROR indicates a more serious failure. DEBUG and INFO are for diagnostic and informational messages, while CRITICAL is for critical system failures. Source: WGU D385 Software Security and Testing | Python Secure-Coding Practice Workbook Question 21: Why should exception handling preserve correct logging and response behavior? A. To improve application performance B. To ensure that failures are recorded and responses are safe
Question 23: Which Python function is prone to a potential code injection attack? A. type() B. eval() C. print() D. append() Correct Answer: B. eval() Rationale: A code injection attack occurs when user-supplied data is executed as code. The Python eval() function evaluates strings as code, making it highly vulnerable if user input is not properly sanitized. This can allow attackers to execute arbitrary code, access sensitive information, or take control of the program. Source: WGU D385 Software and Security Testing Actual Exam – Complete 250 Questions Question 24: Which method is used for a SQL injection attack? A. Exploiting query parameters B. Passing safe query parameters C. Using SQL composition D. Utilizing literal parameters Correct Answer: A. Exploiting query parameters Rationale: SQL injection attacks exploit query parameters by injecting malicious SQL code through user input. This occurs when applications fail to properly validate or sanitize input before including it in SQL queries. Source: WGU D385 Package Deal – Software Security and Testing Practice Test Questions
Question 25: What is the primary defense against SQL injection attacks? A. Using string concatenation to build queries B. Parameterized queries or prepared statements C. Storing passwords in plaintext D. Disabling input validation Correct Answer: B. Parameterized queries or prepared statements Rationale: Parameterized queries ensure that user input is treated as data, not executable code, preventing SQL injection attacks. This is the recommended approach for all database interactions. Source: WGU D385 Software and Security Testing Actual Exam – Complete 250 Questions Question 26: What happens when an attacker exploits a cross-site scripting vulnerability? A. Access the user's data B. Access the server's database C. Access the network D. Access the source code Correct Answer: A. Access the user's data Rationale: An attacker exploits a cross-site scripting vulnerability to access the user's data. XSS allows attackers to inject scripts into web pages, potentially stealing cookies, session tokens, or other sensitive data. Source: WGU D385 Package Deal – Software Security and Testing Practice Test Questions Question 27: A user masquerades as (or pretends to be) another user. What type of attack is this? A. SQL injection B. Cross-Site Scripting
Rationale: An allowlist (whitelist) approach only permits known good inputs, which is more secure than a blocklist approach that tries to block known bad inputs. Allowlists are default-deny, while blocklists always miss unknown-bad inputs. Source: WGU D385 Software Security and Testing | Python Secure-Coding Practice Workbook Question 30: What is the secure way to store passwords? A. Plaintext in a database B. Encrypted with a reversible algorithm C. Hashed with a strong, slow algorithm and salt D. Stored in cookies Correct Answer: C. Hashed with a strong, slow algorithm and salt Rationale: Passwords should be hashed with a strong, slow algorithm like bcrypt, Argon2, or PBKDF2, and include a unique salt for each password. This makes it computationally infeasible for attackers to recover the original passwords. Source: WGU D385 Software Security and Testing | Python Secure-Coding Practice Workbook
Question 31: Which protocol caches a token after it has been acquired? A. MSAL B. Auth
C. OAuth D. SAML Correct Answer: A. MSAL Rationale: MSAL (Microsoft Authentication Library) caches tokens after acquisition to improve performance and reduce authentication overhead. Source: WGU D385 Package Deal – Software Security and Testing Practice Test Questions Question 32: What does Cross-Origin-Resource-Sharing (CORS) allow users to do? A. Override same-origin policy for specific resources B. Bypass all security controls C. Access any website without restrictions D. Disable firewalls Correct Answer: A. Override same-origin policy for specific resources Rationale: CORS allows users to override the same-origin policy for specific resources. The access control allow origin client sends a request to the server, and the server sends back the ACAO (Access Control Allow Origin) header. Source: D385 Software and Security Testing WGU Updated Actual Questions Question 33: Which security principle ensures that users can only access resources they are authorized to use? A. Authentication B. Authorization C. Encryption D. Non-repudiation Correct Answer: B. Authorization