File tree Expand file tree Collapse file tree 2 files changed +38
-0
lines changed Expand file tree Collapse file tree 2 files changed +38
-0
lines changed Original file line number Diff line number Diff line change 184
184
end
185
185
end
186
186
187
+ context 'when the name has non-printable ascii characters' do
188
+ let ( :mod_options ) do
189
+ super ( ) . merge ( name : 'Testing human-readable printable ascii characters ≤' )
190
+ end
191
+
192
+ it 'has errors' do
193
+ expect ( subject . errors . full_messages ) . to eq [ 'Name must only contain human-readable printable ascii characters' ]
194
+ end
195
+ end
196
+
187
197
context 'when the module file path is not snake case' do
188
198
let ( :mod_options ) do
189
199
super ( ) . merge ( file_path : 'modules/exploits/windows/smb/CVE_2020_0796_smbghost.rb' )
204
214
end
205
215
end
206
216
217
+ context 'when the description has non-printable ascii characters' do
218
+ let ( :mod_options ) do
219
+ super ( ) . merge ( description : "Testing human-readable printable ascii characters ≤\n \t and newlines/tabs" )
220
+ end
221
+
222
+ it 'has errors' do
223
+ expect ( subject . errors . full_messages ) . to eq [ 'Description must only contain human-readable printable ascii characters, including newlines and tabs' ]
224
+ end
225
+ end
226
+
207
227
context 'when the platform value is invalid' , skip_before : true do
208
228
let ( :mod_options ) do
209
229
super ( ) . merge ( platform : Msf ::Module ::PlatformList . new ( 'foo' ) )
Original file line number Diff line number Diff line change @@ -28,6 +28,8 @@ class Validator < SimpleDelegator
28
28
validate :validate_reference_ctx_id
29
29
validate :validate_author_bad_chars
30
30
validate :validate_target_platforms
31
+ validate :validate_description_does_not_contain_non_printable_chars
32
+ validate :validate_name_does_not_contain_non_printable_chars
31
33
32
34
attr_reader :mod
33
35
@@ -153,6 +155,22 @@ def has_notes?
153
155
!notes . empty?
154
156
end
155
157
158
+ def validate_description_does_not_contain_non_printable_chars
159
+ unless description &.match? ( /\A [ -~\t \n ]*\z / )
160
+ # Blank descriptions are validated elsewhere, so we will return early to not also add this error
161
+ # and cause unnecessary confusion.
162
+ return if description . nil?
163
+
164
+ errors . add :description , 'must only contain human-readable printable ascii characters, including newlines and tabs'
165
+ end
166
+ end
167
+
168
+ def validate_name_does_not_contain_non_printable_chars
169
+ unless name &.match? ( /\A [ -~]+\z / )
170
+ errors . add :name , 'must only contain human-readable printable ascii characters'
171
+ end
172
+ end
173
+
156
174
validates :mod , presence : true
157
175
158
176
with_options if : :has_notes? do |mod |
You can’t perform that action at this time.
0 commit comments