Repository navigation
feat: add SSRF allowlist #8993
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
bakirFS
wants to merge
2
commits into
main
Choose a base branch
from
feat/ssrf-allowed-hosts
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+104
−1
Open
feat: add SSRF allowlist #8993
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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 hidden or 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,57 @@ | ||
| import socket | ||
|
|
||
| import pytest | ||
| from django.core.exceptions import ValidationError | ||
| from pytest_django.fixtures import SettingsWrapper | ||
| from pytest_mock import MockerFixture | ||
|
|
||
| from core.validators import validate_no_internal_address | ||
|
|
||
|
|
||
| @pytest.mark.parametrize( | ||
| "url, allowed_host", | ||
| [ | ||
| ("http://hooks.internal.example.com/", "hooks.internal.example.com"), | ||
| ("http://hooks.internal.example.com/", ".internal.example.com"), | ||
| ("http://hooks.internal.example.com/", "*.internal.example.com"), | ||
| ("http://10.0.0.5/", "10.0.0.5"), | ||
| ("http://[fd00::1]/", "[fd00::1]"), | ||
| ("http://127.0.0.1/", "*"), | ||
| ], | ||
| ) | ||
| def test_validate_no_internal_address__host_allowed__does_not_raise( | ||
| settings: SettingsWrapper, | ||
| mocker: MockerFixture, | ||
| url: str, | ||
| allowed_host: str, | ||
| ) -> None: | ||
| # Given | ||
| settings.SSRF_ALLOWED_HOSTS = [allowed_host] | ||
| mocker.patch( | ||
| "core.network.socket.getaddrinfo", | ||
| return_value=[(socket.AF_INET, None, None, None, ("10.0.0.5", 0))], | ||
| ) | ||
|
|
||
| # When / Then | ||
| validate_no_internal_address(url) | ||
|
|
||
|
|
||
| @pytest.mark.parametrize("allowed_hosts", [[], ["other.example.com"]]) | ||
| def test_validate_no_internal_address__host_not_allowed__raises_validation_error( | ||
| settings: SettingsWrapper, | ||
| mocker: MockerFixture, | ||
| allowed_hosts: list[str], | ||
| ) -> None: | ||
| # Given | ||
| settings.SSRF_ALLOWED_HOSTS = allowed_hosts | ||
| mocker.patch( | ||
| "core.network.socket.getaddrinfo", | ||
| return_value=[(socket.AF_INET, None, None, None, ("10.0.0.5", 0))], | ||
| ) | ||
|
|
||
| # When | ||
| with pytest.raises(ValidationError) as exc_info: | ||
| validate_no_internal_address("http://hooks.internal.example.com/") | ||
|
|
||
| # Then | ||
| assert exc_info.value.code == "internal_address" |
This file contains hidden or 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 hidden or 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.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Document the subdomain scope of a leading-dot entry.
A leading dot trusts the domain and all its subdomains. For example,
.internal.example.comalso trusts every name underinternal.example.com. An operator who only intends to trustinternal.example.comcan therefore trust more hosts than planned. A subdomain under that domain that resolves to a private address can then be used as a webhook or integration target. The practical risk depends on who can create names under the trusted domain.State this scope in the entry, and show the exact-host form for narrow access. A value without a leading dot matches only that host.
Suggested documentation change
Scope reference: Django
validate_hostCommittable suggestion
LanguageTool
[typographical] ~17-~17: Two consecutive dots
Context: ...solve to a private network address, e.g.
.internal.example.com. -DATABASE_URL: The URL of your Postg...(DOUBLE_PUNCTUATION)