-
Notifications
You must be signed in to change notification settings - Fork 213
Escape username parameter #901
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -60,8 +60,8 @@ def send_request( | |
| return parse_response(resp.text) | ||
|
|
||
|
|
||
| def escape_password(password): | ||
| return (password.replace('&', '&').replace('"', '"') | ||
| def escape_xml(s): | ||
| return (s.replace('&', '&').replace('"', '"') | ||
| .replace("'", ''') # the only one not provided by cgi.escape(s, True) | ||
| .replace('<', '<').replace('>', '>')) | ||
|
|
||
|
|
@@ -116,7 +116,7 @@ def _build_rst(username, password, cloud_audience_urn, endpoint_address, soap_ac | |
| endpoint_address=endpoint_address, | ||
| time_now=wsu_time_format(now), | ||
| time_expire=wsu_time_format(now + timedelta(minutes=10)), | ||
| username=username, password=escape_password(password), | ||
| username=escape_xml(username), password=escape_xml(password), | ||
| wst=Mex.NS["wst"] if soap_action == Mex.ACTION_13 else Mex.NS["wst2005"], | ||
| applies_to=cloud_audience_urn, | ||
|
Comment on lines
116
to
121
|
||
| key_type='http://docs.oasis-open.org/ws-sx/ws-trust/200512/Bearer' | ||
|
|
||
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
|
|
@@ -31,6 +31,7 @@ | |||||
| from xml.etree import ElementTree as ET | ||||||
| import os | ||||||
|
|
||||||
| from msal.wstrust_request import _build_rst, escape_xml | ||||||
|
||||||
| from msal.wstrust_response import * | ||||||
|
|
||||||
| from tests import unittest | ||||||
|
|
@@ -96,3 +97,16 @@ def test_token_parsing_happy_path(self): | |||||
| self.assertEqual(result.get("type"), SAML_TOKEN_TYPE_V1) | ||||||
| self.assertIn(b"<saml:Assertion", result.get("token", "")) | ||||||
|
|
||||||
|
|
||||||
| class Test_WsTrustRequest(unittest.TestCase): | ||||||
|
||||||
| class Test_WsTrustRequest(unittest.TestCase): | |
| class TestWsTrustRequest(unittest.TestCase): |
Copilot
AI
Apr 8, 2026
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.
The tests import and call _build_rst, a private (underscore-prefixed) helper. This makes the test more brittle to internal refactors. If this behavior is intended to be stable, consider making it a supported helper (public name), or alternatively test via a public API boundary with mocking around I/O.
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.
The inline comment references
cgi.escape, which has been deprecated/removed in modern Python and is misleading here. Update the comment to reference an appropriate XML escaping utility (e.g.,xml.sax.saxutils.escape) or remove the historical note to avoid confusion.