Skip to content

Commit

Permalink
Add sanitize host name
Browse files Browse the repository at this point in the history
  • Loading branch information
lysenkooo authored and whitequark committed Dec 22, 2016
1 parent 2220dc2 commit 9644371
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 0 deletions.
1 change: 1 addition & 0 deletions lib/rack/utf8_sanitizer.rb
Expand Up @@ -27,6 +27,7 @@ def call(env)
HTTP_REFERER
ORIGINAL_FULLPATH
ORIGINAL_SCRIPT_NAME
SERVER_NAME
).map(&:freeze).freeze

SANITIZABLE_CONTENT_TYPES = %w(
Expand Down
11 changes: 11 additions & 0 deletions test/test_utf8_sanitizer.rb
Expand Up @@ -28,6 +28,17 @@
end
end

describe "with invalid host input" do
it "sanitizes host entity (SERVER_NAME)" do
host = "host\xD0".force_encoding('UTF-8')
env = @app.({ "SERVER_NAME" => host })
result = env["SERVER_NAME"]

result.encoding.should == Encoding::US_ASCII
result.should.be.valid_encoding
end
end

describe "with invalid UTF-8 input" do
before do
@plain_input = "foo\xe0".force_encoding('UTF-8')
Expand Down

0 comments on commit 9644371

Please sign in to comment.