Skip to content

Commit

Permalink
Fix code scanning alert no. 18: Full server-side request forgery
Browse files Browse the repository at this point in the history
Co-authored-by: Copilot Autofix powered by AI <62310815+github-advanced-security[bot]@users.noreply.github.com>
  • Loading branch information
1 parent 97e6a6f commit a9b392e
Showing 1 changed file with 6 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,17 @@
import os
import pdb
import tiktoken
import urllib.parse

def is_valid_url(url):
parsed_url = urllib.parse.urlparse(url)
return parsed_url.scheme in ["http", "https"] and parsed_url.netloc != ""

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

Expand Down

0 comments on commit a9b392e

Please sign in to comment.