Skip to content
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

Validate scheme of next URL #85

Merged
merged 1 commit into from
Aug 23, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions CHANGES.rst
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
Changelog
=========

Version 0.5.5
-------------

- Ensure only valid schemas (http and https) can be used when validating the ``next`` URL

Version 0.5.4
-------------

Expand Down
2 changes: 1 addition & 1 deletion flask_multipass/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
from .identity import IdentityProvider


__version__ = '0.5.4'
__version__ = '0.5.5'
__all__ = ('Multipass', 'AuthProvider', 'IdentityProvider', 'AuthInfo', 'IdentityInfo', 'Group', 'MultipassException',
'AuthenticationFailed', 'IdentityRetrievalFailed', 'GroupRetrievalFailed', 'NoSuchUser',
'InvalidCredentials')
2 changes: 2 additions & 0 deletions flask_multipass/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,8 @@ def validate_next_url(self, url):
a whitelist of trusted hosts to avoid creating an open redirector.
"""
url_info = urlsplit(url)
if url_info.scheme and url_info.scheme not in {'http', 'https'}:
return False
return not url_info.netloc or url_info.netloc == request.host

def process_login(self, provider=None):
Expand Down
1 change: 1 addition & 0 deletions tests/test_core.py
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,7 @@ def test_next_url_invalid():
('//evil.com:80', False),
('http://evil.com', False),
('https://evil.com', False),
('javascript:alert("eeeeeeeevil")', False),
))
def test_validate_next_url(url, valid):
app = Flask('test')
Expand Down