Skip to content

Commit

Permalink
Detect and convert non-UTF8 encoding as part of input sanitization
Browse files Browse the repository at this point in the history
  • Loading branch information
wrongecho committed Sep 21, 2024
1 parent c5e13fd commit b509090
Showing 1 changed file with 8 additions and 0 deletions.
8 changes: 8 additions & 0 deletions functions.php
Original file line number Diff line number Diff line change
Expand Up @@ -733,6 +733,14 @@ function sanitizeInput($input)
{
global $mysqli;

// Detect encoding
$encoding = mb_detect_encoding($input, ['UTF-8', 'ISO-8859-1', 'Windows-1252', 'ISO-8859-15'], true);

// If not UTF-8, convert to UTF8 (primarily Windows-1252 is problematic)
if ($encoding !== 'UTF-8') {
$input = mb_convert_encoding($input, 'UTF-8', $encoding);
}

// Remove HTML and PHP tags
$input = strip_tags((string) $input);

Expand Down

0 comments on commit b509090

Please sign in to comment.