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

Square brackets "]" and "[" in password crashes #38

Closed
justinhoward opened this issue Mar 21, 2016 · 1 comment
Closed

Square brackets "]" and "[" in password crashes #38

justinhoward opened this issue Mar 21, 2016 · 1 comment

Comments

@justinhoward
Copy link
Contributor

Trying to authenticate with Almodovar crashes when using a password with a square bracket (and some other characters that must be escaped in URIs).

ruby --version: ruby 2.3.0p0 (2015-12-25 revision 53290) [x86_64-linux]
almodovar: 1.5.1

To reproduce:

auth = Almodovar::DigestAuth.new('realm', 'my_user', '[')
api = Almodovar::Resource('https://movida.bebanjo.net/api', auth)
puts api.platforms
/usr/lib/ruby/2.3.0/uri/generic.rb:430:in `check_password': bad component(expected user component): [ (URI::InvalidComponentError)
  from /usr/lib/ruby/2.3.0/uri/generic.rb:503:in `password='
  from ../ruby/2.3.0/gems/almodovar-1.5.1/lib/almodovar/http_client.rb:74:in `request'
  from ../ruby/2.3.0/gems/almodovar-1.5.1/lib/almodovar/http_client.rb:22:in `get'
  from ../ruby/2.3.0/gems/almodovar-1.5.1/lib/almodovar/http_accessor.rb:5:in `xml'
  from ../ruby/2.3.0/gems/almodovar-1.5.1/lib/almodovar/single_resource.rb:57:in `node'
  from ../ruby/2.3.0/gems/almodovar-1.5.1/lib/almodovar/single_resource.rb:46:in `method_missing'
  from ../ruby/2.3.0/gems/almodovar-1.5.1/lib/almodovar/resource.rb:22:in `method_missing'

It seems that URI::Generic.check_password validation rejects square brackets. For my case, simply removing the lines that set user and password on the uri object fixes the issue.

# http_client.rb:69
def request(method, uri, options = {})
  uri = URI.parse(URI.escape(URI.unescape(uri)))
  if (requires_auth?)
    domain = domain_for(uri)
    # uri.user = username
    # uri.password = password
    set_client_auth(domain)
  end
@maxcosworth
Copy link
Member

Good catch! And thanks for the fix. We'll tackle this soon!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants