-
Notifications
You must be signed in to change notification settings - Fork 44.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix (backend): Patching the SSRF vulnerability in Github/Web Search/R…
…equest related blocks (#8531)
- Loading branch information
1 parent
c25d03e
commit bcaf324
Showing
20 changed files
with
362 additions
and
406 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
from urllib.parse import urlparse | ||
|
||
from backend.blocks.github._auth import GithubCredentials | ||
from backend.util.request import Requests | ||
|
||
|
||
def _convert_to_api_url(url: str) -> str: | ||
""" | ||
Converts a standard GitHub URL to the corresponding GitHub API URL. | ||
Handles repository URLs, issue URLs, pull request URLs, and more. | ||
""" | ||
parsed_url = urlparse(url) | ||
path_parts = parsed_url.path.strip("/").split("/") | ||
|
||
if len(path_parts) >= 2: | ||
owner, repo = path_parts[0], path_parts[1] | ||
api_base = f"https://api.github.com/repos/{owner}/{repo}" | ||
|
||
if len(path_parts) > 2: | ||
additional_path = "/".join(path_parts[2:]) | ||
api_url = f"{api_base}/{additional_path}" | ||
else: | ||
# Repository base URL | ||
api_url = api_base | ||
else: | ||
raise ValueError("Invalid GitHub URL format.") | ||
|
||
return api_url | ||
|
||
|
||
def _get_headers(credentials: GithubCredentials) -> dict[str, str]: | ||
return { | ||
"Authorization": credentials.bearer(), | ||
"Accept": "application/vnd.github.v3+json", | ||
} | ||
|
||
|
||
def get_api(credentials: GithubCredentials) -> Requests: | ||
return Requests( | ||
trusted_origins=["https://api.github.com", "https://github.com"], | ||
extra_url_validator=_convert_to_api_url, | ||
extra_headers=_get_headers(credentials), | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.