Permalink
Show file tree
Hide file tree
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
Merge pull request from GHSA-qxmr-qxh6-2cc9
Fix ReDos vulnerability on Spree::EmailValidator::EMAIL_REGEXP
- Loading branch information
Showing
4 changed files
with
61 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
18 changes: 18 additions & 0 deletions
18
core/lib/tasks/solidus/check_orders_with_invalid_email.rake
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,18 @@ | ||
| # frozen_string_literal: true | ||
|
|
||
| namespace :solidus do | ||
| desc 'Prints orders with invalid email (after fix for GHSA-qxmr-qxh6-2cc9)' | ||
| task check_orders_with_invalid_email: :environment do | ||
| matches = Spree::Order.find_each.reduce([]) do |matches, order| | ||
| order.email.nil? || Spree::EmailValidator::EMAIL_REGEXP.match?(order.email) ? matches : matches + [order] | ||
| end | ||
| if matches.any? | ||
| puts 'Email / ID / Number' | ||
| puts(matches.map do |order| | ||
| "#{order.email} / #{order.id} / #{order.number}" | ||
| end.join("\n")) | ||
| else | ||
| puts 'NO MATCHES' | ||
| end | ||
| end | ||
| end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
38 changes: 38 additions & 0 deletions
38
core/spec/lib/tasks/solidus/check_orders_with_invalid_email_spec.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,38 @@ | ||
| # frozen_string_literal: true | ||
|
|
||
| require 'rails_helper' | ||
|
|
||
| path = Spree::Core::Engine.root.join('lib/tasks/solidus/check_orders_with_invalid_email.rake') | ||
|
|
||
| RSpec.describe 'solidus' do | ||
| describe 'check_orders_with_invalid_email' do | ||
| include_context( | ||
| 'rake', | ||
| task_path: path, | ||
| task_name: 'solidus:check_orders_with_invalid_email' | ||
| ) | ||
|
|
||
| it 'includes orders with invalid email' do | ||
| order = create(:order) | ||
| order.update_column(:email, 'invalid email@email.com') | ||
|
|
||
| expect { task.invoke }.to output(/invalid email@email.com \/ #{order.id} \/ #{order.number}\n/).to_stdout | ||
| end | ||
|
|
||
| it "doesn't include orders with valid email" do | ||
| order = create(:order, email: 'valid@email.com') | ||
|
|
||
| expect { task.invoke }.not_to output(/valid@email.com/).to_stdout | ||
| end | ||
|
|
||
| it "doesn't include orders with no email" do | ||
| order = create(:order, user: nil, email: nil, number: '123') | ||
|
|
||
| expect { task.invoke }.not_to output(/#{order.number}/).to_stdout | ||
| end | ||
|
|
||
| it "prints message when no matches found" do | ||
| expect { task.invoke }.to output(/NO MATCHES/).to_stdout | ||
| end | ||
| end | ||
| end |