Skip to content

Commit 4a2ae4d

Browse files
committed
feat(formating): mask sensitive data
1 parent bc48a20 commit 4a2ae4d

File tree

1 file changed

+25
-3
lines changed

1 file changed

+25
-3
lines changed

src/TelegramFormatter.php

Lines changed: 25 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -144,9 +144,9 @@ protected function getMessageForException($exception)
144144
}
145145
}
146146

147-
$message .= PHP_EOL . '<b>Request Inputs:</b> <pre>' . str_replace(
148-
["\n", " ", '<' , '>'], ['', '' , '&lt;', '&gt;'], json_encode($request->except('password', 'password_confirmation'), JSON_UNESCAPED_UNICODE)
149-
) . '</pre>';
147+
$message .= PHP_EOL . '*Request Inputs:* `' . str_replace(
148+
["\n", " ", '<', '>'], ['', '', '&lt;', '&gt;'], json_encode($this->maskSensitiveData($request), JSON_UNESCAPED_UNICODE)
149+
) . '`';
150150

151151
$message .= PHP_EOL . PHP_EOL . '<b>Trace: </b> ' . PHP_EOL . '<b> => </b> => ' . substr($exception->getTraceAsString(), 0, 1000) . ' ...';
152152

@@ -229,4 +229,26 @@ protected function getSeverityName($key)
229229
}
230230
return '';
231231
}
232+
233+
protected function maskSensitiveData($request): array
234+
{
235+
$sensitiveFields = [
236+
'password',
237+
'auth',
238+
'token',
239+
'key',
240+
'credential',
241+
'secret',
242+
'password_confirmation'
243+
];
244+
245+
$data = $request->except($sensitiveFields);
246+
247+
$maskedData = $request->only($sensitiveFields);
248+
foreach ($maskedData as $key => &$value) {
249+
$value = '*';
250+
}
251+
252+
return array_merge($data, $maskedData);
253+
}
232254
}

0 commit comments

Comments
 (0)