Skip to content

Commit a9b392e

Browse files
Fix code scanning alert no. 18: Full server-side request forgery
Co-authored-by: Copilot Autofix powered by AI <62310815+github-advanced-security[bot]@users.noreply.github.com>
1 parent 97e6a6f commit a9b392e

File tree

1 file changed

+6
-1
lines changed
  • End_to_end_Solutions/InsightsGenerator/insights_generator/core

1 file changed

+6
-1
lines changed

End_to_end_Solutions/InsightsGenerator/insights_generator/core/OAI_client.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,17 @@
33
import os
44
import pdb
55
import tiktoken
6+
import urllib.parse
7+
8+
def is_valid_url(url):
9+
parsed_url = urllib.parse.urlparse(url)
10+
return parsed_url.scheme in ["http", "https"] and parsed_url.netloc != ""
611

712
def make_prompt_request(prompt, max_tokens = 2048, timeout = 4):
813
# Whitelist of allowed URLs
914
allowed_urls = ["https://api.openai.com/v1/embeddings", "https://another-trusted-url.com"]
1015
url = os.getenv("AOAI_ENDPOINT")
11-
if url not in allowed_urls:
16+
if not is_valid_url(url) or url not in allowed_urls:
1217
raise ValueError("The provided URL is not allowed.")
1318
key = os.getenv("AOAI_KEY")
1419

0 commit comments

Comments
 (0)