Skip to content

Commit 2182bf1

Browse files
authored
Merge pull request #14160 from erik-krogh/py-clear-text-log-help
Py: add new qhelp for clear-text-logging
2 parents df2b313 + bf3fe3c commit 2182bf1

File tree

3 files changed

+36
-1
lines changed

3 files changed

+36
-1
lines changed

python/ql/src/Security/CWE-312/CleartextLogging.qhelp

Lines changed: 30 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,33 @@
22
"-//Semmle//qhelp//EN"
33
"qhelp.dtd">
44
<qhelp>
5-
<include src="CleartextStorage.qhelp" /></qhelp>
5+
6+
<overview>
7+
8+
<p>If sensitive data is written to a log entry it could be exposed to an attacker
9+
who gains access to the logs.</p>
10+
11+
<p>Potential attackers can obtain sensitive user data when the log output is displayed. Additionally that data may
12+
expose system information such as full path names, system information, and sometimes usernames and passwords.</p>
13+
</overview>
14+
15+
<recommendation>
16+
<p>
17+
Sensitive data should not be logged.
18+
</p>
19+
</recommendation>
20+
21+
<example>
22+
<p>In the example the entire process environment is logged using `print`. Regular users of the production deployed application
23+
should not have access to this much information about the environment configuration.
24+
</p>
25+
<sample src="examples/CleartextLogging.py" />
26+
27+
<p> In the second example the data that is logged is not sensitive.</p>
28+
<sample src="examples/CleartextLoggingGood.py" />
29+
</example>
30+
31+
<references>
32+
<li>OWASP: <a href="https://owasp.org/Top10/A09_2021-Security_Logging_and_Monitoring_Failures/">Insertion of Sensitive Information into Log File</a>.</li>
33+
</references>
34+
</qhelp>
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
# BAD: Logging cleartext sensitive data
2+
import os
3+
print(f"[INFO] Environment: {os.environ}")
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
not_sensitive_data = {'a': 1, 'b': 2}
2+
# GOOD: it is fine to log data that is not sensitive
3+
print(f"[INFO] Some object contains: {not_sensitive_data}")

0 commit comments

Comments
 (0)