@@ -103,29 +103,30 @@ def find(self, credential_type, target=None, query=None):
103
103
104
104
def add (self , event , now = None ):
105
105
# 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" , {}), (
120
118
"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 )
129
130
130
131
def __parse_account (self , response , id_token_claims ):
131
132
"""Return client_info and home_account_id"""
0 commit comments