-
Notifications
You must be signed in to change notification settings - Fork 154
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
ISS 983 Allow for side redirects with new configuration #984
Closed
mchineboy
wants to merge
17
commits into
pallets-eco:master
from
mchineboy:ISS-983-Allow-Side-Redirects
Closed
Changes from all commits
Commits
Show all changes
17 commits
Select commit
Hold shift + click to select a range
b746ad1
ISS 983 Allow for side redirects with new configuration
5ed6afa
Replace mismatched configuration reference.
878a561
Update docs
3319e2a
update documentation with emphasis
f26fbb8
Misspelled ALLOWED -> ALLOW
7c6855f
ALLOW -> MATCH pulling the wrong configuration
f8f2aa6
Missing a proper return if REDIRECT_ALLOW_SUBDOMAINS was False.
cabc191
Address styling issues in the test suite.
935e947
Fix varying style issues.
dba7ae3
Strict matching only, no fuzzy matching allowed.
a2ee546
Simplified logic, and all tests pass.
e5f3da0
Adjust the documentation to match the new logic.
7543ec9
Adjusted the Changelog
4942c63
fix styling issue
4966715
updated tests to demonstrate side-domain desired effect.
3ff6402
revert SERVER_NAME change.
d44ba2b
Add in TLS check,remove all print debug statements
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 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
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
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 |
---|---|---|
|
@@ -171,13 +171,54 @@ def test_authenticate_with_invalid_subdomain_next(app, client, get_message): | |
assert get_message("INVALID_REDIRECT") in response.data | ||
|
||
|
||
def test_authenticate_with_subdomain_match_next_strict(app, client, get_message): | ||
app.config["SERVER_NAME"] = "lp.com" | ||
app.config["SECURITY_REDIRECT_ALLOW_SUBDOMAINS"] = True | ||
app.config["SECURITY_REDIRECT_MATCH_SUBDOMAINS"] = ["sub.lp.com"] | ||
data = dict(email="[email protected]", password="password") | ||
response = client.post("/login?next=http://sub.lp.com", data=data) | ||
assert response.status_code == 302 | ||
|
||
|
||
def test_authenticate_with_subdomain_match_next_strict_invalid( | ||
app, client, get_message | ||
): | ||
app.config["SERVER_NAME"] = "lp.com" | ||
app.config["SECURITY_REDIRECT_ALLOW_SUBDOMAINS"] = True | ||
app.config["SECURITY_REDIRECT_MATCH_SUBDOMAINS"] = ["foo.lp.com"] | ||
data = dict(email="[email protected]", password="password") | ||
response = client.post("/login?next=http://sub.lp.com", data=data) | ||
assert get_message("INVALID_REDIRECT") in response.data | ||
|
||
|
||
def test_authenticate_with_subdomain_next_default_config(app, client, get_message): | ||
app.config["SERVER_NAME"] = "lp.com" | ||
data = dict(email="[email protected]", password="password") | ||
response = client.post("/login?next=http://sub.lp.com", data=data) | ||
assert get_message("INVALID_REDIRECT") in response.data | ||
|
||
|
||
def test_authenticate_with_subdomain_next_invalid_domain(app, client, get_message): | ||
app.config["SERVER_NAME"] = "lp.com" | ||
app.config["SECURITY_REDIRECT_ALLOW_SUBDOMAINS"] = True | ||
app.config["SECURITY_REDIRECT_MATCH_SUBDOMAINS"] = [ | ||
"github.com", | ||
"something.github.com", | ||
] | ||
data = dict(email="[email protected]", password="password") | ||
response = client.post("/login?next=http://sub.lp.net", data=data) | ||
assert get_message("INVALID_REDIRECT") in response.data | ||
|
||
|
||
def test_authenticate_with_subdomain_next_app_context(app, client, get_message): | ||
app.config["SERVER_NAME"] = "application.lp.com" | ||
app.config["SECURITY_REDIRECT_ALLOW_SUBDOMAINS"] = True | ||
app.config["SECURITY_REDIRECT_MATCH_SUBDOMAINS"] = ["sub.lp.com"] | ||
data = dict(email="[email protected]", password="password") | ||
response = client.post("/login?next=http://sub.lp.com", data=data) | ||
assert response.status_code == 302 | ||
|
||
|
||
def test_authenticate_case_insensitive_email(app, client): | ||
response = authenticate(client, "[email protected]", follow_redirects=True) | ||
assert b"Welcome [email protected]" in response.data | ||
|
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.
This is getting close! and much simpler. However - I still think this is enabling redirects to arbitrary hosts - not just subdomains. I don't think your use case needs that and would be a bigger/more risky change. To that end REDIRECT_MATCH_SUBDOMAINS should really be a list of subdomains - as in ["auth", "app", "mktg.app"] and this check should be something like:
if any(f"{n}.{base_domain}" == url_next.netloc for n in allowed_subdomains):
Of course requiring base_domain (e.g. SERVER_NAME) to be set and should always allow url_next.netloc == base_domain right?
Does that make sense?
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.
Hopefully the latest change resolves this, and my explanation further down explains the desired functionality.