Skip to content

Commit 721ff5f

Browse files
committed
Tidy up references and add more precise citations
Signed-off-by: emcdtho <[email protected]>
1 parent f9474c5 commit 721ff5f

File tree

1 file changed

+23
-33
lines changed
  • docs/Secure-Coding-Guide-for-Python/CWE-707/CWE-117

1 file changed

+23
-33
lines changed

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

Lines changed: 23 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -2,17 +2,19 @@
22

33
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 (see [*Attacks on Logs*](https://cheatsheetseries.owasp.org/cheatsheets/Logging_Cheat_Sheet.html#attacks-on-logs) [[OWASP 2025]](https://cheatsheetseries.owasp.org/cheatsheets/Logging_Cheat_Sheet.html#attacks-on-logs)) by submitting strings containing CRLF sequences that create fake log entries.
6+
57
Attackers can exploit this weakness by submitting strings containing Carriage Return Line Feed (CRLF) 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.
68

79
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.
810

9-
The OWASP Top 10 [[OWASP A09:2021](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.
11+
The OWASP Top 10 [[OWASP A09:2021](https://owasp.org/Top10/A09_2021-Security_Logging_and_Monitoring_Failures/)] lists “Security Logging and Monitoring Failures” as a critical security risk.
1012

1113
## Noncompliant Code Example
1214

1315
This example demonstrates how raw user input written to logs enables injection attacks:
1416

15-
_[noncompliant01.py](noncompliant01.py):_
17+
*[noncompliant01.py](noncompliant01.py):*
1618

1719
```python
1820
""" Non-compliant Code Example """
@@ -39,9 +41,11 @@ The attacker's input creates what appears to be a legitimate log entry showing a
3941

4042
## Compliant Solution
4143

44+
As per the OWASP Logging Cheat Sheet [[OWASP 2025]](https://cheatsheetseries.owasp.org/cheatsheets/Logging_Cheat_Sheet.html) section on ["Event collection"](https://cheatsheetseries.owasp.org/cheatsheets/Logging_Cheat_Sheet.html#event-collection), applications should sanitize event data to prevent log injection and encode data correctly for the logged format.
45+
4246
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.
4347

44-
_[compliant01.py](compliant01.py):_
48+
*[compliant01.py](compliant01.py):*
4549

4650
```python
4751
""" Compliant Code Example """
@@ -104,12 +108,6 @@ WARNING:root:Rejected login attempt: invalid username="guest'\nWARNING:root:User
104108
<td>Not Available</td>
105109
<td></td>
106110
</tr>
107-
<tr>
108-
<td>PyLint</td>
109-
<td>2.17</td>
110-
<td>Not Available</td>
111-
<td></td>
112-
</tr>
113111
<tr>
114112
<td>CodeQL</td>
115113
<td>Latest</td>
@@ -130,49 +128,50 @@ WARNING:root:Rejected login attempt: invalid username="guest'\nWARNING:root:User
130128
<table>
131129
<tr>
132130
<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 [CWE-707] </a></td>
131+
<td>Pillar: <a href="https://cwe.mitre.org/data/definitions/707.html"> CWE-707: Improper Neutralization</a></td>
134132
</tr>
135133
<tr>
136134
<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>[CWE-117]</td>
135+
<td>Base: <a href="https://cwe.mitre.org/data/definitions/117.html">CWE-117: Improper Output Neutralization for Log </a></td>
138136
</tr>
139137
<tr>
140138
<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>[CWE-93]</td>
139+
<td>Base: <a href="https://cwe.mitre.org/data/definitions/93.html">CWE-93: Improper Neutralization of CRLF Sequences ('CRLF Injection') </a></td>
142140
</tr>
143141
<tr>
144142
<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>[CWE-113]</td>
143+
<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>
146144
</tr>
147145
<tr>
148146
<td><a href="http://capec.mitre.org/">MITRE CAPEC</a></td>
149-
<td>Detailed: <a href="https://capec.mitre.org/data/definitions/93.html">CAPEC-93: Log Injection-Tampering-Forging </a>[CAPEC-93]</td>
147+
<td>Detailed: <a href="https://capec.mitre.org/data/definitions/93.html">CAPEC-93: Log Injection-Tampering-Forging </a></td>
150148
</tr>
151149
<tr>
152150
<td><a href="https://owasp.org/Top10/">OWASP Top 10</a></td>
153-
<td><a href="https://owasp.org/Top10/A09_2021-Security_Logging_and_Monitoring_Failures/">A09:2021 – Security Logging and Monitoring Failures </a>[OWASP A09:2021]</td>
151+
<td><a href="https://owasp.org/Top10/A09_2021-Security_Logging_and_Monitoring_Failures/">A09:2021 – Security Logging and Monitoring Failures </a></td>
154152
</tr>
155153
<tr>
156154
<td><a href="https://owasp.org/">OWASP ASVS 4.0</a></td>
157-
<td><a href="https://owasp.org/www-project-application-security-verification-standard/">OWASP Application Security Verification Standard (ASVS) </a>[OWASP ASVS 4.0]</td>
155+
<td><a href="https://owasp.org/www-project-application-security-verification-standard/">OWASP Application Security Verification Standard (ASVS) </a>. See "V16 Security Logging and Error Handling".
156+
</td>
157+
<tr>
158+
<td><a href="https://cheatsheetseries.owasp.org/index.html">OWASP Cheat Sheet Series</a></td>
159+
<td><a href="https://cheatsheetseries.owasp.org/cheatsheets/Logging_Cheat_Sheet.html">OWASP Logging Cheat Sheet</a></td>
160+
</tr>
158161
</tr>
159162
<tr>
160163
<td>ISO/IEC TR 24772:2013</td>
161-
<td><a href="https://www.iso.org/standard/61457.html">ISO/IEC TR 24772:2013 Information technology — Programming languages — Guidance to avoiding vulnerabilities in programming languages through language selection and use </a>[ISO 24772:2013]</td>
164+
<td><a href="https://www.iso.org/standard/61457.html">ISO/IEC TR 24772:2013 Information technology — Programming languages — Guidance to avoiding vulnerabilities in programming languages through language selection and use </a></td>
162165
</tr>
163166
<tr>
164167
<td>NIST SP 800-92</td>
165-
<td><a href="https://csrc.nist.gov/pubs/sp/800/92/final">NIST SP 800-92 Guide to Computer Security Log Management </a>[NIST SP 800-92]</td>
168+
<td><a href="https://csrc.nist.gov/pubs/sp/800/92/final">NIST SP 800-92 Guide to Computer Security Log Management </a></td>
166169
</tr>
167170
</table>
168171

169172
## Bibliography
170173

171174
<table>
172-
<tr>
173-
<td>[CWE-707]</a></td>
174-
<td>CWE-707: Improper Neutralization [online]. Available from <a href="https://cwe.mitre.org/data/definitions/707.html">https://cwe.mitre.org/data/definitions/707.html</a>, [Accessed 24 September 2025]</td>
175-
</tr>
176175
<tr>
177176
<td>[CWE-117]</a></td>
178177
<td>CWE-117: Improper Output Neutralization for Log [online]. Available from <a href="https://cwe.mitre.org/data/definitions/117.html">https://cwe.mitre.org/data/definitions/117.html</a>, [Accessed 24 September 2025]</td>
@@ -194,16 +193,7 @@ WARNING:root:Rejected login attempt: invalid username="guest'\nWARNING:root:User
194193
<td>A09:2021 – 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 24 September 2025]</td>
195194
</tr>
196195
<tr>
197-
<td>[OWASP ASVS 4.0]</td>
198-
<td>OWASP Application Security Verification Standard (ASVS) [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 24 September 2025]</td>
199-
</tr>
200-
<tr>
201-
<td>[ISO 24772:2013]</td>
202-
<td>ISO/IEC TR 24772:2013 Information technology — Programming languages — Guidance to avoiding vulnerabilities in programming languages through language selection and use [online]. Available from:
203-
<a href="https://www.iso.org/standard/61457.html">https://www.iso.org/standard/61457.html</a>, [Accessed 24 September 2025]</td>
204-
</tr>
205-
<tr>
206-
<td>[NIST SP 800-92]</td>
207-
<td>NIST SP 800-92 Guide to Computer Security Log Management [online]. Available from:<a href="https://csrc.nist.gov/pubs/sp/800/92/final">https://csrc.nist.gov/pubs/sp/800/92/final</a>, [Accessed 24 September 2025]</td>
196+
<td>[OWASP 2025]</td>
197+
<td>OWASP Cheat Sheet Series: Logging Cheat Sheet [online]. Available from: <a href="https://cheatsheetseries.owasp.org/cheatsheets/Logging_Cheat_Sheet.html">https://cheatsheetseries.owasp.org/cheatsheets/Logging_Cheat_Sheet.html</a> (see “Event collection” and “Attacks on Logs”). [Accessed 24 September 2025]</td>
208198
</tr>
209199
</table>

0 commit comments

Comments
 (0)