Docsity

WGU D385 Task 1 Performance Assessment Guide Software Security & Testing Python Logging,,, Exams of Computer Security

Toggle sidebar
bg1
WGU D385 Task 1 Performance Assessment Guide
Software Security & Testing Python Logging,,
Exams of Computer Security - Complete 50
Verified Q&A with Answers & Rationales for Exam
Prep
Q1
Which Python logging practice best prevents log injection while preserving audit detail?
A. Use a custom Formatter that escapes newlines and control characters in messages.
B. Set logging level to DEBUG to capture all input for later analysis.
C. Rely on the default Formatter, which automatically sanitizes all fields.
D. Log raw user input directly to a file handler without modification.
Answer: A
Rationale: Escaping newlines and control characters in a custom Formatter prevents log injection attacks
while retaining necessary detail. The default Formatter does not sanitize input, and logging raw input or
using DEBUG level increases risk and noise.
Q2
In threat modeling, which element most directly informs secure logging requirements?
A. Data flow diagrams showing trust boundaries and sensitive data paths.
B. The number of developers on the project team.
C. The programming language's built-in logging module version.
D. The frequency of code commits to the repository.
Answer: A
Rationale: Data flow diagrams with trust boundaries identify where sensitive data moves and where
logging is critical for detection and audit. Team size, logging module version, and commit frequency do not
directly define logging requirements from a threat perspective.
pf3
pf4
pf5
pf8
pf9
pfa
pfd
pfe
pff

Partial preview of the text

Download WGU D385 Task 1 Performance Assessment Guide Software Security & Testing Python Logging,, and more Exams Computer Security in PDF only on Docsity!

WGU D385 Task 1 Performance Assessment Guide

Software Security & Testing Python Logging,,

Exams of Computer Security - Complete 50

Verified Q&A with Answers & Rationales for Exam

Prep

Q

Which Python logging practice best prevents log injection while preserving audit detail?

A. Use a custom Formatter that escapes newlines and control characters in messages. B. Set logging level to DEBUG to capture all input for later analysis. C. Rely on the default Formatter, which automatically sanitizes all fields. D. Log raw user input directly to a file handler without modification.

Answer: A Rationale: Escaping newlines and control characters in a custom Formatter prevents log injection attacks while retaining necessary detail. The default Formatter does not sanitize input, and logging raw input or using DEBUG level increases risk and noise.

Q

In threat modeling, which element most directly informs secure logging requirements?

A. Data flow diagrams showing trust boundaries and sensitive data paths. B. The number of developers on the project team. C. The programming language's built-in logging module version. D. The frequency of code commits to the repository.

Answer: A Rationale: Data flow diagrams with trust boundaries identify where sensitive data moves and where logging is critical for detection and audit. Team size, logging module version, and commit frequency do not directly define logging requirements from a threat perspective.

Which Python logging configuration most effectively supports centralized audit trails in a distributed system?

A. Use a SysLogHandler or HTTPHandler to forward logs to a central server. B. Write logs to local files on each host with rotation. C. Use only the root logger with default settings. D. Disable logging in production to reduce overhead.

Answer: A Rationale: Forwarding logs to a central server via SysLogHandler or HTTPHandler enables aggregation and tamper-resistant audit trails. Local files are siloed and vulnerable to tampering, default root logger lacks structure, and disabling logging eliminates audit capability.

Q

Which OWASP Top 10 2021 category is most directly mitigated by proper logging and monitoring?

A. A09:2021 - Security Logging and Monitoring Failures B. A01:2021 - Broken Access Control C. A03:2021 - Injection D. A06:2021 - Vulnerable and Outdated Components

Answer: A Rationale: A09:2021 specifically addresses failures in logging and monitoring, which are mitigated by implementing adequate logging, detection, and response. Other categories relate to access control, injection flaws, and component vulnerabilities, not primarily logging.

Q

When configuring Python logging for security events, which level should be used for failed login attempts?

A. WARNING B. DEBUG C. INFO D. ERROR

Answer: A Rationale: Failed login attempts are security-relevant anomalies best logged at WARNING level to ensure visibility without being overly noisy. DEBUG is too verbose, INFO is for normal operations, and ERROR is typically for system errors rather than authentication failures.

In secure code review, which logging-related vulnerability is most critical?

A. Logging sensitive data such as passwords or tokens. B. Using a non-rotating file handler. C. Setting the log level to DEBUG in development. D. Using the default log format.

Answer: A Rationale: Logging sensitive data exposes credentials and violates privacy, leading to severe security breaches. Non-rotating files, DEBUG level in development, and default format are operational or minor concerns compared to data leakage.

Q

Which threat modeling output most directly guides the selection of logging events?

A. A list of identified threats and their potential impact. B. The project timeline. C. The team's coding style guide. D. The number of test cases.

Answer: A Rationale: Identified threats and impacts determine which events are security-relevant and should be logged for detection and response. Timelines, style guides, and test case counts do not inform logging event selection.

Q

Which Python logging configuration most effectively prevents log injection attacks while preserving structured analysis?

A. Use a RotatingFileHandler with a formatter that includes the raw user input string. B. Log user input only after sanitizing newline and control characters, using parameterized messages. C. Set the logging level to DEBUG to capture all input for later forensic review. D. Disable logging of user-supplied data entirely to eliminate the risk.

Answer: B Rationale: Sanitizing newline/control characters and using parameterized logging prevents log forging and injection while retaining data for analysis. Raw input (A) enables injection, DEBUG (C) increases exposure without sanitization, and disabling logging (D) loses audit value.

In threat modeling a Python web app, which STRIDE category best captures logging of unvalidated user input to a file?

A. Spoofing B. Tampering C. Repudiation D. Information Disclosure

Answer: B Rationale: Log injection via unvalidated input allows attackers to alter log content, which is Tampering. Spoofing (A) involves identity, Repudiation (C) denies actions, and Information Disclosure (D) exposes data, not log integrity.

Q

A Python app must log security events to a central SIEM without blocking request handling. Which logging handler is most appropriate?

A. StreamHandler writing to stdout B. SocketHandler with a non-blocking, queued sender C. FileHandler with immediate flush D. SMTPHandler for email alerts

Answer: B Rationale: A SocketHandler with a queued, non-blocking sender forwards events to a SIEM without blocking. StreamHandler (A) and FileHandler (C) are local and may block; SMTPHandler (D) is for alerts, not central logging.

Q

Which Python logging practice best supports non-repudiation in an audit trail?

A. Logging only at ERROR level to reduce noise B. Using a formatter that includes timestamp, user ID, and a cryptographic hash of the message C. Storing logs in a local file with default permissions D. Rotating logs daily without offsite backup

Answer: B Rationale: Including timestamp, user ID, and a cryptographic hash enables integrity verification and non-repudiation. ERROR-only (A) loses detail, default permissions (C) risk tampering, and no offsite backup (D) risks loss.

Which Python logging formatter attribute helps detect tampering by including a sequence number?

A. %(asctime)s B. %(levelname)s C. %(process)d D. Custom attribute %(seq)d added via a filter

Answer: D Rationale: A custom sequence number added via a filter enables detection of missing or reordered entries. asctime (A), levelname (B), and process (C) do not provide ordering integrity.

Q

When testing a Python logging module, which approach best verifies that sensitive data is not logged?

A. Unit test asserting log output contains no credit card patterns. B. Manual code review of logging statements. C. Integration test checking log file size. D. Static analysis for print statements.

Answer: A Rationale: A unit test with pattern assertions directly verifies absence of sensitive data in logs. Manual review (B) is error-prone, log size (C) is irrelevant, and print statements (D) miss logging calls.

Q

Which Python logging level should be used for security events that require immediate attention but are not errors?

A. DEBUG B. INFO C. WARNING D. CRITICAL

Answer: C Rationale: WARNING indicates potential issues needing attention without being errors. DEBUG (A) is for diagnostics, INFO (B) is routine, and CRITICAL (D) is for severe failures.

In Python's logging module, which handler configuration most directly prevents log injection via newline characters in user-supplied data?

A. Using a RotatingFileHandler with a maximum file size limit B. Setting the formatter to include the thread name and process ID C. Applying a custom Formatter that escapes newline and carriage return characters D. Configuring the logger to use the DEBUG level for all user input

Answer: C Rationale: A custom Formatter that escapes newline and carriage return characters neutralizes log injection by ensuring user data cannot forge new log entries. RotatingFileHandler, thread/process identifiers, and DEBUG level do not sanitize newline characters.

Q

Which OWASP Top 10 2021 category is most directly mitigated by comprehensive security logging and monitoring failures?

A. A01:2021 - Broken Access Control B. A09:2021 - Security Logging and Monitoring Failures C. A03:2021 - Injection D. A05:2021 - Security Misconfiguration

Answer: B Rationale: A09:2021 explicitly addresses security logging and monitoring failures, including insufficient logging of security events. The other categories relate to access control, injection, and misconfiguration, not logging failures.

Q

When performing static application security testing (SAST) on Python code, which limitation is most critical to recognize?

A. SAST cannot analyze interpreted languages like Python B. SAST requires a running application to detect vulnerabilities C. SAST may produce false positives due to incomplete context and dynamic features D. SAST only detects vulnerabilities in third-party dependencies

Answer: C Rationale: SAST analyzes source code without execution and can yield false positives because it lacks runtime context and may not fully resolve dynamic Python features. SAST does analyze Python, does not require a running app, and is not limited to dependencies.

In Python's logging configuration, what is the primary security risk of using a FileHandler with a world-writable log file?

A. Log files may be tampered with or injected with malicious content B. Logging performance will degrade significantly C. The application will crash due to permission errors D. Log rotation will fail silently

Answer: A Rationale: A world-writable log file allows unauthorized users to modify or inject content, compromising log integrity and audit trails. Performance, crashes, and rotation issues are operational concerns, not the primary security risk.

Q

Which dynamic application security testing (DAST) finding is most indicative of a logging-related vulnerability?

A. SQL injection in a login form B. Cross-site scripting in a search field C. Sensitive data such as passwords appearing in log files D. Directory traversal in file download

Answer: C Rationale: DAST can detect sensitive data exposure in logs, which is a logging-related vulnerability. SQL injection, XSS, and directory traversal are separate vulnerability classes not specific to logging.

Q

When designing an audit trail for a Python application, which logging attribute is essential to ensure non-repudiation?

A. The log level (e.g., INFO, ERROR) B. A timestamp and user identity for each event C. The name of the logger instance D. The process ID and thread name

Answer: B Rationale: Non-repudiation requires associating events with a timestamp and authenticated user identity to prevent denial of actions. Log level, logger name, and process/thread identifiers do not establish accountability.

Which CIS Control v8 safeguard specifically addresses the logging of security events?

A. Control 8: Audit Log Management B. Control 4: Secure Configuration C. Control 12: Network Infrastructure Management D. Control 16: Application Software Security

Answer: A Rationale: CIS Control 8 is dedicated to Audit Log Management, covering collection, retention, and review of security events. The other controls focus on configuration, network, and application security, not logging specifically.

Q

Which Python logging configuration most effectively prevents log injection attacks in a web application?

A. Using a RotatingFileHandler with a maximum file size limit. B. Setting the logging level to WARNING to reduce log volume. C. Sanitizing user input before logging and using structured logging formats. D. Employing a SysLogHandler to send logs to a remote server.

Answer: C Rationale: Log injection occurs when untrusted input containing newlines or control characters is written to logs, allowing attackers to forge entries. Sanitizing input and using structured formats (e.g., JSON) prevent this. Other options address availability or volume, not injection.

Q

In threat modeling, which STRIDE category is mitigated by implementing logging of failed authentication attempts?

A. Spoofing B. Tampering C. Repudiation D. Information Disclosure

Answer: C Rationale: Repudiation threats involve users denying having performed an action. Logging failed authentication attempts provides an audit trail that prevents repudiation. Spoofing is mitigated by authentication, tampering by integrity controls, and information disclosure by encryption.

Which NIST SSDF practice emphasizes logging security-relevant events for software?

A. PO.1: Define security requirements B. PW.4: Reuse existing, well-secured software C. PS.2: Provide a mechanism for verifying software release integrity D. RV.1: Identify and confirm vulnerabilities on an ongoing basis

Answer: A Rationale: NIST SSDF PO.1 (Define security requirements) includes requirements for logging and monitoring. While other practices relate to security, logging is part of defining requirements. PW.4 is about reuse, PS.2 about integrity verification, and RV.1 about vulnerability identification.

Q

In dynamic application security testing (DAST), which technique best detects logging-related vulnerabilities?

A. Static code analysis of logging statements. B. Fuzzing input fields with malicious payloads and monitoring logs. C. Reviewing log configuration files for best practices. D. Penetration testing of the logging server infrastructure.

Answer: B Rationale: DAST involves testing the running application. Fuzzing inputs and observing log outputs can reveal log injection or insufficient logging. Static analysis (A) is SAST, configuration review (C) is not dynamic, and infrastructure testing (D) is outside application logging scope.

Q

Which Python logging formatter attribute is most critical to include for security audit trails?

A. The process ID (process). B. The thread name (threadName). C. A timestamp with timezone (asctime). D. The logger name (name).

Answer: C Rationale: Timestamps with timezone provide accurate event ordering and correlation, essential for audits. While process ID, thread name, and logger name add context, they are not as critical as time for establishing an audit trail.

Which secure coding principle is violated by logging sensitive data such as passwords or credit card numbers?

A. Least privilege B. Defense in depth C. Data minimization D. Fail securely

Answer: C Rationale: Data minimization means collecting and retaining only necessary data. Logging sensitive data violates this by unnecessarily exposing it. Least privilege is about access rights, defense in depth layers controls, and fail securely handles errors safely.

Q

Which logging level should be used to record a security event that is not an error but requires immediate attention?

A. DEBUG B. INFO C. WARNING D. CRITICAL

Answer: C Rationale: WARNING indicates a potential problem that should be reviewed, suitable for security events needing attention but not errors. DEBUG is for diagnostic details, INFO for routine events, and CRITICAL for severe errors requiring immediate action.

Q

Which Python logging configuration most effectively prevents log injection attacks via user-controlled data?

A. Using a Formatter with a custom format string that escapes newline characters in the message. B. Setting the logging level to WARNING to reduce the volume of logged user input. C. Employing a RotatingFileHandler with a maximum file size to limit injection payload size. D. Disabling the logging module's internal exception handling to avoid format string vulnerabilities.

Answer: A Rationale: Log injection occurs when untrusted input containing newlines or control characters is written directly to logs, allowing attackers to forge log entries. A custom Formatter that escapes newlines (e.g., replacing '\n' with '\n') neutralizes this risk. The other options do not address the injection vector: level adjustment, file rotation, and disabling exception handling are unrelated to input sanitization.

Which OWASP Top 10 2021 category is most directly mitigated by implementing structured logging with proper sanitization?

A. A01: Broken Access Control B. A03: Injection C. A05: Security Misconfiguration D. A09: Security Logging and Monitoring Failures

Answer: D Rationale: A09 directly addresses failures in logging and monitoring, including insufficient logging of security events and improper sanitization that can lead to log injection. While injection (A03) could involve logs, A09 is the category explicitly focused on logging practices. The other categories are less directly related to logging implementation.

Q

When configuring Python logging for a security-sensitive application, which level should be used for logging authentication failures?

A. DEBUG B. INFO C. WARNING D. ERROR

Answer: C Rationale: Authentication failures are typically logged at WARNING level because they indicate a potential security issue but are not necessarily errors in the application's operation. DEBUG is for detailed diagnostic information, INFO for routine events, and ERROR for serious problems that prevent normal operation. Using WARNING ensures visibility without flooding logs with false positives.

Q

Which secure coding practice best prevents sensitive data leakage through Python logging?

A. Logging all user input at DEBUG level for troubleshooting. B. Using a whitelist approach to log only non-sensitive fields. C. Storing log files in a publicly accessible directory for easy monitoring. D. Disabling logging entirely in production to avoid leaks.

Answer: B Rationale: A whitelist approach ensures only explicitly approved, non-sensitive data is logged, preventing accidental leakage of PII or secrets. Logging all input at DEBUG risks exposure, public directories are insecure, and disabling logging eliminates audit capabilities and is not a secure practice.

In a log management system, which control best ensures the integrity of audit logs against tampering?

A. Encrypting log files at rest with AES-256. B. Using append-only storage with cryptographic hashing. C. Restricting log file permissions to root only. D. Rotating logs every hour to limit exposure.

Answer: B Rationale: Append-only storage prevents modification or deletion of log entries, and cryptographic hashing (e.g., chaining hashes) provides tamper evidence. Encryption at rest protects confidentiality but not integrity, file permissions can be bypassed by privileged users, and frequent rotation does not prevent tampering.

Q

Which Python logging formatter attribute is most critical for correlating security events across distributed systems?

A. asctime B. levelname C. process D. threadName

Answer: A Rationale: asctime provides a timestamp, which is essential for correlating events chronologically across systems. While process and threadName help identify local context, they lack global uniqueness. levelname indicates severity but not timing. Timestamps are fundamental for reconstructing attack timelines.

Q

Which NIST SSDF practice directly addresses secure logging implementation in software development?

A. PW.4: Reuse well-secured software B. PS.1: Protect all forms of code from unauthorized access C. RV.1: Identify and confirm vulnerabilities on an ongoing basis D. PO.3: Implement supporting toolchains

Answer: B Rationale: PS.1 focuses on protecting code and related artifacts, which includes ensuring logs are securely implemented and protected from unauthorized access. PW.4 concerns software reuse, RV.1 is about vulnerability identification, and PO.3 is about toolchains-none specifically target logging security as directly as PS.1.