Skip to content

Commit

Permalink
[#512] Masks consumerKey and consumerSecret in all debug logs (#514)
Browse files Browse the repository at this point in the history
  • Loading branch information
shadcn authored Oct 29, 2020
1 parent 8b5e0a6 commit c4140b4
Showing 1 changed file with 14 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,20 @@ abstract protected function getFormatter(): Formatter;
public function formatResponse(ResponseInterface $response, RequestInterface $request): string {
if ($this->removeCredentials) {
$request = $request->withoutHeader('Authorization');
$masks = [
'consumerKey' => '***consumer-key***',
'consumerSecret' => '***consumer-secret***',
];
$json = json_decode((string) $response->getBody(), TRUE);
if (json_last_error() === JSON_ERROR_NONE) {
array_walk_recursive($json, function (&$value, $key) use ($masks) {
if (isset($masks[$key])) {
$value = $masks[$key];
}
});
$response = $response->withBody(Psr7\stream_for(json_encode((object) $json, JSON_PRETTY_PRINT)));
}

if ($request->getMethod() === 'POST' && $request->getUri()->getPath() === '/oauth/token') {
$json = json_decode((string) $response->getBody(), TRUE);
if (json_last_error() === JSON_ERROR_NONE) {
Expand Down

0 comments on commit c4140b4

Please sign in to comment.