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

Allow redirects not configurable in sessions #4951

Open
Paradoxis opened this issue Jan 29, 2019 · 0 comments
Open

Allow redirects not configurable in sessions #4951

Paradoxis opened this issue Jan 29, 2019 · 0 comments

Comments

@Paradoxis
Copy link

I have an application I need to reach behind a firewall, I've set up a tunnel to this application via SSH running on my machine which forwards all connections from 127.0.0.1:1234 to 192.168.1.10:80. Whenever I make a request to my application, it redirects me to a login page first.

The issue with this is that all redirect URL's have the 192.168.1.10 hostname, which requests tries to follow and inevitably crashes (as this host does not exist on my network).

I tried to set allow_redirects to False on my session by overriding the request method, but the session source hard-codes the allow_redirects option to True if it isn't explicitly set when calling get, head and options (source)

Expected Result

I expected no redirect to be followed, but rather that that the request ends after the first response. I expected the allow_redirects option to be configurable in sessions like the verify flag is (source)

Actual Result

The 302 was resolved, and attempted to redirect me to a nonexistent host, leading to a connection error exception.

Reproduction Steps

import requests


class Example(requests.Session):
    def __init__(self, allow_redirects=False, *args, **kwargs):
        super(Example, self).__init__(*args, **kwargs)
        self.allow_redirects = allow_redirects

    def request(self, *args, **kwargs):
        kwargs.setdefault('allow_redirects', self.allow_redirects)
        return super(Example, self).request(*args, **kwargs)


sess = Example()
sess.get('http://127.0.0.1:1234')  # ConnectionError ... 192.168.1.10 connection refused (redirected)

System Information

$ python -m requests.help
{
  "chardet": {
    "version": "3.0.4"
  },
  "cryptography": {
    "version": ""
  },
  "idna": {
    "version": "2.8"
  },
  "implementation": {
    "name": "CPython",
    "version": "3.6.0"
  },
  "platform": {
    "release": "10",
    "system": "Windows"
  },
  "pyOpenSSL": {
    "openssl_version": "",
    "version": null
  },
  "requests": {
    "version": "2.21.0"
  },
  "system_ssl": {
    "version": "100020af"
  },
  "urllib3": {
    "version": "1.24.1"
  },
  "using_pyopenssl": false
}
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

1 participant