Skip to content

Commit 2efef9e

Browse files
author
xboard
committed
fix(security): prevent payment gateway credentials leakage via OrderResource
1 parent df77cbf commit 2efef9e

4 files changed

Lines changed: 13 additions & 3 deletions

File tree

app/Http/Controllers/V2/Admin/PaymentController.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ public function getPaymentMethods()
2525

2626
public function fetch()
2727
{
28-
$payments = Payment::orderBy('sort', 'ASC')->get();
28+
$payments = Payment::orderBy('sort', 'ASC')->get()->makeVisible('config');
2929
foreach ($payments as $k => $v) {
3030
$notifyUrl = url("/api/v1/guest/payment/notify/{$v->payment}/{$v->uuid}");
3131
if ($v->notify_domain) {

app/Http/Resources/OrderResource.php

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,12 @@ public function toArray(Request $request): array
2323
...parent::toArray($request),
2424
'period' => PlanService::getLegacyPeriod((string)$this->period),
2525
'plan' => $this->whenLoaded('plan', fn() => PlanResource::make($this->plan)),
26+
'payment' => $this->whenLoaded('payment', fn() => $this->payment ? [
27+
'id' => $this->payment->id,
28+
'name' => $this->payment->name,
29+
'payment' => $this->payment->payment,
30+
'icon' => $this->payment->icon,
31+
] : null),
2632
];
2733
}
2834
}

app/Models/Payment.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,4 +15,8 @@ class Payment extends Model
1515
'config' => 'array',
1616
'enable' => 'boolean'
1717
];
18+
19+
protected $hidden = [
20+
'config',
21+
];
1822
}

app/Services/PaymentService.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,14 +29,14 @@ public function __construct($method, $id = NULL, $uuid = NULL)
2929
if (!$paymentModel) {
3030
throw new ApiException('payment not found');
3131
}
32-
$payment = $paymentModel->toArray();
32+
$payment = $paymentModel->makeVisible('config')->toArray();
3333
}
3434
if ($uuid) {
3535
$paymentModel = Payment::where('uuid', $uuid)->first();
3636
if (!$paymentModel) {
3737
throw new ApiException('payment not found');
3838
}
39-
$payment = $paymentModel->toArray();
39+
$payment = $paymentModel->makeVisible('config')->toArray();
4040
}
4141

4242
$this->config = [];

0 commit comments

Comments
 (0)