Skip to content

Commit

Permalink
Minor fixes for purify
Browse files Browse the repository at this point in the history
  • Loading branch information
turbo124 committed Jan 6, 2025
1 parent d4c7ea6 commit 45db150
Showing 1 changed file with 28 additions and 1 deletion.
29 changes: 28 additions & 1 deletion app/Services/Pdf/Purify.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,11 @@ class Purify
'img', 'a',

// Template specific
'ninja'
'ninja',

// SVG Elements
'svg', 'path', 'rect', 'circle', 'ellipse', 'line', 'polyline',
'polygon', 'g', 'text', 'tspan', 'defs', 'use', 'title',
];

private static array $allowed_attributes = [
Expand All @@ -50,6 +54,24 @@ class Purify
'data-element' => ['*'],
'data-state' => ['*'],

//SVG
'd' => ['*'],
'viewBox' => ['*'],
'xmlns' => ['http://www.w3.org/2000/svg'],
'fill' => ['*'],
'stroke' => ['*'],
'stroke-width' => ['*'],
'cx' => ['*'],
'cy' => ['*'],
'r' => ['*'],
'x' => ['*'],
'y' => ['*'],
'transform' => ['*'],
'points' => ['*'],
'preserveAspectRatio' => ['*'],
'version' => ['*'],
'xlink:href' => ['#*'], // Only allow internal references

// Layout & Presentation
'align' => ['left', 'center', 'right', 'justify'],
'valign' => ['top', 'middle', 'bottom', 'baseline'],
Expand Down Expand Up @@ -164,6 +186,11 @@ private static function isAllowedScript(string $script): bool

// Check for dangerous patterns
$dangerous_patterns = [
'/<svg[^>]*>[^<]*<script/i',
'/<svg[^>]*>[^<]*<handler\b/i',
'/<svg[^>]*>[^<]*<animate/i',
'/<svg[^>]*>[^<]*<set\b/i',
'/<svg[^>]*>[^<]*<foreignObject/i',
// JavaScript global objects and methods
'/(window|global|globalThis|eval|Function|setTimeout|setInterval)/',
// Network requests
Expand Down

0 comments on commit 45db150

Please sign in to comment.