Parse a flask/werkzeug URL to extract placeholders and their processors This is used in taint analysis to find tainted URL arguments for example: /api/v1.0/lookup/ /info would extract the 'username' placeholder (with no processor)
(url: str)
| 298 | |
| 299 | |
| 300 | def parse_werkzeug_url(url: str) -> dict: |
| 301 | """ |
| 302 | Parse a flask/werkzeug URL to extract placeholders and their processors |
| 303 | This is used in taint analysis to find tainted URL arguments |
| 304 | for example: /api/v1.0/lookup/<username>/info |
| 305 | would extract the 'username' placeholder (with no processor) |
| 306 | """ |
| 307 | regex = re.compile( |
| 308 | r"<(?P<processor>([a-z_\d]+)(\(.*\))?:)?(?P<parameter>[a-z\d_]+)>" |
| 309 | ) |
| 310 | |
| 311 | parsed = {} |
| 312 | |
| 313 | for finding in regex.findall(url): |
| 314 | parsed[finding[-1]] = finding[0].rstrip(":") |
| 315 | |
| 316 | return parsed |