Skip to content

Commit d59a8d4

Browse files
committed
Add security checks and dependency audit
Introduce a rake security task that runs bundler-audit and Semgrep, document the workflow, and pin stringio to address CVE-2024-27280.
1 parent d24b206 commit d59a8d4

5 files changed

Lines changed: 41 additions & 1 deletion

File tree

CHANGELOG.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,13 @@ Changes section to scan for breaking or behavioral changes.
8888
* Accept hash-like inputs (`to_hash`) in hash conversion to support Rails
8989
`HashWithIndifferentAccess` data (see #104).
9090

91+
* Add `bundler-audit` to support security-focused dependency checks.
92+
93+
* Pin `stringio` to `>= 3.0.1.1` in development to address CVE-2024-27280.
94+
95+
* Add a `rake security` task that runs `bundler-audit` and Semgrep (when
96+
installed).
97+
9198
* Add AVL, AA, Treap, Binary Heap, and Binary Max-Heap implementations with
9299
ordered insert/search/delete or insert/extract operations.
93100

CONTRIBUTING.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,8 @@ Development dependencies (not required for installing the gem):
2323
* [awesome_bot][] for markdown link checking
2424
* [mdl][] for markdown linting
2525
* [RuboCop][] for linting the code
26+
* [bundler-audit][] for security advisory checks
27+
* [Semgrep][] for security-focused static analysis (optional)
2628

2729
If RubyGems warns about ambiguous `stringio` specs in your dev gemset,
2830
remove the extra versions in this repo’s gemset (for example):
@@ -77,6 +79,9 @@ installed automatically by [Bundler][].
7779
* Run `bundle exec rake lint` and `bundle exec rake test:all` before proposing
7880
changes. Resolve all RuboCop offenses before committing.
7981
* Run `bundle exec rake doc:check` when modifying markdown documentation.
82+
* Run `bundle exec rake security` for dependency and static security checks.
83+
Semgrep is optional; if it is not installed, the task will warn and skip it.
84+
If Semgrep fails to download rules, set `SSL_CERT_FILE=/etc/ssl/cert.pem`.
8085
* Update `CHANGELOG.md` for notable changes and API behavior changes.
8186
* Update `README.md` when introducing new capabilities or new tree types.
8287
* Ensure YARD documentation exists for new or modified modules, classes, and
@@ -108,13 +113,15 @@ bundle exec rake bench
108113
[Bundler]: https://bundler.io
109114
[contributor_covenant]: https://www.contributor-covenant.org/version/2/1/
110115
[awesome_bot]: https://github.com/dkhamsing/awesome_bot
116+
[bundler-audit]: https://github.com/rubysec/bundler-audit
111117
[github_issues]: https://github.com/evolve75/RubyTree/issues
112118
[mdl]: https://github.com/markdownlint/markdownlint
113119
[Rake]: https://rubygems.org/gems/rake
114120
[Ruby]: https://www.ruby-lang.org
115121
[RSpec]: https://rspec.info/
116122
[RuboCop]: https://rubocop.org/
117123
[SCM]: https://en.wikipedia.org/wiki/Source_Code_Management
124+
[Semgrep]: https://semgrep.dev
118125
[Yard]: https://yardoc.org
119126
[git]: https://git-scm.com
120127
[rt@github]: https://github.com/evolve75/RubyTree

Gemfile.lock

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,9 @@ GEM
1010
ast (2.4.3)
1111
awesome_bot (1.20.0)
1212
parallel (= 1.20.1)
13+
bundler-audit (0.9.3)
14+
bundler (>= 1.2.0)
15+
thor (~> 1.0)
1316
cgi (0.5.1)
1417
chef-utils (19.1.164)
1518
concurrent-ruby
@@ -99,9 +102,10 @@ GEM
99102
simplecov-html (0.13.2)
100103
simplecov-lcov (0.9.0)
101104
simplecov_json_formatter (0.1.4)
102-
stringio (3.0.1)
105+
stringio (3.2.0)
103106
test-unit (3.7.7)
104107
power_assert
108+
thor (1.5.0)
105109
tomlrb (2.0.4)
106110
tsort (0.2.0)
107111
unicode-display_width (3.2.0)
@@ -115,6 +119,7 @@ PLATFORMS
115119
DEPENDENCIES
116120
awesome_bot (~> 1.20)
117121
bundler (~> 2.6)
122+
bundler-audit (~> 0.9)
118123
mdl (~> 0.13)
119124
rake (~> 13.3)
120125
rdoc (~> 7.1)
@@ -126,6 +131,7 @@ DEPENDENCIES
126131
rubytree!
127132
simplecov (~> 0.22)
128133
simplecov-lcov (~> 0.9)
134+
stringio (~> 3.0, >= 3.0.1.1)
129135
test-unit (~> 3.7)
130136
yard (~> 0.9)
131137

Rakefile

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,24 @@ end
6666
desc 'Run lint checks'
6767
task lint: %i[gemspec rubocop]
6868

69+
# ................................ Security checks
70+
desc 'Run security checks (bundler-audit, semgrep)'
71+
task :security do
72+
sh('bundle', 'exec', 'bundler-audit', 'check', '--update')
73+
74+
semgrep_available = system('command -v semgrep >/dev/null 2>&1')
75+
unless semgrep_available
76+
warn 'WARN: semgrep not found; skipping semgrep security scan.'
77+
return
78+
end
79+
80+
env = {}
81+
default_cert = '/etc/ssl/cert.pem'
82+
env['SSL_CERT_FILE'] = default_cert if ENV['SSL_CERT_FILE'].nil? && File.exist?(default_cert)
83+
84+
sh(env, 'semgrep', '--config', 'p/r2c-security-audit', '--config', 'p/ruby', 'lib')
85+
end
86+
6987
# ................................ Release checks
7088
desc 'Run release checks (lint, tests, docs, package)'
7189
task 'release:check' => %i[lint test:all doc:yard gem:package]

rubytree.gemspec

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,8 +82,10 @@ Gem::Specification.new do |s|
8282
s.add_development_dependency 'rubocop-rspec', '~> 3.0'
8383
s.add_development_dependency 'simplecov', '~> 0.22'
8484
s.add_development_dependency 'simplecov-lcov', '~> 0.9'
85+
s.add_development_dependency 'stringio', '~> 3.0', '>= 3.0.1.1'
8586
s.add_development_dependency 'test-unit', '~> 3.7'
8687
s.add_development_dependency 'yard', '~> 0.9'
88+
s.add_development_dependency 'bundler-audit', '~> 0.9'
8789

8890
s.post_install_message = <<-END_MESSAGE
8991
========================================================================

0 commit comments

Comments
 (0)