Scott
Scott

Reputation: 121

An Encoded forward slash is being handled as if it was un-encoded - Sinatra

I have a Sinatra route like

get 'check/:input' do |in|
   ##Do stuff in here
end

but when I put a string in :input that contains a forward slash, such as "abcde/12345" or even encoded like "abcde%2F12345", Sinatra is thinking I am trying to reach

check/abcde/12345

and I hit the standard Sinatra 404 page. How do I get around this? I need the slash in the input variable, so I can't simply trim it out or anything like that. Any help would be greatly appreciated!!

Upvotes: 2

Views: 579

Answers (2)

matt
matt

Reputation: 79733

This is done deliberately as part of rack-protection’s path traversal protection.

To disable it you can do

set :protection, :except => :path_traversal

Upvotes: 1

Tacoman667
Tacoman667

Reputation: 1401

This is probably what you are looking for. Props to the person who answered it here: https://stackoverflow.com/a/529172/78551

Basically you are confusing the router. You need to pull it in as separate inputs and join them back in the action.

Upvotes: 0

Related Questions