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

Decode a URL encoded proxy username or password #665

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

jrafanie
Copy link
Contributor

@jrafanie jrafanie commented Jun 5, 2018

Fixes #661

We already decode a URL encoded username or password using CGI.unescape,
this change does the same thing for a proxy's credentials provided in a
URL.

@jrafanie
Copy link
Contributor Author

jrafanie commented Jun 5, 2018

@ab Please review when you can. Thanks!

@jrafanie
Copy link
Contributor Author

It looks like it's failing on rubocop configuration changes but all of the tests pass. I can look at this in a followup PR.

Copy link

@empeje empeje left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good to me 🙆‍♂️

jrafanie added a commit to jrafanie/manageiq that referenced this pull request Oct 17, 2018
https://bugzilla.redhat.com/show_bug.cgi?id=1566615

Monkey patch RestClient for patch releases of rest-client 2.0.0.
The underlying method, net_http_object, has not been modified since 2015
so it should be relatively safe to monkey patch this until the upstream
PR gets merged/released.

Upstream PR: rest-client/rest-client#665
jrafanie added a commit to jrafanie/manageiq that referenced this pull request Oct 19, 2018
https://bugzilla.redhat.com/show_bug.cgi?id=1566615

Monkey patch RestClient for patch releases of rest-client 2.0.0.
The underlying method, net_http_object, has not been modified since 2015
so it should be relatively safe to monkey patch this until the upstream
PR gets merged/released.

Upstream PR: rest-client/rest-client#665

To verify this works, run bin/rails console:

Before:

```
irb(main):004:0> r = RestClient::Request.new(method: :get, url:
'http://127.0.0.1/api', proxy: 'http://%24myuser:%24%3Fxxxx@127.0.0.1')
=> <RestClient::Request @method="get", @url="http://127.0.0.1/api">=>
<RestClient::Request @method="get", @url="https://127.0.0.1/api">
irb(main):002:0> r.net_http_object('host', 80).proxy_user
=> "%24myuser"
irb(main):003:0> r.net_http_object('host', 80).proxy_pass
=> "%24%3Fxxxx"
```

After:

```
irb(main):004:0> r = RestClient::Request.new(method: :get, url:
'http://127.0.0.1/api', proxy: 'http://%24myuser:%24%3Fxxxx@127.0.0.1')
=> <RestClient::Request @method="get", @url="http://127.0.0.1/api">=>
<RestClient::Request @method="get", @url="https://127.0.0.1/api">
irb(main):002:0> r.net_http_object('host', 80).proxy_user
=> "$myuser"
irb(main):003:0> r.net_http_object('host', 80).proxy_pass
=> "$?xxxx"
```
@adamruzicka
Copy link

Any chance this could get moving again anytime soon?

adamruzicka added a commit to adamruzicka/foreman that referenced this pull request Mar 24, 2021
Restclient as of version 2.1.0 uses provided credentials stored in a proxy URI
object verbatim. If the credentials are escaped as they should be, then this
leads to errors when we try to use the credentials because restclient sends the
escaped form.

There is a PR[1] in upstream restclient, which addresses this issue, but last
movement there was in October 2018. ManageIQ folks decided to monkey patch
restclient when they ran into the same issue, this commit is a loose adaptation
of the original[1] and ManageIQ patches[2].

[1] - rest-client/rest-client#665
[2] - ManageIQ/manageiq#18105
adamruzicka added a commit to adamruzicka/foreman that referenced this pull request Mar 24, 2021
Restclient as of version 2.1.0 uses provided credentials stored in a proxy URI
object verbatim. If the credentials are escaped as they should be, then this
leads to errors when we try to use the credentials because restclient sends the
escaped form.

There is a PR[1] in upstream restclient, which addresses this issue, but last
movement there was in October 2018. ManageIQ folks decided to monkey patch
restclient when they ran into the same issue, this commit is a loose adaptation
of the original[1] and ManageIQ patches[2].

[1] - rest-client/rest-client#665
[2] - ManageIQ/manageiq#18105
adamruzicka added a commit to adamruzicka/foreman that referenced this pull request Mar 24, 2021
Restclient as of version 2.1.0 uses provided credentials stored in a proxy URI
object verbatim. If the credentials are escaped as they should be, then this
leads to errors when we try to use the credentials because restclient sends the
escaped form.

There is a PR[1] in upstream restclient, which addresses this issue, but last
movement there was in October 2018. ManageIQ folks decided to monkey patch
restclient when they ran into the same issue, this commit is a loose adaptation
of the original[1] and ManageIQ patches[2].

[1] - rest-client/rest-client#665
[2] - ManageIQ/manageiq#18105
adamruzicka added a commit to adamruzicka/foreman that referenced this pull request Mar 24, 2021
Restclient as of version 2.1.0 uses provided credentials stored in a proxy URI
object verbatim. If the credentials are escaped as they should be, then this
leads to errors when we try to use the credentials because restclient sends the
escaped form.

There is a PR[1] in upstream restclient, which addresses this issue, but last
movement there was in October 2018. ManageIQ folks decided to monkey patch
restclient when they ran into the same issue, this commit is a loose adaptation
of the original[1] and ManageIQ patches[2].

[1] - rest-client/rest-client#665
[2] - ManageIQ/manageiq#18105
adamruzicka added a commit to adamruzicka/foreman that referenced this pull request Mar 24, 2021
Restclient as of version 2.1.0 uses provided credentials stored in a proxy URI
object verbatim. If the credentials are escaped as they should be, then this
leads to errors when we try to use the credentials because restclient sends the
escaped form.

There is a PR[1] in upstream restclient, which addresses this issue, but last
movement there was in October 2018. ManageIQ folks decided to monkey patch
restclient when they ran into the same issue, this commit is a loose adaptation
of the original[1] and ManageIQ patches[2].

[1] - rest-client/rest-client#665
[2] - ManageIQ/manageiq#18105
adamruzicka added a commit to adamruzicka/foreman that referenced this pull request Mar 24, 2021
Restclient as of version 2.1.0 uses provided credentials stored in a proxy URI
object verbatim. If the credentials are escaped as they should be, then this
leads to errors when we try to use the credentials because restclient sends the
escaped form.

There is a PR[1] in upstream restclient, which addresses this issue, but last
movement there was in October 2018. ManageIQ folks decided to monkey patch
restclient when they ran into the same issue, this commit is a loose adaptation
of the original[1] and ManageIQ patches[2].

[1] - rest-client/rest-client#665
[2] - ManageIQ/manageiq#18105
adamruzicka added a commit to adamruzicka/foreman that referenced this pull request Jun 10, 2021
Restclient as of version 2.1.0 uses provided credentials stored in a proxy URI
object verbatim. If the credentials are escaped as they should be, then this
leads to errors when we try to use the credentials because restclient sends the
escaped form.

There is a PR[1] in upstream restclient, which addresses this issue, but last
movement there was in October 2018. ManageIQ folks decided to monkey patch
restclient when they ran into the same issue, this commit is a loose adaptation
of the original[1] and ManageIQ patches[2].

[1] - rest-client/rest-client#665
[2] - ManageIQ/manageiq#18105
ezr-ondrej pushed a commit to theforeman/foreman that referenced this pull request Jun 11, 2021
Restclient as of version 2.1.0 uses provided credentials stored in a proxy URI
object verbatim. If the credentials are escaped as they should be, then this
leads to errors when we try to use the credentials because restclient sends the
escaped form.

There is a PR[1] in upstream restclient, which addresses this issue, but last
movement there was in October 2018. ManageIQ folks decided to monkey patch
restclient when they ran into the same issue, this commit is a loose adaptation
of the original[1] and ManageIQ patches[2].

[1] - rest-client/rest-client#665
[2] - ManageIQ/manageiq#18105
Fixes rest-client#661

We already decode a URL encoded username or password using CGI.unescape,
this change does the same thing for a proxy's credentials provided in a
URL.
@jrafanie jrafanie force-pushed the decode_url_encoded_proxy_user_pass branch from 6080346 to 35d1640 Compare September 8, 2021 15:45
@jrafanie
Copy link
Contributor Author

jrafanie commented Sep 8, 2021

@ab I have pushed a commit to fix a sporadic test failure on this pull request. Even though the PR is a few years old, it still is correct and we have similar code running in ManageIQ for a long time.

If you combine this PR + #759 to correct renamed rubocops, the rubocop part will no longer exit 1 and will instead exit 0 with some cop warnings to fix later on so both specs and cops will exit 0.

Please let me know what we can do to get this merged. Thank you!

Changes to the global RestClient.log were rolled back in the "before" instead of the
"after", which meant, if tests made changes to the RestClient.log, those changes remained
after the test.  This was causing breakages when the request_spec.rb examples
ran before the resource-spec.rb.
@jrafanie jrafanie force-pushed the decode_url_encoded_proxy_user_pass branch from 35d1640 to 45ddcbb Compare September 8, 2021 16:00
@jrafanie
Copy link
Contributor Author

jrafanie commented Sep 8, 2021

cc @L2G @mattmanning please also review if you have a chance... thanks!

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

Successfully merging this pull request may close these issues.

Can't use proxy password with percent encoded characters
3 participants