[#146251] Fix Security Vulnerabilities (Bundle Audit + Brakeman) #178
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Ticket: https://reinteractive.zendesk.com/agent/tickets/146251
Overview
This PR addresses all security vulnerabilities identified by
bundle auditandbrakemanstatic analysis tools. The solution for dependency vulnerabilities avoids upgrading Sprockets (which would require extensive changes) by pinning ERB to version 5.x. Additionally, we fixed 4 real security vulnerabilities identified by Brakeman and cleaned up the ignore configuration.Security Vulnerabilities Fixed
Bundle Audit - Dependency Vulnerabilities
1. Bootstrap (CVE-2019-8331)
2. Rails (CVE-2025-55193, CVE-2025-24293)
3. Nokogiri (Multiple CVEs)
4. Rack (6 CVEs)
5. Rexml (6 CVEs)
6. Thor (CVE-2025-54314)
Supporting Updates
7. autoprefixer-rails
Brakeman - Code Security Issues
Fixed 6 real security vulnerabilities and cleaned up ignore configuration:
1. Mass Assignment (CSP Reports Controller) ✅
app/controllers/api/csp_reports_controller.rbparams.permit!method that allowed unrestricted parametersreport_paramsmethod entirely2. Cross-Site Scripting (XSS) - Hero Content Title ✅
app/views/home/_hero_content.html.erbrawhelper on user-controlled content without sanitizationrawwithsanitizehelper, allowing only safe HTML tags (br,strong,em,i,b)3. Cross-Site Scripting (XSS) - Collection Description ✅
app/views/admin/cms/collections/show.html.erbrawhelper on database content without sanitizationrawwithsanitizehelper, allowing common formatting tags while preventing script injection4. Cross-Site Scripting (XSS) - Institution URL ✅
app/views/home/_hero_content.html.erblink_towithout validationhttp://,https://, or relative pathsjavascript:and other XSS vectors in institution URLs5. SQL Injection - User Contributions Report ✅
app/services/reports/user_contributions.rb.to_iand dates properly quoted6. File Access - Azure Speech-to-Text Job ✅
app/jobs/azure/speech_to_text_job.rbFile.openwithout validation/tmp/directory usingrealpathand prefix checkConfiguration Cleanup
Brakeman ignore file (
config/brakeman.ignore):Results:
Technical Approach
The Challenge - Bundle Audit
Upgrading Rails to 8.0.2.1 brought in ERB 6.0, which has breaking changes incompatible with Sprockets 3.7.x. The standard solution would be to upgrade Sprockets to 4.x, but this would require:
The Solution
Instead of upgrading Sprockets, we pinned ERB to version 5.x:
This approach:
Changes Made
Dependencies (Bundle Audit Fixes)
Gemfile:
gem 'erb', '~> 5.0'to pin ERB versionrailsto'8.0.2.1'bootstrapto'~> 4.3.1'autoprefixer-railsto'>= 9.1.0'nokogirito'~> 1.18', '>= 1.18.9'Gemfile.lock:
bundle updateto resolve security vulnerabilities.bundler-audit.yml (new file):
Added configuration to ignore withdrawn CVE:
Note: This CVE was officially withdrawn because "it was not a security issue in Bootstrap." Source: GHSA-vc8w-jr9v-vj7f
Code Security Fixes (Brakeman Fixes)
Controllers:
app/controllers/api/csp_reports_controller.rb- Removed unused mass assignment methodViews:
app/views/home/_hero_content.html.erb- Fixed 2 XSS issues (title sanitization + URL validation)app/views/admin/cms/collections/show.html.erb- Fixed XSS in collection descriptionServices:
app/services/reports/user_contributions.rb- Fixed SQL injection with parameterized queriesJobs:
app/jobs/azure/speech_to_text_job.rb- Added file path validationConfiguration:
config/brakeman.ignore- Cleaned up obsolete entries, added documentation for false positivesDocumentation:
README.md- Added Security Scanning section with instructions for running Bundle Audit and BrakemanVerification
Security Scans
Bundle Audit:
Brakeman:
$ bundle exec brakeman --no-pager Security Warnings: 0 Ignored Warnings: 8 (all documented)Test Suite
All tests passing:
$ bundle exec rspec spec/models spec/controllers spec/services 752 examples, 0 failuresSummary of Security Improvements
Dependencies
The following gems were updated as part of this security patch:
Backwards Compatibility
This PR maintains full backwards compatibility:
Future Considerations
While this PR successfully addresses all current security vulnerabilities, consider the following for future work:
Testing Instructions
bundle installFiles Changed
Dependencies & Configuration (3 files):
Gemfile- Updated gem versions + ERB pinGemfile.lock- Resolved dependencies.bundler-audit.yml- Bundle Audit configuration (new)Security Fixes (5 files):
app/controllers/api/csp_reports_controller.rbapp/views/home/_hero_content.html.erbapp/views/admin/cms/collections/show.html.erbapp/services/reports/user_contributions.rbapp/jobs/azure/speech_to_text_job.rbConfiguration & Documentation (2 files):
config/brakeman.ignore- Cleaned up + documentedREADME.md- Added security scanning sectionTotal: 10 files changed
References
CVE Information:
Security Tools: