Skip to content

Commit

Permalink
Merge pull request #2 from faraazahmad/detect-params
Browse files Browse the repository at this point in the history
feat: use hash as taint source
  • Loading branch information
faraazahmad authored Nov 4, 2023
2 parents 158bc8e + c505304 commit b7a980a
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 4 deletions.
13 changes: 10 additions & 3 deletions lib/tainted/static.rb
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,17 @@ def visit(node)

def parse_assign(node)
variable_name = node.target.value.value
# pp node.value.class
return unless node.value.is_a?(SyntaxTree::CallNode)

method_name = node.value.message.value
method_name =
case node.value
when SyntaxTree::CallNode
node.value.message.value
when SyntaxTree::ARef
# (aref (vcall (ident "<method_name>")))
node.value.collection.value.value
end

return if method_name.nil?
return unless @sources.include?(method_name&.to_sym)

State.instance.var_dependencies[variable_name.to_sym][:tainted] = true
Expand Down
2 changes: 1 addition & 1 deletion lib/tainted/version.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# frozen_string_literal: true

module Tainted
VERSION = "0.1.0"
VERSION = "0.2.0"
end
9 changes: 9 additions & 0 deletions spec/fixtures/params.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
# frozen_string_literal: true

a = params[:insecure]
b = a + 1
c = b + 2
d = b + c

sql = "select * from users where age = #{d};"
execute(sql)
12 changes: 12 additions & 0 deletions spec/lib/tainted/lint_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,5 +14,17 @@
]
)
end

it "returns issue for sql query from unsanitized param" do
file = File.expand_path "#{__dir__}/../../fixtures/params.rb"
lint = Tainted::Lint.new(file, %i[params], %i[execute])
result = lint.analyze

expect(result).to eq(
[
"Method `execute()` consuming tainted variable `sql`",
]
)
end
end
end

0 comments on commit b7a980a

Please sign in to comment.