AnonSec Shell
Server IP : 85.193.89.191  /  Your IP : 3.147.69.22
Web Server : Apache
System : Linux 956367-cx40159.tmweb.ru 3.10.0-1160.105.1.el7.x86_64 #1 SMP Thu Dec 7 15:39:45 UTC 2023 x86_64
User : bitrix ( 600)
PHP Version : 8.1.27
Disable Function : NONE
MySQL : OFF  |  cURL : OFF  |  WGET : ON  |  Perl : ON  |  Python : ON  |  Sudo : ON  |  Pkexec : ON
Directory :  /home/bitrix/www/bitrix/modules/sender/lib/security/

Upload File :
current_dir [ Writeable ] document_root [ Writeable ]

 

Command :


[ HOME ]     

Current File : /home/bitrix/www/bitrix/modules/sender/lib/security/sanitizer.php
<?php
/**
 * Bitrix Framework
 * @package bitrix
 * @subpackage sender
 * @copyright 2001-2012 Bitrix
 */
namespace Bitrix\Sender\Security;

use Bitrix\Main\Loader;
use Bitrix\Fileman;

/**
 * Class Sanitizer
 * @package Bitrix\Sender\Security
 */
class Sanitizer
{
	/**
	 * Clean html.
	 *
	 * @param string $html Html text.
	 * @param string $previousHtml Previous html text.
	 * @param User $user User instance.
	 * @return string|null
	 */
	public static function sanitizeHtml($html, $previousHtml = '', User $user = null)
	{
		$html = self::cleanHtml($html);
		return self::removePhp($html, $previousHtml, $user);
	}

	/**
	 * Clean html.
	 *
	 * @param string $html Html text.
	 * @return string|null
	 */
	public static function cleanHtml($html)
	{
		if (!$html || !is_string($html))
		{
			return null;
		}

		$html = preg_replace('/<(script|iframe)(.*?)>(.*?)(<\\/\\1.*?>)/is', '', $html);
		if (Loader::includeModule('fileman'))
		{
			$html = Fileman\Block\Content\SliceConverter::sanitize($html);
		}

		return $html;
	}

	/**
	 * Fix replaced style tags and attributes.
	 *
	 * @param string $html Html text.
	 * @return string|null
	 */
	public static function fixReplacedStyles($html)
	{
		return str_replace(
			[
				'<st yle ', '<st yle	',
				' st yle="','	st yle="',
				' st yle=\'','	st yle=\'',
			],
			[
				'<style ', '<style	',
				' style="','	style="',
				' style=\'','	style=\'',
			],
			$html
		);
	}

	/**
	 * Fix template styles.
	 *
	 * @param string $html Html text.
	 * @return string|null
	 */
	public static function fixTemplateStyles($html)
	{
		$html = str_replace('<body class="">{}', '<body class="">', $html);
		$html = str_replace('</style>{}', '</style>', $html);

		if (!$html)
		{
			return $html;
		}

		$html = preg_replace('/<st yle.*?>(.*?)<\/style>/is', '</style>', $html);
		$html = preg_replace('/<\/style>([\s]*?)<\/style>/is', '</style>', $html);

		return $html;
	}

	/**
	 * Remove php from string with checking operations edit_php and lpa_template_edit
	 *
	 * @param string $string String.
	 * @param User $user User instance.
	 * @return bool
	 */
	public static function removePhp($string = '', $previousString, User $user = null)
	{
		$user = $user ?: User::current();
		Loader::includeModule('fileman');
		return Fileman\Block\EditorMail::removePhpFromHtml(
			$string,
			$previousString,
			$user->canEditPhp(),
			$user->canUseLpa()
		);
	}
}

Anon7 - 2022
AnonSec Team