fix: check arg length (external liquid renderer)

This commit is contained in:
Benjamin Nussbaum 2025-11-06 14:17:36 +01:00
parent 02e695fe4d
commit 9c37352c17
2 changed files with 62 additions and 3 deletions

View file

@ -11,6 +11,7 @@ use App\Liquid\Filters\StandardFilters;
use App\Liquid\Filters\StringMarkup;
use App\Liquid\Filters\Uniqueness;
use App\Liquid\Tags\TemplateTag;
use App\Services\PluginImportService;
use Exception;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
@ -372,14 +373,14 @@ class Plugin extends Model
* @param array $context The render context data
* @return string The rendered HTML
*
* @throws LiquidException
* @throws Exception
*/
private function renderWithExternalLiquidRenderer(string $template, array $context): string
{
$liquidPath = config('services.trmnl.liquid_path');
if (empty($liquidPath)) {
throw new LiquidException('External liquid renderer path is not configured');
throw new Exception('External liquid renderer path is not configured');
}
// HTML encode the template
@ -389,9 +390,12 @@ class Plugin extends Model
$jsonContext = json_encode($context, JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES);
if ($jsonContext === false) {
throw new LiquidException('Failed to encode render context as JSON: '.json_last_error_msg());
throw new Exception('Failed to encode render context as JSON: '.json_last_error_msg());
}
// Validate argument sizes
app(PluginImportService::class)->validateExternalRendererArguments($encodedTemplate, $jsonContext, $liquidPath);
// Execute the external renderer
$process = Process::run([
$liquidPath,