Skip to content
This repository was archived by the owner on Sep 29, 2023. It is now read-only.

Commit a4366c5

Browse files
jmstimsorayluo
authored andcommitted
Enable dynamic whitelisting of dSTS endpoints to support new buildouts (#215)
* Whitelisting dsts endpoints. * adding whitespace * changing back WORLD_WIDE_AUTHORITY * add whitelist function add whitelist function so dsts hosts pass validation. * Adding unit tests Adding unit test to test static instance discovery of dsts enpoints and validating of a dsts endpoint in AuthenticationContext. * fixed whitespace * fix syntax error * Fix whitespace * fix more spaces * Respond to PR comments Remove unnecessary white space, add documentation to whitelist, use self.fail in unit test. * Enable endpoint discovery Change dSTS host whitelisting to dynamic discovery of endpoints containing dsts. * Fix whitespace Fix whitespace * Update test_authority.py Fix dSTS test endpoint value to correct format. * Update test_authority.py Fix dsts test endpoint. * Update authority.py Update whitelist funtion to only check for ".dsts." in url.
1 parent 094812c commit a4366c5

File tree

3 files changed

+5
-15
lines changed

3 files changed

+5
-15
lines changed

adal/authority.py

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -63,10 +63,9 @@ def url(self):
6363
return self._url.geturl()
6464

6565
def _whitelisted(self): # testing if self._url.hostname is a dsts whitelisted domain
66-
for domain in AADConstants.WHITELISTED_DOMAINS:
67-
if self._url.hostname.endswith(domain):
68-
return True
69-
return False
66+
# Add dSTS domains to whitelist based on based on domain
67+
# https://microsoft.sharepoint.com/teams/AzureSecurityCompliance/Security/SitePages/dSTS%20Fundamentals.aspx
68+
return ".dsts." in self._url.hostname
7069

7170
def _validate_authority_url(self):
7271

adal/constants.py

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -217,15 +217,6 @@ class AADConstants(object):
217217
'login.microsoftonline.us',
218218
'login.microsoftonline.de',
219219
]
220-
WHITELISTED_DOMAINS = [
221-
# Define dSTS domains whitelist based on its Supported Environments & National Clouds list here
222-
# https://microsoft.sharepoint.com/teams/AzureSecurityCompliance/Security/SitePages/dSTS%20Fundamentals.aspx
223-
'dsts.core.windows.net',
224-
'dsts.core.chinacloudapi.cn',
225-
'dsts.core.cloudapi.de',
226-
'dsts.core.usgovcloudapi.net',
227-
'dsts.core.azure-test.net',
228-
]
229220
INSTANCE_DISCOVERY_ENDPOINT_TEMPLATE = 'https://{authorize_host}/common/discovery/instance?authorization_endpoint={authorize_endpoint}&api-version=1.0' # pylint: disable=invalid-name
230221
AUTHORIZE_ENDPOINT_PATH = '/oauth2/authorize'
231222
TOKEN_ENDPOINT_PATH = '/oauth2/token'

tests/test_authority.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ class TestAuthority(unittest.TestCase):
6060
# discovery.
6161
nonHardCodedAuthority = 'https://login.doesntexist.com/' + cp['tenant']
6262
nonHardCodedAuthorizeEndpoint = nonHardCodedAuthority + '/oauth2/authorize'
63-
dstsTestEndpoint = 'https://test-dsts.core.azure-test.net/dstsv2/common'
63+
dstsTestEndpoint = 'https://test-dsts.dsts.core.azure-test.net/dstsv2/common'
6464

6565

6666
def setUp(self):
@@ -130,7 +130,7 @@ def test_success_static_instance_discovery(self):
130130
self.performStaticInstanceDiscovery('test-dsts.dsts.core.chinacloudapi.cn')
131131
self.performStaticInstanceDiscovery('test-dsts.dsts.core.cloudapi.de')
132132
self.performStaticInstanceDiscovery('test-dsts.dsts.core.usgovcloudapi.net')
133-
self.performStaticInstanceDiscovery('test-dsts.core.azure-test.net')
133+
self.performStaticInstanceDiscovery('test-dsts.dsts.core.azure-test.net')
134134

135135

136136
@httpretty.activate

0 commit comments

Comments
 (0)