From f992e44fb5c8c1041e244b1e1d96e4cf3511b74e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Miroslav=20=C5=A0tampar?= Date: Tue, 28 Jul 2026 14:39:44 +0200 Subject: [PATCH] Minor bug fix for --openapi --- lib/core/settings.py | 2 +- lib/parse/openapi.py | 6 +++++- tests/test_openapi.py | 8 ++++++++ 3 files changed, 14 insertions(+), 2 deletions(-) diff --git a/lib/core/settings.py b/lib/core/settings.py index 6e0df8735..65996180f 100644 --- a/lib/core/settings.py +++ b/lib/core/settings.py @@ -20,7 +20,7 @@ from lib.core.enums import OS from thirdparty import six # sqlmap version (...) -VERSION = "1.10.7.219" +VERSION = "1.10.7.220" 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/parse/openapi.py b/lib/parse/openapi.py index 05054208c..f2007edbe 100644 --- a/lib/parse/openapi.py +++ b/lib/parse/openapi.py @@ -193,7 +193,11 @@ def _baseUrl(spec, origin=None, servers=None): variables = servers[0].get("variables") if isinstance(variables, dict): for name, meta in variables.items(): - default = meta.get("default", "1") if isinstance(meta, dict) else "1" + meta = meta if isinstance(meta, dict) else {} + default = meta.get("default") + if default is None: # 'default' is spec-required; when omitted, a declared enum value beats a placeholder host ('1') + enum = meta.get("enum") + default = enum[0] if isinstance(enum, list) and enum else "1" url = url.replace("{%s}" % name, str(default)) if re.match(r"(?i)[a-z][a-z0-9+.-]*://", url): # absolute server URL -> used as declared (the host is NOT rewritten to the spec's own origin) return url.rstrip('/') diff --git a/tests/test_openapi.py b/tests/test_openapi.py index f5ed80b46..460166897 100644 --- a/tests/test_openapi.py +++ b/tests/test_openapi.py @@ -116,6 +116,14 @@ class TestOpenApi(unittest.TestCase): "paths": {"/p": {"get": {}}}} self.assertEqual(_targets(spec, None)[0][0], "https://prod.x.io/v3/p") + def test_server_variable_enum_without_default(self): + # a server variable that declares an 'enum' but omits the (spec-required) 'default' must use a + # declared enum value, not a placeholder host - else the target is https://1/... (unscannable) + spec = {"openapi": "3.0.0", "servers": [{"url": "https://{h}/v1", + "variables": {"h": {"enum": ["real.com"]}}}], + "paths": {"/x": {"get": {}}}} + self.assertEqual(_targets(spec, None)[0][0], "https://real.com/v1/x") + def test_headers_are_hashable_tuples(self): # kb.targets is an OrderedSet, so the emitted headers must be hashable (tuple, not list) spec = {"openapi": "3.0.0", "paths": {"/x": {"get": {"parameters": [