A free open source IT asset/license management system
add validation to font for label import
Godfrey M7b3e58b112bd
diff --git a/app/Models/Labels/CustomLabelFonts.php b/app/Models/Labels/CustomLabelFonts.phpnew file mode 100644index 0000000000..c2c292b66d--- /dev/null+++ b/app/Models/Labels/CustomLabelFonts.php@@ -0,0 +1,9 @@+<?php++namespace App\Models\Labels;++final class CustomLabelFonts+{+ /** Fonts the customizer exposes — the only names allowed to reach TCPDF. */+ public const ALLOWED = ['freemono', 'freesans', 'dejavusans'];+}\ No newline at end of filediff --git a/app/Services/CustomLabelImportValidator.php b/app/Services/CustomLabelImportValidator.phpindex f8f51f3e66..6f64d3e552 100644--- a/app/Services/CustomLabelImportValidator.php+++ b/app/Services/CustomLabelImportValidator.php@@ -3,6 +3,8 @@namespace App\Services;use Illuminate\Validation\ValidationException;+use Illuminate\Validation\Rule;+use App\Models\Labels\CustomLabelFonts;class CustomLabelImportValidator{public function validate(?string $rawJson): array@@ -100,10 +102,10 @@ class CustomLabelImportValidator'content.field_value_font_size' => ['required', 'numeric'],'content.field_value_margin' => ['required', 'numeric'],- 'content.tag_font' => ['nullable', 'string'],- 'content.title_font' => ['nullable', 'string'],- 'content.field_label_font' => ['nullable', 'string'],- 'content.field_value_font' => ['nullable', 'string'],+ 'content.tag_font' => ['nullable', 'string', Rule::in(CustomLabelFonts::ALLOWED)],+ 'content.title_font' => ['nullable', 'string', Rule::in(CustomLabelFonts::ALLOWED)],+ 'content.field_label_font' => ['nullable', 'string', Rule::in(CustomLabelFonts::ALLOWED)],+ 'content.field_value_font' => ['nullable', 'string', Rule::in(CustomLabelFonts::ALLOWED)],];}