filter_xss_bad_protocol

Хочешь помочь с переводом? Это очень просто и быстро. Лишь зарегистрируйся, и можешь тут же начать переводить.

modules/filter/filter.module, строка 1178

Версии
5 – 6
filter_xss_bad_protocol($string, $decode = TRUE)

Обрабатывает значение HTML-аттрибута и проверяет, чтобы он не содержал URL с запрещённым протоколом (например, javascript:)

Параметры

$string Стока со значение аттрибута.

$decode Нужно ли декодировать сущности в $string. Укажите FALSE, если $string является простым текстом, или TRUE в противном случае. По умолчанию TRUE.

Возвращаемое значение

Очищенная версия $string, где также экранирован HTML.

▾ 4 функции вызывают filter_xss_bad_protocol()

check_url in includes/common.inc
Подготавливает URL для использования в качестве HTML-атрибута. Убирает вредоносные протоколы.
menu_path_is_external in includes/menu.inc
Возвратить TRUE если путь является внешним (например http://example.com).
url in includes/common.inc
Генерирует URL из указанного пути меню. Также поддерживает уже существующие URL.
_filter_xss_attributes in modules/filter/filter.module
Processes a string of HTML attributes.

Код

<?php
function filter_xss_bad_protocol($string, $decode = TRUE) {
  static $allowed_protocols;
  if (!isset($allowed_protocols)) {
    $allowed_protocols = array_flip(variable_get('filter_allowed_protocols', array('http', 'https', 'ftp', 'news', 'nntp', 'telnet', 'mailto', 'irc', 'ssh', 'sftp', 'webcal', 'rtsp')));
  }

  // Get the plain text representation of the attribute value (i.e. its meaning).
  if ($decode) {
    $string = decode_entities($string);
  }

  // Iteratively remove any invalid protocol found.

  do {
    $before = $string;
    $colonpos = strpos($string, ':');
    if ($colonpos > 0) {
      // We found a colon, possibly a protocol. Verify.
      $protocol = substr($string, 0, $colonpos);
      // If a colon is preceded by a slash, question mark or hash, it cannot
      // possibly be part of the URL scheme. This must be a relative URL,
      // which inherits the (safe) protocol of the base document.
      if (preg_match('![/?#]!', $protocol)) {
        break;
      }
      // Per RFC2616, section 3.2.3 (URI Comparison) scheme comparison must be case-insensitive
      // Check if this is a disallowed protocol.
      if (!isset($allowed_protocols[strtolower($protocol)])) {
        $string = substr($string, $colonpos + 1);
      }
    }
  } while ($before != $string);
  return check_plain($string);
}
?>
Войдите или зарегистрируйтесь, чтобы получить возможность отправлять комментарии

Вход в систему