Skip to content

Commit c9f4229

Browse files
committed
fix: validate URL scheme to allow only HTTP/HTTPS in knowledge base handler
1 parent f963721 commit c9f4229

File tree

1 file changed

+10
-0
lines changed
  • src/datapilot/core/knowledge

1 file changed

+10
-0
lines changed

src/datapilot/core/knowledge/cli.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,16 @@ def do_GET(self):
5151
def handle_knowledge_base(self, public_id):
5252
"""Fetch and return knowledge base data."""
5353
url = f"{backend_url}/knowledge_bases/public/{public_id}"
54+
55+
# Validate URL scheme for security
56+
parsed_url = urlparse(url)
57+
if parsed_url.scheme not in ('http', 'https'):
58+
self.send_response(400)
59+
self.send_header("Content-Type", "application/json")
60+
self.end_headers()
61+
error_msg = json.dumps({"error": "Invalid URL scheme. Only HTTP and HTTPS are allowed."})
62+
self.wfile.write(error_msg.encode("utf-8"))
63+
return
5464

5565
headers = {"Authorization": f"Bearer {token}", "X-Tenant": instance_name, "Content-Type": "application/json"}
5666

0 commit comments

Comments
 (0)