Skip to content

Commit

Permalink
Remove invalid bytecode handler (#1555)
Browse files Browse the repository at this point in the history
We introduced this handler to handle the gnarly Invalid Byte Sequence
ArgumentError from requests having invalid encoding.

Finally Rails 5.1.7 and 5.2.3 handles this in the framework.

Everybody not able to update or still using Rails 5.0 should install a
Rack middleware like rack-uri_sanitizer and/or rack-utf8_sanitizer.
  • Loading branch information
tvdeyen authored Mar 28, 2019
1 parent ccfb620 commit 4b0e6e5
Show file tree
Hide file tree
Showing 2 changed files with 1 addition and 17 deletions.
12 changes: 1 addition & 11 deletions lib/alchemy/routing_constraints.rb
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,6 @@ def matches?(request)
@params = @request.params

handable_format? && no_rails_route?
rescue ArgumentError => e
handle_invalid_byte_sequence(e)
end

private
Expand All @@ -35,16 +33,8 @@ def handable_format?
# We don't want to handle the Rails info routes.
def no_rails_route?
return true if !%w(development test).include?(Rails.env)
(@params['urlname'] =~ /\Arails\//).nil?
end

# Handle invalid byte sequence in UTF-8 errors with 400 status.
def handle_invalid_byte_sequence(error)
if error.message =~ /invalid byte sequence/
raise ActionController::BadRequest
else
raise
end
(@params['urlname'] =~ /\Arails\//).nil?
end
end
end
6 changes: 0 additions & 6 deletions spec/features/page_feature_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -73,12 +73,6 @@
end
end

context "with invalid byte code char in urlname parameter" do
it "should raise BadRequest (400) error" do
expect { visit '/%ed' }.to raise_error(ActionController::BadRequest)
end
end

describe "menubar" do
context "rendering for guest users" do
it "is prohibited" do
Expand Down

0 comments on commit 4b0e6e5

Please sign in to comment.