-
Notifications
You must be signed in to change notification settings - Fork 287
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 #1075 from texpert/sanitize-attrs
Sanitize name and description attrs of TermTaxonomy classes to prevent XSS attacks
- Loading branch information
Showing
16 changed files
with
140 additions
and
0 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
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
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
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,10 @@ | ||
# frozen_string_literal: true | ||
|
||
require 'rails_helper' | ||
require 'shared_specs/sanitize_attrs' | ||
|
||
RSpec.describe CamaleonCms::Category, type: :model do | ||
before { allow_any_instance_of(described_class).to receive(:set_site) } | ||
|
||
it_behaves_like 'sanitize attrs', model: described_class, attrs_to_sanitize: %i[name description] | ||
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 |
---|---|---|
@@ -0,0 +1,10 @@ | ||
# frozen_string_literal: true | ||
|
||
require 'rails_helper' | ||
require 'shared_specs/sanitize_attrs' | ||
|
||
RSpec.describe CamaleonCms::NavMenuItem, type: :model do | ||
before { allow_any_instance_of(described_class).to receive(:update_count) } | ||
|
||
it_behaves_like 'sanitize attrs', model: described_class, attrs_to_sanitize: %i[name description] | ||
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 |
---|---|---|
@@ -0,0 +1,8 @@ | ||
# frozen_string_literal: true | ||
|
||
require 'rails_helper' | ||
require 'shared_specs/sanitize_attrs' | ||
|
||
RSpec.describe CamaleonCms::NavMenu, type: :model do | ||
it_behaves_like 'sanitize attrs', model: described_class, attrs_to_sanitize: %i[name description] | ||
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 |
---|---|---|
@@ -0,0 +1,8 @@ | ||
# frozen_string_literal: true | ||
|
||
require 'rails_helper' | ||
require 'shared_specs/sanitize_attrs' | ||
|
||
RSpec.describe CamaleonCms::Plugin, type: :model do | ||
it_behaves_like 'sanitize attrs', model: described_class, attrs_to_sanitize: %i[name description] | ||
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 |
---|---|---|
@@ -0,0 +1,8 @@ | ||
# frozen_string_literal: true | ||
|
||
require 'rails_helper' | ||
require 'shared_specs/sanitize_attrs' | ||
|
||
RSpec.describe CamaleonCms::PostTag, type: :model do | ||
it_behaves_like 'sanitize attrs', model: described_class, attrs_to_sanitize: %i[name description] | ||
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 |
---|---|---|
@@ -0,0 +1,10 @@ | ||
# frozen_string_literal: true | ||
|
||
require 'rails_helper' | ||
require 'shared_specs/sanitize_attrs' | ||
|
||
RSpec.describe CamaleonCms::PostType, type: :model do | ||
init_site | ||
|
||
it_behaves_like 'sanitize attrs', model: described_class, attrs_to_sanitize: %i[name description] | ||
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
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,8 @@ | ||
# frozen_string_literal: true | ||
|
||
require 'rails_helper' | ||
require 'shared_specs/sanitize_attrs' | ||
|
||
RSpec.describe CamaleonCms::TermTaxonomy, type: :model do | ||
it_behaves_like 'sanitize attrs', model: described_class, attrs_to_sanitize: %i[name description] | ||
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 |
---|---|---|
@@ -0,0 +1,8 @@ | ||
# frozen_string_literal: true | ||
|
||
require 'rails_helper' | ||
require 'shared_specs/sanitize_attrs' | ||
|
||
RSpec.describe CamaleonCms::Theme, type: :model do | ||
it_behaves_like 'sanitize attrs', model: described_class, attrs_to_sanitize: %i[name description] | ||
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 |
---|---|---|
@@ -0,0 +1,8 @@ | ||
# frozen_string_literal: true | ||
|
||
require 'rails_helper' | ||
require 'shared_specs/sanitize_attrs' | ||
|
||
RSpec.describe CamaleonCms::UserRole, type: :model do | ||
it_behaves_like 'sanitize attrs', model: described_class, attrs_to_sanitize: %i[name description] | ||
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 |
---|---|---|
@@ -0,0 +1,8 @@ | ||
# frozen_string_literal: true | ||
|
||
require 'rails_helper' | ||
require 'shared_specs/sanitize_attrs' | ||
|
||
RSpec.describe CamaleonCms::Widget::Main, type: :model do | ||
it_behaves_like 'sanitize attrs', model: described_class, attrs_to_sanitize: %i[name description] | ||
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 |
---|---|---|
@@ -0,0 +1,8 @@ | ||
# frozen_string_literal: true | ||
|
||
require 'rails_helper' | ||
require 'shared_specs/sanitize_attrs' | ||
|
||
RSpec.describe CamaleonCms::Widget::Sidebar, type: :model do | ||
it_behaves_like 'sanitize attrs', model: described_class, attrs_to_sanitize: %i[name description] | ||
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 |
---|---|---|
@@ -0,0 +1,23 @@ | ||
# frozen_string_literal: true | ||
|
||
RSpec.shared_examples 'sanitize attrs' do |model:, attrs_to_sanitize:| | ||
attrs_to_sanitize.each do |attr| | ||
it 'sanitizes name attribute on create' do | ||
attrs_for_creation = { attr => '"><script>alert(1)</script>' } | ||
attrs_for_creation.merge!(site: @site) if defined?(@site) | ||
model_instance = model.create(attrs_for_creation) | ||
|
||
expect(model_instance.__send__(attr)).to eql('">alert(1)') | ||
end | ||
|
||
it 'sanitizes name attribute on update' do | ||
attrs_for_creation = { attr => 'Legit text' } | ||
attrs_for_creation.merge!(site: @site) if defined?(@site) | ||
model_instance = model.create(attrs_for_creation) | ||
# attrs_for_creation = { attr => '"><script>alert(1)</script>' } | ||
model_instance.update(attr => '"><script>alert(1)</script>') | ||
|
||
expect(model_instance.__send__(attr)).to eql('">alert(1)') | ||
end | ||
end | ||
end |