diff --git a/lib/core/settings.py b/lib/core/settings.py index 76ae2dafe..081fee1a8 100644 --- a/lib/core/settings.py +++ b/lib/core/settings.py @@ -19,7 +19,7 @@ from lib.core.enums import OS from thirdparty import six # sqlmap version (...) -VERSION = "1.10.11.88" +VERSION = "1.10.11.89" TYPE = "dev" if VERSION.count('.') > 2 and VERSION.split('.')[-1] != '0' else "stable" TYPE_COLORS = {"dev": 33, "stable": 90, "pip": 34} VERSION_STRING = "sqlmap/%s#%s" % ('.'.join(VERSION.split('.')[:-1]) if VERSION.count('.') > 2 and VERSION.split('.')[-1] == '0' else VERSION, TYPE) diff --git a/lib/request/redirecthandler.py b/lib/request/redirecthandler.py index 32f65f992..e214e358e 100644 --- a/lib/request/redirecthandler.py +++ b/lib/request/redirecthandler.py @@ -10,6 +10,7 @@ import re import time import types +from lib.core.common import checkSameHost from lib.core.common import getHostHeader from lib.core.common import getSafeExString from lib.core.common import logHTTPTraffic @@ -180,6 +181,10 @@ class SmartRedirectHandler(_urllib.request.HTTPRedirectHandler): if conf.authRefresh and not authrefresh.sameOrigin(req.get_full_url(), redurl): req.headers = authrefresh.stripHeaders(req.headers) req.unredirected_hdrs = authrefresh.stripHeaders(req.unredirected_hdrs) + + # Note: credentials are not to be forwarded to a different host (like browsers, curl and requests do) (#6185) + if not checkSameHost(req.get_full_url(), redurl): + req.headers = dict((key, value) for key, value in req.headers.items() if key.upper() not in (HTTP_HEADER.COOKIE.upper(), HTTP_HEADER.AUTHORIZATION.upper())) result = _urllib.request.HTTPRedirectHandler.http_error_302(self, req, fp, code, msg, headers) except _urllib.error.HTTPError as ex: result = error = ex diff --git a/tests/test_authrefresh.py b/tests/test_authrefresh.py index 5aff5d687..9fe24f329 100644 --- a/tests/test_authrefresh.py +++ b/tests/test_authrefresh.py @@ -68,6 +68,7 @@ class _Handler(BaseHTTPServer.BaseHTTPRequestHandler): def do_POST(self): body = self.rfile.read(int(self.headers.get('Content-Length', '0'))) token = self.headers.get('X-Auth-Token') + self.server.credentials = (self.headers.get('Cookie'), self.headers.get('Authorization')) if self.path == '/refresh': self.server.refreshes += 1 code, body = 200, b'{"token":"fresh"}' @@ -270,6 +271,28 @@ class TestAuthRefresh(unittest.TestCase): other.server_close() thread.join(5) + def test_redirect_to_another_host_does_not_receive_credentials(self): + # Note: user-supplied Cookie/Authorization must not leak to a different host (#6185), while the same host keeps them + conf.authRefresh = None + conf.httpHeaders = [('X-Auth-Token', 'fresh'), ('Cookie', 'session=secret'), ('Authorization', 'Bearer secret')] + other = _Server(('127.0.0.1', 0), _Handler) + other.requests, other.token, other.expired = [], 'fresh', 0 + other.lock = threading.Lock() + other.syncExpired = False + thread = threading.Thread(target=other.serve_forever) + thread.daemon = True + thread.start() + try: + for host, expected in (('localhost', (None, None)), ('127.0.0.1', ('session=secret', 'Bearer secret'))): + other.credentials = None + self.server.redirect = 'http://%s:%d/landing' % (host, other.server_port) + Connect.getPage(url=conf.url.replace('/test', '/redirect')) + self.assertEqual(other.credentials, expected) + finally: + other.shutdown() + other.server_close() + thread.join(5) + def test_auth_refresh_latency_is_excluded_from_query_timing(self): import lib.request.connect as connect originalPage, originalDelta = Connect.getPage, connect.calculateDeltaSeconds