Skip to content

Commit 186623f

Browse files
committed
Ruby: Add CleartextLogging.qhelp
1 parent 7ed4478 commit 186623f

File tree

3 files changed

+72
-0
lines changed

3 files changed

+72
-0
lines changed
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
<!DOCTYPE qhelp PUBLIC
2+
"-//Semmle//qhelp//EN"
3+
"qhelp.dtd">
4+
<qhelp>
5+
6+
<overview>
7+
<p>
8+
Sensitive information that is stored unencrypted is accessible to an attacker
9+
who gains access to the storage.
10+
</p>
11+
</overview>
12+
13+
<recommendation>
14+
<p>
15+
Ensure that sensitive information is always encrypted before being stored.
16+
</p>
17+
<p>
18+
In general, decrypt sensitive information only at the point where it is
19+
necessary for it to be used in cleartext.
20+
</p>
21+
22+
<p>
23+
24+
Be aware that external processes often store the <code>standard
25+
out</code> and <code>standard error</code> streams of the application,
26+
causing logged sensitive information to be stored as well.
27+
28+
</p>
29+
30+
</recommendation>
31+
32+
<example>
33+
<p>
34+
The following example code logs user credentials (in this case, their password)
35+
to <code>standard out</code> in plaintext:
36+
</p>
37+
<sample src="examples/CleartextLoggingBad.rb"/>
38+
<p>
39+
Instead, the credentials should be masked or redacted before logging:
40+
</p>
41+
<sample src="examples/CleartextLoggingGood.rb"/>
42+
</example>
43+
44+
45+
<references>
46+
47+
<li>M. Dowd, J. McDonald and J. Schuhm, <i>The Art of Software Security Assessment</i>, 1st Edition, Chapter 2 - 'Common Vulnerabilities of Encryption', p. 43. Addison Wesley, 2006.</li>
48+
<li>M. Howard and D. LeBlanc, <i>Writing Secure Code</i>, 2nd Edition, Chapter 9 - 'Protecting Secret Data', p. 299. Microsoft, 2002.</li>
49+
50+
</references>
51+
</qhelp>
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
require 'Logger'
2+
3+
class UserSession
4+
@@logger = Logger.new STDOUT
5+
6+
def login(username, password)
7+
# ...
8+
@@logger.info "login with password: #{password})"
9+
end
10+
end
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
require 'Logger'
2+
3+
class UserSession
4+
@@logger = Logger.new STDOUT
5+
6+
def login(username, password)
7+
# ...
8+
password_escaped = password.sub(/.*/, "[redacted]")
9+
@@logger.info "login with password: #{password_escaped})"
10+
end
11+
end

0 commit comments

Comments
 (0)