Skip to content

Commit 93758f7

Browse files
committed
fixed formatting and cosmetics, not sure what to do with the reference, related guidelines
Signed-off-by: Helge Wehder <[email protected]>
1 parent e11605b commit 93758f7

File tree

1 file changed

+44
-26
lines changed
  • docs/Secure-Coding-Guide-for-Python/CWE-707/CWE-117

1 file changed

+44
-26
lines changed

docs/Secure-Coding-Guide-for-Python/CWE-707/CWE-117/README.md

Lines changed: 44 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,19 @@
11
# CWE-117: Improper Output Neutralization for Logs
22

3-
Log injection occurs when untrusted data is written to application logs without proper neutralization, allowing attackers to forge log entries or inject malicious content. Attackers can inject fake log records or hide real ones by inserting newline sequences (`\r` or `\n`), misleading auditors and incident-response teams. This vulnerability can also enable injection of XSS attacks when logs are viewed in vulnerable web applications.
3+
Log injection occurs when untrusted data is written to application logs without proper neutralization, allowing attackers to forge log entries or inject malicious content. Attackers can inject fake log records or hide real ones by inserting newline sequences (`\r` or `\n`), misleading auditors and incident-response teams. This vulnerability can also enable injection of `XSS` attacks when logs are viewed in vulnerable web applications.
44

5-
Attackers can exploit this weakness by submitting strings containing CRLF (Carriage Return Line Feed) sequences that create fake log entries. For instance, an attacker authenticating with a crafted username can make failed login attempts appear successful in audit logs, potentially framing innocent users or hiding malicious activity.
5+
Attackers can exploit this weakness by submitting strings containing `CRLF` (Carriage Return Line Feed) sequences that create fake log entries. For instance, an attacker authenticating with a crafted username can make failed login attempts appear successful in audit logs, potentially framing innocent users or hiding malicious activity.
66

7-
This vulnerability is classified as **CWE-117: Improper Output Neutralization for Logs** [cwe117]. It occurs when CRLF sequences are not properly neutralized in log output, which is a specific instance of the broader **CWE-93: Improper Neutralization of CRLF Sequences** [cwe93] weakness. Attackers exploit this using the **CAPEC-93: Log Injection-Tampering-Forging** [capec93] attack pattern.
7+
This vulnerability is classified as **CWE-117: Improper Output Neutralization for Logs** [[CWE-117](https://cwe.mitre.org/data/definitions/117.html)]. It occurs when `CRLF` sequences are not properly neutralized in log output, which is a specific instance of the broader **CWE-93: Improper Neutralization of CRLF Sequences** [[CWE-93](https://cwe.mitre.org/data/definitions/93.html)] weakness. Attackers exploit this using the **CAPEC-93: Log Injection-Tampering-Forging** [[CAPEC-93](https://capec.mitre.org/data/definitions/93.html)] attack pattern.
88

9-
The OWASP Top 10 lists “Security Logging and Monitoring Failures” as a critical security risk, emphasizing that log data must be encoded correctly to prevent injections.
9+
The OWASP Top 10 [[OWASP](https://owasp.org/www-project-top-ten/)]lists “Security Logging and Monitoring Failures” as a critical security risk, emphasizing that log data must be encoded correctly to prevent injections.
1010

1111
## Noncompliant Code Example
1212

1313
This example demonstrates how raw user input written to logs enables injection attacks:
1414

15+
_[noncompliant01.py](noncompliant01.py):_
16+
1517
```python
1618
""" Non-compliant Code Example """
1719
import logging
@@ -26,7 +28,7 @@ def log_authentication_failed(user):
2628
log_authentication_failed("guest'\nWARNING:root:User login failed for: 'administrator")
2729
```
2830

29-
The output demonstrates successful log injection:
31+
**Expample output of noncompliant01.py:**
3032

3133
```bash
3234
WARNING:root:User login failed for: 'guest'
@@ -37,7 +39,9 @@ The attacker's input creates what appears to be a legitimate log entry showing a
3739

3840
## Compliant Solution
3941

40-
The `compliant01.py` solution uses a strict allow-list for usernames and returns early on any mismatch, so CR/LF or other disallowed characters never reach the logger; for rejected attempts it logs a safe one-line summary with `%r` (escaped newlines), preventing forged secondary log lines. In short: validate upfront and neutralize what you do record.
42+
The `compliant01.py` solution uses a strict allow-list for usernames and returns early on any mismatch, so `CR/LF` or other disallowed characters never reach the logger; for rejected attempts it logs a safe one-line summary with `%r` (escaped newlines), preventing forged secondary log lines. In short: validate upfront and neutralize what you do record.
43+
44+
_[compliant01.py](compliant01.py):_
4145

4246
```python
4347
""" Compliant Code Example """
@@ -76,6 +80,8 @@ log_authentication_failed("guest'\nWARNING:root:User login failed for: 'administ
7680

7781
The following output shows that a warning is logged, and the input is sanitized before logging.
7882

83+
**Example compliant01.py output:**
84+
7985
```bash
8086
WARNING:root:Rejected login attempt: invalid username="guest'\nWARNING:root:User login failed for: 'administrator"
8187
```
@@ -121,26 +127,38 @@ WARNING:root:Rejected login attempt: invalid username="guest'\nWARNING:root:User
121127

122128
## Related Guidelines
123129

124-
- **CWE-117**: Improper Output Neutralization for Logs [cwe117]
125-
- **CWE-93**: Improper Neutralization of CRLF Sequences ('CRLF Injection') [cwe93]
126-
- **CWE-113**: Improper Neutralization of CRLF Sequences in HTTP Headers [cwe113]
127-
- **CAPEC-93**: Log Injection-Tampering-Forging [capec93]
128-
- **OWASP Top 10 2021**: A09 - Security Logging and Monitoring Failures [owasp_top10_2021]
129-
- **OWASP ASVS 4.0**: V7.1 Log Content Requirements [owasp_asvs]
130-
- **ISO/IEC TR 24772:2013**: Injection [RST] [iso24772]
131-
- **NIST SP 800-92**: Guide to Computer Security Log Management [nist80092]
130+
<table>
131+
<tr>
132+
<td><a href="http://cwe.mitre.org/">MITRE CWE</a></td>
133+
<td>Pillar: <a href="https://cwe.mitre.org/data/definitions/707.html"> CWE-707: Improper Neutralization</a></td>
134+
</tr>
135+
<tr>
136+
<td><a href="http://cwe.mitre.org/">MITRE CWE</a></td>
137+
<td>Base: <a href="https://cwe.mitre.org/data/definitions/117.html">CWE-117: Improper Output Neutralization for Log</a></td>
138+
</tr>
139+
<tr>
140+
<td><a href="http://cwe.mitre.org/">MITRE CWE</a></td>
141+
<td>Base: <a href="https://cwe.mitre.org/data/definitions/93.html">CWE-93: Improper Neutralization of CRLF Sequences ('CRLF Injection')</a></td>
142+
</tr>
143+
<tr>
144+
<td><a href="http://cwe.mitre.org/">MITRE CWE</a></td>
145+
<td>Variant: <a href="https://cwe.mitre.org/data/definitions/113.html">CWE-113: Improper Neutralization of CRLF Sequences in HTTP Headers ('HTTP Request/Response Splitting')</a></td>
146+
</tr>
147+
<tr>
148+
<td><a href="http://cwe.mitre.org/">MITRE CWE</a></td>
149+
<td>Detailed: <a href="https://capec.mitre.org/data/definitions/93.html">CAPEC-93: Log Injection-Tampering-Forging</a></td>
150+
</tr>
151+
<tr>
152+
<td><a href="https://csrc.nist.gov/">NIST SP 800-92</a></td>
153+
<td><a href="https://csrc.nist.gov/pubs/sp/800/92/final">2006 Guide to Computer Security Log Management</a></td>
154+
</tr>
155+
</table>
132156

133157
## Bibliography
134158

135-
<ul>
136-
<li>[cwe117] MITRE. “CWE-117: Improper Output Neutralization for Logs” [online]. Available from: <a href="https://cwe.mitre.org/data/definitions/117.html">https://cwe.mitre.org/data/definitions/117.html</a>. Accessed 23 September 2025.</li>
137-
<li>[cwe93] MITRE. “CWE-93: Improper Neutralization of CRLF Sequences ('CRLF Injection')” [online]. Available from: <a href="https://cwe.mitre.org/data/definitions/93.html">https://cwe.mitre.org/data/definitions/93.html</a>. Accessed 23 September 2025.</li>
138-
<li>[cwe113] MITRE. “CWE-113: Improper Neutralization of CRLF Sequences in HTTP Headers” [online]. Available from: <a href="https://cwe.mitre.org/data/definitions/113.html">https://cwe.mitre.org/data/definitions/113.html</a>. Accessed 23 September 2025.</li>
139-
<li>[capec93] MITRE. “CAPEC-93: Log Injection‑Tampering‑Forging” [online]. Available from: <a href="https://capec.mitre.org/data/definitions/93.html">https://capec.mitre.org/data/definitions/93.html</a>. Accessed 23 September 2025.</li>
140-
<li>[nist80092] Kent, K.; Souppaya, M. “NIST Special Publication 800‑92: Guide to Computer Security Log Management” [online]. Available from: <a href="https://nvlpubs.nist.gov/nistpubs/Legacy/SP/nistspecialpublication800-92.pdf">https://nvlpubs.nist.gov/nistpubs/Legacy/SP/nistspecialpublication800-92.pdf</a>. Accessed 23 September 2025.</li>
141-
<li>[owasp_asvs] OWASP. “Application Security Verification Standard 4.x” [online]. Available from: <a href="https://owasp.org/www-project-application-security-verification-standard/">https://owasp.org/www-project-application-security-verification-standard/</a>. Accessed 23 September 2025.</li>
142-
<li>[owasp_top10_2021] OWASP. “OWASP Top 10 — 2021: A09 Security Logging and Monitoring Failures” [online]. Available from: <a href="https://owasp.org/Top10/A09_2021-Security_Logging_and_Monitoring_Failures/">https://owasp.org/Top10/A09_2021-Security_Logging_and_Monitoring_Failures/</a>. Accessed 23 September 2025.</li>
143-
<li>[codeql] GitHub. “Log Injection — CodeQL query help (Python)” [online]. Available from: <a href="https://codeql.github.com/codeql-query-help/python/py-log-injection/">https://codeql.github.com/codeql-query-help/python/py-log-injection/</a>. Accessed 23 September 2025.</li>
144-
<li>[veracode] Veracode. “How to Fix CWE‑117 — Improper Output Neutralization for Logs” [online]. Available from: <a href="https://community.veracode.com/s/article/How-to-Fix-CWE-117-Improper-Output-Neutralization-for-Logs">https://community.veracode.com/s/article/How-to-Fix-CWE-117-Improper-Output-Neutralization-for-Logs</a>. Accessed 23 September 2025.</li>
145-
<li>[iso24772] ISO/IEC. “TR 24772:2013 — Programming languages — Guidance to avoiding vulnerabilities in programming languages through language selection and use (Withdrawn)” [online]. Available from: <a href="https://www.iso.org/standard/61457.html">https://www.iso.org/standard/61457.html</a>. Accessed 23 September 2025.</li>
146-
</ul>
159+
<table>
160+
<tr>
161+
<td>[OWASP ASVS 4.0]</td>
162+
<td>Python Software Foundation. (2024). concurrent.futures — Launching parallel tasks [online]. Available from: <a href="https://docs.python.org/3.10/library/concurrent.futures.html">https://docs.python.org/3.10/library/concurrent.futures.html</a>, [Accessed 18 September 2025]</td>
163+
</tr>
164+
</table>

0 commit comments

Comments
 (0)