Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
45 changes: 41 additions & 4 deletions backend/views/api-log/view.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,19 @@
$this->params['breadcrumbs'][] = ['label' => Yii::t('app', 'Api Logs'), 'url' => ['index']];
$this->params['breadcrumbs'][] = $this->title;
\yii\web\YiiAsset::register($this);

$redactApiLogValue = function ($value) {
if ($value === null || $value === '') {
return $value;
}

$redacted = (string)$value;
$redacted = preg_replace('/\b(Authorization|Proxy-Authorization)\s*[:=]\s*(?:Bearer|Basic)?\s*[^\r\n,;]+/i', '$1: ***REDACTED***', $redacted);
$redacted = preg_replace('/\b(Bearer|Basic)\s+[A-Za-z0-9._~+\/=-]+/i', '$1 ***REDACTED***', $redacted);
$redacted = preg_replace('/([\'"]?(?:api[_-]?key|secret|token|access[_-]?token|refresh[_-]?token|password|client[_-]?secret)[\'"]?\s*[:=]\s*[\'"]?)[^\'",\r\n&]+/i', '$1***REDACTED***', $redacted);
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 Badge Redact bracketed key/value pairs from print_r payloads

Update the redaction pattern to handle print_r-style entries (e.g. [secret] => ...), because the current regex only matches keys followed directly by : or =. In this codebase, API log payloads are stored via print_r(..., true) (see common/components/TapPayments.php around the request_body/response_body assignments), so credential fields like api_key, secret, or token in those arrays will bypass this replacement and still be shown in the API log detail view.

Useful? React with 👍 / 👎.


return $redacted;
};
?>
<div class="api-log-view">

Expand All @@ -33,10 +46,34 @@
'restaurant_uuid',
'method',
'endpoint',
'request_headers:ntext',
'request_body:ntext',
'response_headers:ntext',
'response_body:ntext',
[
'attribute' => 'request_headers',
'format' => 'ntext',
'value' => function ($model) use ($redactApiLogValue) {
return $redactApiLogValue($model->request_headers);
},
],
[
'attribute' => 'request_body',
'format' => 'ntext',
'value' => function ($model) use ($redactApiLogValue) {
return $redactApiLogValue($model->request_body);
},
],
[
'attribute' => 'response_headers',
'format' => 'ntext',
'value' => function ($model) use ($redactApiLogValue) {
return $redactApiLogValue($model->response_headers);
},
],
[
'attribute' => 'response_body',
'format' => 'ntext',
'value' => function ($model) use ($redactApiLogValue) {
return $redactApiLogValue($model->response_body);
},
],
'created_at',
],
]) ?>
Expand Down
27 changes: 27 additions & 0 deletions tests/check-api-log-view-redaction.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
#!/usr/bin/env bash
set -euo pipefail

target="backend/views/api-log/view.php"

for direct in \
"request_headers:ntext" \
"request_body:ntext" \
"response_headers:ntext" \
"response_body:ntext"
do
if grep -q "$direct" "$target"; then
echo "api log view still renders $direct directly" >&2
exit 1
fi
done

grep -q "redactApiLogValue" "$target"
grep -q "Authorization" "$target"
grep -q "Bearer" "$target"
grep -q "Basic" "$target"
grep -q "api\\[_-\\]?key" "$target"
grep -q "secret" "$target"
grep -q "token" "$target"
grep -q "\\*\\*\\*REDACTED\\*\\*\\*" "$target"

echo "API log view redaction guard passed."