|
1 | 1 | from flask import request
|
2 | 2 |
|
3 | 3 | import requests
|
4 |
| - |
| 4 | +import re |
5 | 5 |
|
6 | 6 | def full_ssrf():
|
7 | 7 | user_input = request.args['untrusted_input']
|
@@ -120,3 +120,57 @@ def partial_ssrf_6():
|
120 | 120 |
|
121 | 121 | url = f"https://example.com/foo#{user_input}"
|
122 | 122 | requests.get(url) # NOT OK -- user only controlled fragment
|
| 123 | + |
| 124 | +def partial_ssrf_7(): |
| 125 | + user_input = request.args['untrusted_input'] |
| 126 | + |
| 127 | + if user_input.isalnum(): |
| 128 | + url = f"https://example.com/foo#{user_input}" |
| 129 | + requests.get(url) # OK - user input can only contain alphanumerical characters |
| 130 | + |
| 131 | + if user_input.isalpha(): |
| 132 | + url = f"https://example.com/foo#{user_input}" |
| 133 | + requests.get(url) # OK - user input can only contain alphabetical characters |
| 134 | + |
| 135 | + if user_input.isdecimal(): |
| 136 | + url = f"https://example.com/foo#{user_input}" |
| 137 | + requests.get(url) # OK - user input can only contain decimal characters |
| 138 | + |
| 139 | + if user_input.isdigit(): |
| 140 | + url = f"https://example.com/foo#{user_input}" |
| 141 | + requests.get(url) # OK - user input can only contain digits |
| 142 | + |
| 143 | + if user_input.isnumeric(): |
| 144 | + url = f"https://example.com/foo#{user_input}" |
| 145 | + requests.get(url) # OK - user input can only contain numeric characters |
| 146 | + |
| 147 | + if user_input.isspace(): |
| 148 | + url = f"https://example.com/foo#{user_input}" |
| 149 | + requests.get(url) # OK - user input can only contain whitespace characters |
| 150 | + |
| 151 | + if re.fullmatch(r'[a-zA-Z0-9]+', user_input): |
| 152 | + url = f"https://example.com/foo#{user_input}" |
| 153 | + requests.get(url) # OK - user input can only contain alphanumerical characters |
| 154 | + |
| 155 | + if re.fullmatch(r'.*[a-zA-Z0-9]+.*', user_input): |
| 156 | + url = f"https://example.com/foo#{user_input}" |
| 157 | + requests.get(url) # NOT OK, but NOT FOUND - user input can contain arbitrary characters |
| 158 | + |
| 159 | + |
| 160 | + if re.match(r'^[a-zA-Z0-9]+$', user_input): |
| 161 | + url = f"https://example.com/foo#{user_input}" |
| 162 | + requests.get(url) # OK - user input can only contain alphanumerical characters |
| 163 | + |
| 164 | + if re.match(r'[a-zA-Z0-9]+', user_input): |
| 165 | + url = f"https://example.com/foo#{user_input}" |
| 166 | + requests.get(url) # NOT OK, but NOT FOUND - user input can contain arbitrary character as a suffix. |
| 167 | + |
| 168 | + reg = re.compile(r'^[a-zA-Z0-9]+$') |
| 169 | + |
| 170 | + if reg.match(user_input): |
| 171 | + url = f"https://example.com/foo#{user_input}" |
| 172 | + requests.get(url) # OK - user input can only contain alphanumerical characters |
| 173 | + |
| 174 | + if reg.fullmatch(user_input): |
| 175 | + url = f"https://example.com/foo#{user_input}" |
| 176 | + requests.get(url) # OK - user input can only contain alphanumerical characters |
0 commit comments