-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathruby_on_rail_baseline.yaml
182 lines (162 loc) · 5.23 KB
/
ruby_on_rail_baseline.yaml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
# ==========================================================
# Semgrep Ruleset for Ruby and Ruby Frameworks Security
# Created by: Conviso
# Description: This ruleset is designed to detect common
# vulnerabilities in Ruby applications, including Rails,
# Sinatra, Hanami, and Padrino, covering SQL Injection,
# Mass Assignment, Command Injection, and Path Traversal.
# ==========================================================
rules:
- id: detect-sql-injection-rails
languages: [ruby]
message: |
Possible SQL Injection vulnerability in Rails ActiveRecord query. Avoid using unsanitized user input.
severity: ERROR
patterns:
- pattern: |
User.where("name = '#{params[:name]}'")
fix: |
Use parameterized queries with ActiveRecord to avoid SQL Injection. Example:
```ruby
User.where("name = ?", params[:name])
```
metadata:
cwe: CWE-89
owasp: A1 Injection
- id: detect-sql-injection-sinatra
languages: [ruby]
message: |
Possible SQL Injection vulnerability in Sinatra database query. Avoid using unsanitized user input.
severity: ERROR
patterns:
- pattern: |
DB.execute("SELECT * FROM users WHERE name = '" + params[:name] + "'")
fix: |
Use parameterized queries to avoid SQL Injection in Sinatra. Example:
```ruby
DB.execute("SELECT * FROM users WHERE name = ?", [params[:name]])
```
metadata:
cwe: CWE-89
owasp: A1 Injection
- id: detect-sql-injection-hanami
languages: [ruby]
message: |
Possible SQL Injection vulnerability in Hanami query. Avoid using unsanitized user input.
severity: ERROR
patterns:
- pattern: |
repo.where("name = '#{params[:name]}'")
fix: |
Use parameterized queries in Hanami to prevent SQL Injection. Example:
```ruby
repo.where(name: params[:name])
```
metadata:
cwe: CWE-89
owasp: A1 Injection
- id: detect-sql-injection-padrino
languages: [ruby]
message: |
Possible SQL Injection vulnerability in Padrino ActiveRecord query. Avoid using unsanitized user input.
severity: ERROR
patterns:
- pattern: |
User.where("name = '#{params[:name]}'")
fix: |
Use parameterized queries with ActiveRecord in Padrino. Example:
```ruby
User.where("name = ?", params[:name])
```
metadata:
cwe: CWE-89
owasp: A1 Injection
- id: detect-mass-assignment-rails
languages: [ruby]
message: |
Possible Mass Assignment vulnerability. Avoid using unsanitized user input in `new` or `update`.
severity: ERROR
patterns:
- pattern: |
User.new(params[:user])
- pattern: |
@user.update(params[:user])
fix: |
Use strong parameters to whitelist allowed attributes. Example:
```ruby
params.require(:user).permit(:name, :email)
```
metadata:
cwe: CWE-915
owasp: A4 Insecure Design
- id: detect-command-injection-ruby
languages: [ruby]
message: |
Possible Command Injection vulnerability. Avoid using unsanitized user input in system commands.
severity: ERROR
patterns:
- pattern: |
`#{params[:command]}`
- pattern: |
system(params[:command])
fix: |
Use `system()` or backticks with sanitized inputs to avoid Command Injection. Example:
```ruby
system("safe_command", params[:command])
```
metadata:
cwe: CWE-78
owasp: A1 Injection
- id: detect-path-traversal-ruby
languages: [ruby]
message: |
Possible Path Traversal vulnerability. Avoid using unsanitized user input in file paths.
severity: ERROR
patterns:
- pattern: |
File.read(params[:file_path])
- pattern: |
File.open(params[:file_path])
fix: |
Use `File.expand_path` or validate input paths to avoid Path Traversal. Example:
```ruby
safe_path = File.expand_path(params[:file_path])
File.read(safe_path)
```
metadata:
cwe: CWE-22
owasp: A5 Broken Access Control
- id: detect-insecure-deserialization-ruby
languages: [ruby]
message: |
Possible Insecure Deserialization vulnerability. Avoid deserializing untrusted user input.
severity: ERROR
patterns:
- pattern: |
Marshal.load(params[:data])
fix: |
Avoid using `Marshal.load()` with untrusted data or use safer alternatives like JSON. Example:
```ruby
data = JSON.parse(params[:data])
```
metadata:
cwe: CWE-502
owasp: A8 Insecure Deserialization
- id: detect-sensitive-data-exposure-ruby
languages: [ruby]
message: |
Sensitive data exposure. Avoid logging sensitive information such as passwords or credit card numbers.
severity: WARNING
patterns:
- pattern: |
logger.debug(params[:password])
- pattern: |
puts params[:credit_card]
fix: |
Mask sensitive data before logging or output. Example:
```ruby
logger.debug(mask_sensitive_data(params[:password]))
```
metadata:
cwe: CWE-200
owasp: A3 Sensitive Data Exposure