-
-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -24,30 +24,27 @@ class Tester | |
let(:invalid_emails) { | ||
[ | ||
'invalid [email protected]', | ||
'[email protected]', | ||
'[email protected]', | ||
'@email.com', | ||
'[email protected]', | ||
'invalidemailemail.com', | ||
'@[email protected]', | ||
'invalid@[email protected]', | ||
'invalid.email@@email.com' | ||
] | ||
} | ||
|
||
it 'validates valid email addresses' do | ||
it 'validates valid email addresses', :aggregate_failures do | ||
tester = Tester.new | ||
valid_emails.each do |email| | ||
tester.email_address = email | ||
expect(tester.valid?).to be true | ||
expect(tester.valid?).to be(true), "expected #{email} to be valid" | ||
end | ||
end | ||
|
||
it 'validates invalid email addresses' do | ||
it 'validates invalid email addresses', :aggregate_failures do | ||
tester = Tester.new | ||
invalid_emails.each do |email| | ||
tester.email_address = email | ||
expect(tester.valid?).to be false | ||
expect(tester.valid?).to be(false), "expected #{email} not to be valid" | ||
end | ||
end | ||
end |
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 protected]') | ||
|
||
expect { task.invoke }.to output(/invalid [email protected] \/ #{order.id} \/ #{order.number}\n/).to_stdout | ||
end | ||
|
||
it "doesn't include orders with valid email" do | ||
order = create(:order, email: '[email protected]') | ||
|
||
expect { task.invoke }.not_to output(/[email protected]/).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 |