Skip to content

Commit 6450431

Browse files
committed
Updates module validation to check description and name for non-printable chars
1 parent fda250d commit 6450431

File tree

2 files changed

+38
-0
lines changed

2 files changed

+38
-0
lines changed

spec/module_validation_spec.rb

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -184,6 +184,16 @@
184184
end
185185
end
186186

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+
187197
context 'when the module file path is not snake case' do
188198
let(:mod_options) do
189199
super().merge(file_path: 'modules/exploits/windows/smb/CVE_2020_0796_smbghost.rb')
@@ -204,6 +214,16 @@
204214
end
205215
end
206216

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\tand 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+
207227
context 'when the platform value is invalid', skip_before: true do
208228
let(:mod_options) do
209229
super().merge(platform: Msf::Module::PlatformList.new('foo'))

spec/support/lib/module_validation.rb

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,8 @@ class Validator < SimpleDelegator
2828
validate :validate_reference_ctx_id
2929
validate :validate_author_bad_chars
3030
validate :validate_target_platforms
31+
validate :validate_description_does_not_contain_non_printable_chars
32+
validate :validate_name_does_not_contain_non_printable_chars
3133

3234
attr_reader :mod
3335

@@ -153,6 +155,22 @@ def has_notes?
153155
!notes.empty?
154156
end
155157

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+
156174
validates :mod, presence: true
157175

158176
with_options if: :has_notes? do |mod|

0 commit comments

Comments
 (0)