Skip to content

Commit 56e39dc

Browse files
committed
Remove effectiveless in-place clean
1 parent e3232c9 commit 56e39dc

File tree

2 files changed

+25
-24
lines changed

2 files changed

+25
-24
lines changed

msal/application.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1182,7 +1182,7 @@ def _acquire_token_by_cloud_shell(self, scopes, data=None):
11821182
client_id=self.client_id,
11831183
scope=response["scope"].split() if "scope" in response else scopes,
11841184
token_endpoint=self.authority.token_endpoint,
1185-
response=response.copy(),
1185+
response=response,
11861186
data=data or {},
11871187
authority_type=_AUTHORITY_TYPE_CLOUDSHELL,
11881188
))
@@ -1399,7 +1399,7 @@ def _process_broker_response(self, response, scopes, data):
13991399
client_id=self.client_id,
14001400
scope=response["scope"].split() if "scope" in response else scopes,
14011401
token_endpoint=self.authority.token_endpoint,
1402-
response=response.copy(),
1402+
response=response,
14031403
data=data,
14041404
_account_id=response["_account_id"],
14051405
))

msal/token_cache.py

Lines changed: 23 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -103,29 +103,30 @@ def find(self, credential_type, target=None, query=None):
103103

104104
def add(self, event, now=None):
105105
# type: (dict) -> None
106-
"""Handle a token obtaining event, and add tokens into cache.
107-
108-
Known side effects: This function modifies the input event in place.
109-
"""
110-
def wipe(dictionary, sensitive_fields): # Masks sensitive info
111-
for sensitive in sensitive_fields:
112-
if sensitive in dictionary:
113-
dictionary[sensitive] = "********"
114-
wipe(event.get("data", {}),
115-
("password", "client_secret", "refresh_token", "assertion"))
116-
try:
117-
return self.__add(event, now=now)
118-
finally:
119-
wipe(event.get("response", {}), ( # These claims were useful during __add()
106+
"""Handle a token obtaining event, and add tokens into cache."""
107+
def make_clean_copy(dictionary, sensitive_fields): # Masks sensitive info
108+
return {
109+
k: "********" if k in sensitive_fields else v
110+
for k, v in dictionary.items()
111+
}
112+
clean_event = dict(
113+
event,
114+
data=make_clean_copy(event.get("data", {}), (
115+
"password", "client_secret", "refresh_token", "assertion",
116+
)),
117+
response=make_clean_copy(event.get("response", {}), (
120118
"id_token_claims", # Provided by broker
121-
"access_token", "refresh_token", "id_token", "username"))
122-
wipe(event, ["username"]) # Needed for federated ROPC
123-
logger.debug("event=%s", json.dumps(
124-
# We examined and concluded that this log won't have Log Injection risk,
125-
# because the event payload is already in JSON so CR/LF will be escaped.
126-
event, indent=4, sort_keys=True,
127-
default=str, # A workaround when assertion is in bytes in Python 3
128-
))
119+
"access_token", "refresh_token", "id_token", "username",
120+
)),
121+
)
122+
logger.debug("event=%s", json.dumps(
123+
# We examined and concluded that this log won't have Log Injection risk,
124+
# because the event payload is already in JSON so CR/LF will be escaped.
125+
clean_event,
126+
indent=4, sort_keys=True,
127+
default=str, # assertion is in bytes in Python 3
128+
))
129+
return self.__add(event, now=now)
129130

130131
def __parse_account(self, response, id_token_claims):
131132
"""Return client_info and home_account_id"""

0 commit comments

Comments
 (0)