forked from stringer-rss/stringer
-
Notifications
You must be signed in to change notification settings - Fork 0
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 stringer-rss#492 from swanson/vk-feed-title-xss
Sanitize feed titles
- Loading branch information
Showing
6 changed files
with
66 additions
and
37 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
class ContentSanitizer | ||
def self.sanitize(content) | ||
Loofah.fragment(content.gsub(/<wbr\s*>/i, "")) | ||
.scrub!(:prune) | ||
.scrub!(:unprintable) | ||
.to_s | ||
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
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,29 @@ | ||
require "spec_helper" | ||
|
||
app_require "utils/content_sanitizer" | ||
|
||
describe ContentSanitizer do | ||
describe ".sanitize" do | ||
context "regressions" do | ||
it "handles <wbr> tag properly" do | ||
result = described_class.sanitize("<code>WM_<wbr\t\n >ERROR</code> asdf") | ||
expect(result).to eq "<code>WM_ERROR</code> asdf" | ||
end | ||
|
||
it "handles <figure> tag properly" do | ||
result = described_class.sanitize("<figure>some code</figure>") | ||
expect(result).to eq "<figure>some code</figure>" | ||
end | ||
|
||
it "handles unprintable characters" do | ||
result = described_class.sanitize("n\u2028\u2029") | ||
expect(result).to eq "n" | ||
end | ||
|
||
it "preserves line endings" do | ||
result = described_class.sanitize("test\r\ncase") | ||
expect(result).to eq "test\r\ncase" | ||
end | ||
end | ||
end | ||
end |