Skip to content

Commit cc87c97

Browse files
committed
feat(idp, open_browser): validate login URL for SAML plugin
1 parent 18df82f commit cc87c97

5 files changed

+19
-1
lines changed

redshift_connector/plugin/browser_azure_credentials_provider.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -232,5 +232,5 @@ def open_browser(self: "BrowserAzureCredentialsProvider", state: str) -> None:
232232
"&redirect_uri={uri}"
233233
"&state={state}".format(tenant=self.idp_tenant, id=self.client_id, uri=self.redirectUri, state=state)
234234
)
235-
235+
self.validate_url(url)
236236
webbrowser.open(url)

redshift_connector/plugin/browser_azure_oauth2_credentials_provider.py

+1
Original file line numberDiff line numberDiff line change
@@ -165,6 +165,7 @@ def open_browser(self: "BrowserAzureOAuth2CredentialsProvider", state: str) -> N
165165

166166
if url is None:
167167
raise InterfaceError("the login_url could not be empty")
168+
self.validate_url(url)
168169
webbrowser.open(url)
169170

170171
def get_listen_socket(self: "BrowserAzureOAuth2CredentialsProvider") -> socket.socket:

redshift_connector/plugin/browser_saml_credentials_provider.py

+1
Original file line numberDiff line numberDiff line change
@@ -109,4 +109,5 @@ def open_browser(self: "BrowserSamlCredentialsProvider") -> None:
109109

110110
if url is None:
111111
raise InterfaceError("the login_url could not be empty")
112+
self.validate_url(url)
112113
webbrowser.open(url)

redshift_connector/plugin/idp_credentials_provider.py

+6
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import typing
22
from abc import ABC, abstractmethod
33

4+
from redshift_connector.error import InterfaceError
45
from redshift_connector.redshift_property import RedshiftProperty
56

67
if typing.TYPE_CHECKING:
@@ -39,3 +40,8 @@ def add_parameter(self: "IdpCredentialsProvider", info: RedshiftProperty) -> Non
3940
Defines instance attributes from the :class:RedshiftProperty object associated with the current authentication session.
4041
"""
4142
pass # pragma: no cover
43+
44+
@classmethod
45+
def validate_url(cls, uri: str) -> None:
46+
if not uri.startswith("https"):
47+
raise InterfaceError("URI: {} is an invalid web address".format(uri))

test/unit/plugin/test_browser_saml_credentials_provider.py

+10
Original file line numberDiff line numberDiff line change
@@ -99,3 +99,13 @@ def test_open_browser_no_url_should_fail():
9999
with pytest.raises(InterfaceError) as ex:
100100
browser_saml_credentials.open_browser()
101101
assert "the login_url could not be empty" in str(ex.value)
102+
103+
104+
@pytest.mark.parametrize("url", ["test", "1234", "file.txt", "file:///"])
105+
def test_open_browser_invalid_url_should_fail(url):
106+
browser_saml_credentials: BrowserSamlCredentialsProvider = BrowserSamlCredentialsProvider()
107+
browser_saml_credentials.login_url = url
108+
109+
with pytest.raises(InterfaceError) as ex:
110+
browser_saml_credentials.open_browser()
111+
assert "is an invalid web address" in str(ex.value)

0 commit comments

Comments
 (0)