Files
FOSSBilling/src/ipn.php
T
b49ccb9df8 Sanitize invoice handling, enhance security, and improve API responses (#3524)
* Sanitize invoice hash and secure asset paths

* Guard against missing client session

* Serialize invoice items into indexed inputs

* Validate URL field input type before checking

* Block legacy paid support hooks on ticket create

* Harden CSRF token validation in API client

* Add 'Paidsupport' to cspell word list

* Use Stripe metadata to link client and invoice

* Remove legacy Paidsupport hooks handling

* Add paidsupport to cspell word list

* Use config debug flag; always warn if install exists

* Revert "Use config debug flag; always warn if install exists"

This reverts commit fda6fcc0b05758d897a837d125ce1c0a35be0226.

* Fix for pull request finding

Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>

* Fix for pull request finding

Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>

* Fix Stripe getClientFromTransaction and simplify UpdatePatcher cache invalidation

Agent-Logs-Url: https://github.com/FOSSBilling/FOSSBilling/sessions/49a72bff-61f2-4a3e-9107-08aec7b255d2

Co-authored-by: admdly <2807620+admdly@users.noreply.github.com>

* Fix for pull request finding

Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>

* Restrict Dompdf logo remote URLs to http/https schemes only

Agent-Logs-Url: https://github.com/FOSSBilling/FOSSBilling/sessions/58c16027-cc36-4c11-a039-0bfcaf5a45f5

Co-authored-by: admdly <2807620+admdly@users.noreply.github.com>

* Enable Buildx cache and add release archive

* Restrict `claimForProcessing` SQL and update tests

* Add HTML sanitizer and sandboxed Twig rendering

* Update test expected HTML in ServiceTest

* Add `RequestFactory` and trusted proxy support

* Use HttpFoundation Responses & Request everywhere

* Return HTTP Response objects for exports/downloads

* Refactor request routing, auth errors and CSV export

* Remove RequestFactory wrapper and minor cleanups

* Specify Response union return types

* Parenthesize response constructions before send

* Clean up PHPStan ignore rules

* Relax HTML test to accept optional tbody/br

* fix(theme): call getUploadedAssets without arguments

Agent-Logs-Url: https://github.com/FOSSBilling/FOSSBilling/sessions/ce04bff6-ccde-4a10-8a68-f6278b1b550e

Co-authored-by: admdly <2807620+admdly@users.noreply.github.com>

---------

Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com>
Co-authored-by: admdly <2807620+admdly@users.noreply.github.com>
2026-05-12 00:10:49 +01:00

76 lines
2.3 KiB
PHP

<?php
declare(strict_types=1);
/**
* Copyright 2022-2025 FOSSBilling
* Copyright 2011-2021 BoxBilling, Inc.
* SPDX-License-Identifier: Apache-2.0.
*
* @copyright FOSSBilling (https://www.fossbilling.org)
* @license http://www.apache.org/licenses/LICENSE-2.0 Apache-2.0
*/
require_once __DIR__ . DIRECTORY_SEPARATOR . 'load.php';
use Symfony\Component\Filesystem\Path;
use Symfony\Component\HttpFoundation\JsonResponse;
use Symfony\Component\HttpFoundation\RedirectResponse;
/* @var Symfony\Component\HttpFoundation\Request $request */
global $request;
$di = include Path::join(PATH_ROOT, 'di.php');
$di['translate']();
$invoiceID = $request->get('invoice_id');
if ($invoiceID !== null) {
$invoiceID = filter_var($invoiceID, FILTER_VALIDATE_INT, ['options' => ['min_range' => 1]]);
if ($invoiceID === false) {
(new JsonResponse(['error' => ['message' => 'Invalid invoice ID']], 400))->send();
exit;
}
}
$gatewayID = $request->get('gateway_id');
if ($gatewayID !== null) {
$gatewayID = filter_var($gatewayID, FILTER_VALIDATE_INT, ['options' => ['min_range' => 1]]);
if ($gatewayID === false) {
(new JsonResponse(['error' => ['message' => 'Invalid gateway ID']], 400))->send();
exit;
}
}
$ipn = [
'invoice_id' => $invoiceID,
'gateway_id' => $gatewayID,
'source' => 'ipn',
'get' => $request->query->all(),
'post' => $request->request->all(),
'server' => $request->server->all(),
'http_raw_post_data' => $request->getContent(),
];
try {
$service = $di['mod_service']('invoice', 'transaction');
$output = $service->createAndProcess($ipn);
$res = ['result' => $output, 'error' => null];
} catch (Exception $e) {
$res = ['result' => null, 'error' => ['message' => $e->getMessage()]];
$output = false;
}
// redirect to invoice if gateways requires
if ($request->query->has('redirect') && $request->query->has('invoice_hash')) {
$invoiceHash = $request->query->get('invoice_hash');
$hash = preg_replace('/[^a-zA-Z0-9]/', '', is_string($invoiceHash) ? $invoiceHash : '');
$url = $di['url']->link('invoice/' . $hash);
(new RedirectResponse($url))->send();
exit;
}
(new JsonResponse($res, 200, [
'Cache-Control' => 'no-cache, must-revalidate',
'Expires' => 'Mon, 26 Jul 1997 05:00:00 GMT',
]))->send();
exit;