Skip to content
Prev Previous commit
Next Next commit
support for nested payloads
  • Loading branch information
donnd-t committed Nov 3, 2021
commit 5ab5f5811f2d1ae8c87fb1a82bed891211ee6a3f
30 changes: 21 additions & 9 deletions lib/core/swagger.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
from lib.core.data import logger
from lib.core.exception import SqlmapSyntaxException
from lib.core.exception import SqlmapSkipTargetException
from typing import Dict

class Operation:

Expand Down Expand Up @@ -70,28 +71,39 @@ def headers(self):
hdrs.append((hp["name"], "%s*" %hp["example"]))
return hdrs

def _ref(swagger, refPath):
paths = refPath.replace("#/", "", 1).split('/')
def _obj(swagger, objOrRefPath):
if isinstance(objOrRefPath, Dict):
return objOrRefPath
paths = objOrRefPath.replace("#/", "", 1).split('/')
r = swagger
for p in paths:
r = r[p]
return r

def _example(swagger, refPath):
def _example(swagger, objOrRefPath):
example = {}
ref = _ref(swagger, refPath)
if "type" in ref and ref["type"] == "object" and "properties" in ref:
properties = ref["properties"]
obj = _obj(swagger, objOrRefPath)

if "type" in obj and obj["type"] == "object" and "properties" in obj:
properties = obj["properties"]
for prop in properties:
if "example" in properties[prop]:
value = properties[prop]["example"]
example[prop] = value
if properties[prop]["type"] == "object":
example[prop] = {}
for objectProp in properties[prop]["properties"]:
example[prop][objectProp] = _example(swagger, properties[prop]["properties"][objectProp])
elif "$ref" in properties[prop]:
example[prop] = _example(swagger, properties[prop]["$ref"])
elif properties[prop]["type"] == "array" and "$ref" in properties[prop]["items"]:
example[prop] = [ _example(swagger, properties[prop]["items"]["$ref"]) ]
elif "example" in properties[prop]:
value = properties[prop]["example"]
example[prop] = value
else:
raise SqlmapSkipTargetException("missing example for parameter '%s'" %prop)
elif "example" in obj:
return obj["example"]
else:
raise SqlmapSkipTargetException("missing example for object '%s'" %obj)


return example
Expand Down