Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix XSS injection issues #5

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,12 @@ Please follow the recommendations outlined at [keepachangelog.com](https://keepa

## [Unreleased]

### [0.0.2]
#### Fixed
- XSS injection issues [PR 5](https://github.com/shakacode/jstreamer/pull/5)

#### Improved
- docs formatting and typos [PR 4](https://github.com/shakacode/jstreamer/pull/4)

### [0.0.1]
- Initial release
2 changes: 1 addition & 1 deletion lib/jstreamer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,6 @@ def generate(template, object = nil, **options)
# Creates new stream (low-level engine)
# @return stream low-level engine
def create_new_stream
Oj::StringWriter.new
Oj::StringWriter.new(escape_mode: :xss_safe)
end
end
18 changes: 18 additions & 0 deletions spec/jstreamer_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -29,5 +29,23 @@ def render
it "retruns stream" do
expect(described_class.create_new_stream).not_to be_nil
end

it "handles Unicode XSS injections" do
stream = described_class.create_new_stream

stream.push_value("\u2028\u2029\u0000", "x")
result = stream.to_s.split(":").last

expect(result).to eq('"\\u2028\\u2029\\u0000"')
end

it "handles HTML XSS injections" do
stream = described_class.create_new_stream

stream.push_value("<>&", "x")
result = stream.to_s.split(":").last

expect(result).to eq('"\\u003c\\u003e\\u0026"')
end
end
end