Skip to content

url matching doesnt take into account the URL encoding #35

@jepetko

Description

@jepetko

I had to create a reverse proxy for encoded_uri in this URL:

/proxy?url=encoded_uri

The configuration of the proxy:

  reverse_proxy /^\/proxy\?url=(.*)$/, "$1", :preserve_host => false

The problem is that the implementation of get_uri doesnt take into account the URL encoding of the parameter and it returns:

https%3A%2F%2Fgithub.com%2Fjaswope%2Frack-reverse-proxy%2Fissues%2Fnew

which causes an internal server error.

My fix:

class Rack::ReverseProxyMatcher

  alias_method :get_uri_without_decode, :get_uri

  def get_uri(path,env)
    puts 'this is a monkeypatched method for :get_uri'
    url = get_uri_without_decode(path,env)
    if url.path.start_with?('http%')
      url = URI.decode url.path
      url = URI(url)
    end
    url
  end
end

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions