Skip to content

Commit d79a6dd

Browse files
committed
Ruby: Improve qhelp for rb/tainted-format-string
1 parent 0cfe37d commit d79a6dd

File tree

2 files changed

+11
-6
lines changed

2 files changed

+11
-6
lines changed

ruby/ql/src/queries/security/cwe-134/TaintedFormatString.qhelp

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -28,20 +28,20 @@ argument to <code>Kernel.printf</code> to be appended to the message:
2828
</p>
2929
<sample src="examples/tainted_format_string_bad.rb"/>
3030
<p>
31-
However, if a malicious user provides a format specified such as <code>%s</code> as their
32-
user name, <code>Kernel.printf</code> throw an exception that there are too few arguments
33-
to satisfy the format. This can result in denial of service or leaking of internal
34-
information to the attacker via a stack trace.
31+
However, if a malicious user provides a format specified such as <code>%s</code>
32+
as their user name, <code>Kernel.printf</code> will throw an exception as there
33+
are too few arguments to satisfy the format. This can result in denial of
34+
service or leaking of internal information to the attacker via a stack trace.
3535
</p>
3636
<p>
3737
Instead, the user name should be included using the <code>%s</code> specifier:
3838
</p>
3939
<sample src="examples/tainted_format_string_good.rb"/>
4040

4141
<p>
42-
Alternatively, a method such as <code>Kernel.puts</code> should be used, which does not
43-
apply string formatting to its arguments.
42+
Alternatively, string interpolation should be used exclusively:
4443
</p>
44+
<sample src="examples/tainted_format_string_interpolation.rb"/>
4545
</example>
4646

4747
<references>
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
class UsersController < ActionController::Base
2+
def index
3+
puts "Unauthorised access attempt by #{params[:user]}: #{request.ip}"
4+
end
5+
end

0 commit comments

Comments
 (0)