tainted 0.1.0 → 0.3.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +7 -2
- data/Rakefile +1 -1
- data/lib/tainted/lint.rb +2 -2
- data/lib/tainted/offense.rb +12 -0
- data/lib/tainted/static.rb +17 -7
- data/lib/tainted/version.rb +1 -1
- data/lib/tainted.rb +1 -0
- metadata +3 -3
- data/fixtures/simple.rb +0 -8
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 278da9234147c4a8df18795ca9666877032253e8cb4409219ba0fd8e4420444b
|
4
|
+
data.tar.gz: 16e24fa14406e9755b3f631809a23a13fcf255605b5f6a2f66fc60d27ecee27a
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: b1fdc6834f8e8727e6e7fa0328ddd4193d4a7433f3c020f16eacaa6d63ef61f96b682a7a7e8b34db7e39d28a4554c77373d96467bb3a9cab8b8b00348d4b0fd0
|
7
|
+
data.tar.gz: 96b9a1687308bed7f57317dd66ece9eca69a7d0e2a7544cc8e40861017911d447aa11244daf44d5e3d27620358e80150e117b008c3a7a97b76e633608ff73f31
|
data/README.md
CHANGED
@@ -29,8 +29,13 @@ require 'tainted'
|
|
29
29
|
file = "#{__dir__}/../fixtures/simple.rb"
|
30
30
|
lint = Tainted::Lint.new(file, %i[tainted], %i[unsafe])
|
31
31
|
lint.analyze
|
32
|
-
|
33
|
-
|
32
|
+
=>
|
33
|
+
[#<Tainted::Offense:0x0000000107caf690
|
34
|
+
@message="Method `unsafe()` consuming tainted variable `d`",
|
35
|
+
@node=(call nil nil (ident "unsafe") (arg_paren (args ((var_ref (ident "d"))))))>,
|
36
|
+
#<Tainted::Offense:0x0000000107caf5f0
|
37
|
+
@message="Method `unsafe()` consuming tainted variable `c`",
|
38
|
+
@node=(call nil nil (ident "unsafe") (arg_paren (args ((var_ref (ident "c"))))))>]
|
34
39
|
```
|
35
40
|
|
36
41
|
## Development
|
data/Rakefile
CHANGED
data/lib/tainted/lint.rb
CHANGED
@@ -5,7 +5,7 @@ module Tainted
|
|
5
5
|
def initialize(filepath, sources, sinks)
|
6
6
|
@filepath = filepath
|
7
7
|
|
8
|
-
t =
|
8
|
+
t = DataFlow.new(@filepath)
|
9
9
|
t.generate
|
10
10
|
var_dependencies = t.tainted
|
11
11
|
State.instance.var_dependencies = var_dependencies
|
@@ -15,7 +15,7 @@ module Tainted
|
|
15
15
|
|
16
16
|
def analyze
|
17
17
|
@visitor.visit(SyntaxTree.parse_file(@filepath))
|
18
|
-
@visitor.
|
18
|
+
@visitor.offenses
|
19
19
|
end
|
20
20
|
end
|
21
21
|
end
|
data/lib/tainted/static.rb
CHANGED
@@ -2,13 +2,14 @@
|
|
2
2
|
|
3
3
|
module Tainted
|
4
4
|
class Static < SyntaxTree::Visitor
|
5
|
-
attr_reader :
|
5
|
+
attr_reader :offenses
|
6
6
|
|
7
|
-
def initialize(sources,
|
7
|
+
def initialize(sources, sinks)
|
8
8
|
super()
|
9
9
|
|
10
10
|
@sources = sources
|
11
|
-
@
|
11
|
+
@sinks = sinks
|
12
|
+
@offenses = []
|
12
13
|
end
|
13
14
|
|
14
15
|
def visit(node)
|
@@ -29,10 +30,17 @@ module Tainted
|
|
29
30
|
|
30
31
|
def parse_assign(node)
|
31
32
|
variable_name = node.target.value.value
|
32
|
-
# pp node.value.class
|
33
|
-
return unless node.value.is_a?(SyntaxTree::CallNode)
|
34
33
|
|
35
|
-
method_name =
|
34
|
+
method_name =
|
35
|
+
case node.value
|
36
|
+
when SyntaxTree::CallNode
|
37
|
+
node.value.message.value
|
38
|
+
when SyntaxTree::ARef
|
39
|
+
# (aref (vcall (ident "<method_name>")))
|
40
|
+
node.value.collection.value.value
|
41
|
+
end
|
42
|
+
|
43
|
+
return if method_name.nil?
|
36
44
|
return unless @sources.include?(method_name&.to_sym)
|
37
45
|
|
38
46
|
State.instance.var_dependencies[variable_name.to_sym][:tainted] = true
|
@@ -45,10 +53,12 @@ module Tainted
|
|
45
53
|
arguments.map { |arg| [arg, taint_status(arg.value.value.to_sym)] }
|
46
54
|
|
47
55
|
method_name = node.message.value
|
56
|
+
return unless @sinks.include?(method_name.to_sym)
|
57
|
+
|
48
58
|
taint_statuses.each do |status|
|
49
59
|
next unless status[1]
|
50
60
|
|
51
|
-
@
|
61
|
+
@offenses << Offense.new(node, "Method `#{method_name}()` consuming tainted variable `#{status[0].value.value}`")
|
52
62
|
end
|
53
63
|
end
|
54
64
|
|
data/lib/tainted/version.rb
CHANGED
data/lib/tainted.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: tainted
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.3.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Syed Faraaz Ahmad
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2023-
|
11
|
+
date: 2023-11-09 00:00:00.000000000 Z
|
12
12
|
dependencies: []
|
13
13
|
description:
|
14
14
|
email:
|
@@ -23,10 +23,10 @@ files:
|
|
23
23
|
- LICENSE.txt
|
24
24
|
- README.md
|
25
25
|
- Rakefile
|
26
|
-
- fixtures/simple.rb
|
27
26
|
- lib/tainted.rb
|
28
27
|
- lib/tainted/dataflow.rb
|
29
28
|
- lib/tainted/lint.rb
|
29
|
+
- lib/tainted/offense.rb
|
30
30
|
- lib/tainted/state.rb
|
31
31
|
- lib/tainted/static.rb
|
32
32
|
- lib/tainted/version.rb
|