Skip to content

Commit d59f721

Browse files
committed
python: add test for header injection
1 parent 1c2d8bb commit d59f721

File tree

1 file changed

+22
-0
lines changed
  • python/ql/test/query-tests/Security/CWE-113-HeaderInjection/Tests1

1 file changed

+22
-0
lines changed
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
from http.server import HTTPServer, BaseHTTPRequestHandler
2+
import urllib.parse
3+
4+
class VulnerableHandler(BaseHTTPRequestHandler):
5+
def do_GET(self):
6+
parsed_path = urllib.parse.urlparse(self.path)
7+
params = urllib.parse.parse_qs(parsed_path.query)
8+
input_value = params.get("input", [""])[0]
9+
# Unsafe: Directly including user input in headers
10+
self.send_response(200)
11+
try:
12+
self.send_header("X-Info", input_value) # BAD
13+
except Exception as e:
14+
print(f"[!] Header injection failed: {e}")
15+
self.end_headers()
16+
self.wfile.write(b"Hello world!")
17+
18+
19+
# if __name__ == "__main__":
20+
# print("Serving vulnerable app on http://127.0.0.1:8080")
21+
# httpd = HTTPServer(("127.0.0.1", 8080), VulnerableHandler)
22+
# httpd.serve_forever()

0 commit comments

Comments
 (0)