diff --git a/ruby/ql/test/query-tests/security/cwe-079/ReflectedXSS.qlref b/ruby/ql/test/query-tests/security/cwe-079/ReflectedXSS.qlref
index 5ab6c6da840..af140959abb 100644
--- a/ruby/ql/test/query-tests/security/cwe-079/ReflectedXSS.qlref
+++ b/ruby/ql/test/query-tests/security/cwe-079/ReflectedXSS.qlref
@@ -1,2 +1 @@
-query: queries/security/cwe-079/ReflectedXSS.ql
-postprocess: utils/test/InlineExpectationsTestQuery.ql
+queries/security/cwe-079/ReflectedXSS.ql
diff --git a/ruby/ql/test/query-tests/security/cwe-079/StoredXSS.qlref b/ruby/ql/test/query-tests/security/cwe-079/StoredXSS.qlref
index ed8577c438d..78de28cb282 100644
--- a/ruby/ql/test/query-tests/security/cwe-079/StoredXSS.qlref
+++ b/ruby/ql/test/query-tests/security/cwe-079/StoredXSS.qlref
@@ -1,2 +1 @@
-query: queries/security/cwe-079/StoredXSS.ql
-postprocess: utils/test/InlineExpectationsTestQuery.ql
+queries/security/cwe-079/StoredXSS.ql
\ No newline at end of file
diff --git a/ruby/ql/test/query-tests/security/cwe-079/UnsafeHtmlConstruction.qlref b/ruby/ql/test/query-tests/security/cwe-079/UnsafeHtmlConstruction.qlref
index 501577ea1b9..ae814bcc35c 100644
--- a/ruby/ql/test/query-tests/security/cwe-079/UnsafeHtmlConstruction.qlref
+++ b/ruby/ql/test/query-tests/security/cwe-079/UnsafeHtmlConstruction.qlref
@@ -1,2 +1 @@
-query: queries/security/cwe-079/UnsafeHtmlConstruction.ql
-postprocess: utils/test/InlineExpectationsTestQuery.ql
+queries/security/cwe-079/UnsafeHtmlConstruction.ql
\ No newline at end of file
diff --git a/ruby/ql/test/query-tests/security/cwe-079/app/controllers/foo/bars_controller.rb b/ruby/ql/test/query-tests/security/cwe-079/app/controllers/foo/bars_controller.rb
index 8b855847f69..4146cc29953 100644
--- a/ruby/ql/test/query-tests/security/cwe-079/app/controllers/foo/bars_controller.rb
+++ b/ruby/ql/test/query-tests/security/cwe-079/app/controllers/foo/bars_controller.rb
@@ -6,34 +6,34 @@ class BarsController < ApplicationController
end
def user_name
- return params[:user_name] # $ Source[rb/reflected-xss]
+ return params[:user_name]
end
def user_name_memo
- @user_name ||= params[:user_name] # $ Source[rb/reflected-xss]
+ @user_name ||= params[:user_name]
end
def show
- @user_website = params[:website] # $ Source[rb/reflected-xss]
- dt = params[:text] # $ Source[rb/reflected-xss]
+ @user_website = params[:website]
+ dt = params[:text]
@instance_text = dt
@safe_foo = params[:text]
@safe_foo = "safe_foo"
@html_escaped = ERB::Util.html_escape(params[:text])
@header_escaped = ERB::Util.html_escape(cookies[:foo]) # OK - cookies not controllable by 3rd party
- response.header["content-type"] = params[:content_type] # $ Alert[rb/reflected-xss]
+ response.header["content-type"] = params[:content_type]
response.header["x-customer-header"] = params[:bar] # OK - header not relevant to XSS
render "foo/bars/show", locals: { display_text: dt, safe_text: "hello" }
end
def make_safe_html
- str = params[:user_name] # $ Source[rb/reflected-xss]
- str.html_safe # $ Alert[rb/reflected-xss]
+ str = params[:user_name]
+ str.html_safe
- translate("welcome", name: params[:user_name]).html_safe # $ Alert[rb/reflected-xss] // NOT OK - translate preserves taint
- t("welcome", name: params[:user_name]).html_safe # $ Alert[rb/reflected-xss] // NOT OK - t is an alias of translate
+ translate("welcome", name: params[:user_name]).html_safe # NOT OK - translate preserves taint
+ t("welcome", name: params[:user_name]).html_safe # NOT OK - t is an alias of translate
t("welcome_html", name: params[:user_name]).html_safe # OK - t escapes html when key ends in _html
- I18n.t("welcome_html", name: params[:user_name]).html_safe # $ Alert[rb/reflected-xss] // NOT OK - I18n.t does not escape html
- I18n.translate("welcome_html", name: params[:user_name]).html_safe # $ Alert[rb/reflected-xss] // NOT OK - alias
+ I18n.t("welcome_html", name: params[:user_name]).html_safe # NOT OK - I18n.t does not escape html
+ I18n.translate("welcome_html", name: params[:user_name]).html_safe # NOT OK - alias
end
end
diff --git a/ruby/ql/test/query-tests/security/cwe-079/app/controllers/foo/stores_controller.rb b/ruby/ql/test/query-tests/security/cwe-079/app/controllers/foo/stores_controller.rb
index 84918d48c4d..6dbb2508353 100644
--- a/ruby/ql/test/query-tests/security/cwe-079/app/controllers/foo/stores_controller.rb
+++ b/ruby/ql/test/query-tests/security/cwe-079/app/controllers/foo/stores_controller.rb
@@ -5,7 +5,7 @@ class StoresController < ApplicationController
end
def show
- dt = File.read("foo.txt") # $ Source[rb/stored-xss]
+ dt = File.read("foo.txt")
@instance_text = dt
@user = User.find 1
@safe_user_handle = ERB::Util.html_escape(@user.handle)
diff --git a/ruby/ql/test/query-tests/security/cwe-079/app/views/foo/bars/_widget.html.erb b/ruby/ql/test/query-tests/security/cwe-079/app/views/foo/bars/_widget.html.erb
index cbd27d512dc..54b52afe8c7 100644
--- a/ruby/ql/test/query-tests/security/cwe-079/app/views/foo/bars/_widget.html.erb
+++ b/ruby/ql/test/query-tests/security/cwe-079/app/views/foo/bars/_widget.html.erb
@@ -2,10 +2,10 @@
<%= raw @display_text %>
<%# BAD: A local rendered raw as a local variable %>
-<%= raw display_text %> <%# $ Alert[rb/reflected-xss], Alert[rb/stored-xss] %>
+<%= raw display_text %>
<%# BAD: A local rendered raw via the local_assigns hash %>
-<%= raw local_assigns[:display_text] %> <%# $ Alert[rb/reflected-xss], Alert[rb/stored-xss] %>
+<%= raw local_assigns[:display_text] %>
<%# GOOD: A local rendered with default escaping via the local_assigns hash %>
<%= local_assigns[:display_text] %>
diff --git a/ruby/ql/test/query-tests/security/cwe-079/app/views/foo/bars/show.html.erb b/ruby/ql/test/query-tests/security/cwe-079/app/views/foo/bars/show.html.erb
index f821a423c70..b8092cd883f 100644
--- a/ruby/ql/test/query-tests/security/cwe-079/app/views/foo/bars/show.html.erb
+++ b/ruby/ql/test/query-tests/security/cwe-079/app/views/foo/bars/show.html.erb
@@ -1,20 +1,20 @@
<%# BAD: An instance variable rendered without escaping %>
-website <%# $ Alert[rb/reflected-xss] %>
+website
<%# BAD: A local rendered raw as a local variable %>
-<%= raw display_text %> <%# $ Alert[rb/reflected-xss] %>
+<%= raw display_text %>
<%# BAD: A local rendered raw via the local_assigns hash %>
-<%= raw local_assigns[:display_text] %> <%# $ Alert[rb/reflected-xss] %>
+<%= raw local_assigns[:display_text] %>
<% key = :display_text %>
<%# BAD: A local rendered raw via the locals_assigns hash %>
-<%= raw local_assigns[key] %> <%# $ Alert[rb/reflected-xss] %>
+<%= raw local_assigns[key] %>
<% for key in [:display_text, :safe_text] do %>
<%# BAD: A local rendered raw via the locals hash %>
- - <%= raw local_assigns[key] %>
<%# $ Alert[rb/reflected-xss] %>
+ - <%= raw local_assigns[key] %>
<% end %>
@@ -32,28 +32,28 @@
<%# BAD: html_safe marks string as not requiring HTML escaping %>
<%=
- display_text.html_safe <%# $ Alert[rb/reflected-xss] %>
+ display_text.html_safe
%>
<%# BAD: html_safe marks string as not requiring HTML escaping %>
<%=
- @instance_text.html_safe <%# $ Alert[rb/reflected-xss] %>
+ @instance_text.html_safe
%>
<%= render partial: 'foo/bars/widget', locals: { display_text: "widget_" + display_text } %>
<%# BAD: user_name is a helper method that returns unsanitized user-input %>
-<%= user_name.html_safe %> <%# $ Alert[rb/reflected-xss] %>
+<%= user_name.html_safe %>
<%# BAD: user_name_memo is a helper method that returns unsanitized user-input %>
<%# TODO: we miss this because the return value from user_name_memo is not properly linked to this call %>
-<%= user_name_memo.html_safe %> <%# $ Alert[rb/reflected-xss] %>
+<%= user_name_memo.html_safe %>
<%# BAD: unsanitized user-input should not be passed to link_to as the URL %>
-<%= link_to "user website", params[:website] %> <%# $ Alert[rb/reflected-xss] %>
+<%= link_to "user website", params[:website] %>
<%# BAD: unsanitized user-input should not be passed to link_to as the URL %>
-<%= link_to params[:website], class: "user-link" do %> <%# $ Alert[rb/reflected-xss] %>
+<%= link_to params[:website], class: "user-link" do %>
user website
<% end %>
@@ -70,20 +70,20 @@
%>
<%# BAD: simple_format called with sanitize: false %>
-<%= simple_format(params[:comment], sanitize: false) %> <%# $ Alert[rb/reflected-xss] %>
+<%= simple_format(params[:comment], sanitize: false) %>
<%# BAD: javasript_include_tag called with remote input %>
-<%= javascript_include_tag params[:url] %> <%# $ Alert[rb/reflected-xss] %>
+<%= javascript_include_tag params[:url] %>
<%# GOOD: input is sanitized %>
<%= sanitize(params[:comment]).html_safe %>
<%# BAD: A local rendered raw as a local variable %>
-<%== display_text %> <%# $ Alert[rb/reflected-xss] %>
+<%== display_text %>
<%# BAD: translate preserves taint %>
-<%= raw translate("welcome", name: display_text) %> <%# $ Alert[rb/reflected-xss] %>
-<%= raw t("welcome", name: display_text) %> <%# $ Alert[rb/reflected-xss] %>
+<%= raw translate("welcome", name: display_text) %>
+<%= raw t("welcome", name: display_text) %>
<%# GOOD: translate sanitizes for html keys %>
<%= raw t("welcome1.html", name: display_text) %>
diff --git a/ruby/ql/test/query-tests/security/cwe-079/app/views/foo/stores/show.html.erb b/ruby/ql/test/query-tests/security/cwe-079/app/views/foo/stores/show.html.erb
index 16080cb948a..d8afec1c432 100644
--- a/ruby/ql/test/query-tests/security/cwe-079/app/views/foo/stores/show.html.erb
+++ b/ruby/ql/test/query-tests/security/cwe-079/app/views/foo/stores/show.html.erb
@@ -1,17 +1,17 @@
<%# BAD: A local rendered raw as a local variable %>
-<%= raw display_text %> <%# $ Alert[rb/stored-xss] %>
+<%= raw display_text %>
<%# BAD: A local rendered raw via the local_assigns hash %>
-<%= raw local_assigns[:display_text] %> <%# $ Alert[rb/stored-xss] %>
+<%= raw local_assigns[:display_text] %>
<% key = :display_text %>
<%# BAD: A local rendered raw via the locals_assigns hash %>
-<%= raw local_assigns[key] %> <%# $ Alert[rb/stored-xss] %>
+<%= raw local_assigns[key] %>
<% for key in [:display_text, :safe_text] do %>
<%# BAD: A local rendered raw via the locals hash %>
- - <%= raw local_assigns[key] %>
<%# $ Alert[rb/stored-xss] %>
+ - <%= raw local_assigns[key] %>
<% end %>
@@ -29,12 +29,12 @@
<%# BAD: html_safe marks string as not requiring HTML escaping %>
<%=
- display_text.html_safe <%# $ Alert[rb/stored-xss] %>
+ display_text.html_safe
%>
<%# BAD: html_safe marks string as not requiring HTML escaping %>
<%=
- @instance_text.html_safe <%# $ Alert[rb/stored-xss] %>
+ @instance_text.html_safe
%>
<%= render partial: 'foo/bars/widget', locals: { display_text: "widget_" + display_text } %>
@@ -43,7 +43,7 @@
<%= user_name_handle.html_safe %>
<%# BAD: Direct to a database value without escaping %>
-<%= @user.handle.html_safe %> <%# $ Alert[rb/stored-xss] %>
+<%= @user.handle.html_safe %>
<%# BAD: Indirect to a database value without escaping %>
<%= @user.raw_name.html_safe %>
@@ -60,7 +60,7 @@
<%# BAD: Direct to a database value without escaping %>
<%=
some_user = User.find 1
- some_user.handle.html_safe <%# $ Alert[rb/stored-xss] %>
+ some_user.handle.html_safe
%>
<%# BAD: Indirect to a database value without escaping (currently missed due to lack of 'self' handling in ORM tracking) %>
@@ -83,7 +83,7 @@
<%# BAD: Kernel.sprintf is a taint-step %>
<%=
- sprintf("%s", @user.handle).html_safe <%# $ Alert[rb/stored-xss] %>
+ sprintf("%s", @user.handle).html_safe
%>
<%# GOOD: The `foo.bar.baz` is not recognized as a source %>
diff --git a/ruby/ql/test/query-tests/security/cwe-079/lib/unsafeHtml.rb b/ruby/ql/test/query-tests/security/cwe-079/lib/unsafeHtml.rb
index 1e025ce6ba2..3f92d5938b1 100644
--- a/ruby/ql/test/query-tests/security/cwe-079/lib/unsafeHtml.rb
+++ b/ruby/ql/test/query-tests/security/cwe-079/lib/unsafeHtml.rb
@@ -1,27 +1,27 @@
class Foobar
- def create_user_description(name) # $ Source[rb/html-constructed-from-input]
- "#{name}
".html_safe # $ Alert[rb/html-constructed-from-input] // NOT OK - the parameter is not escaped
+ def create_user_description(name)
+ "#{name}
".html_safe # NOT OK - the parameter is not escaped
# escape
"#{ERB::Util.html_escape(name)}
".html_safe # OK - the parameter is escaped
end
- def string_like_literal name # $ Source[rb/html-constructed-from-input]
+ def string_like_literal name
h = <<-HTML
- #{name}
# $ Alert[rb/html-constructed-from-input]
+ #{name}
HTML
h.html_safe # NOT OK - the parameter is not escaped
end
- def sprintf_use name # $ Source[rb/html-constructed-from-input]
- sprintf("%s
", name).html_safe # $ Alert[rb/html-constructed-from-input] // NOT OK - the parameter is not escaped
+ def sprintf_use name
+ sprintf("%s
", name).html_safe # NOT OK - the parameter is not escaped
# escape
sprintf("%s
", ERB::Util.html_escape(name)).html_safe # OK - the parameter is escaped
end
- def create_user_description2(name) # $ Source[rb/html-constructed-from-input]
- "#{name}
".html_safe # $ Alert[rb/html-constructed-from-input] // NOT OK - the value is not necessarily HTML safe
+ def create_user_description2(name)
+ "#{name}
".html_safe # NOT OK - the value is not necessarily HTML safe
if name.html_safe?
"#{name}
".html_safe # OK - value is marked as being HTML safe