メインコンテンツに移動

メインナビゲーション

  • ホーム
  • サイトマップ
  • ビデオ
  • ご連絡

パンくず

  • ホーム
  • Drupalのモジュール(Views)でフィールド出力変更可能なHTMLタグおよび制限条件

Drupalのモジュール(Views)でフィールド出力変更可能なHTMLタグおよび制限条件

drupal
module usage
Views

モジュール(Views)でフィールドの結果を書き換えテキストにいろいろなHTMLタグ/属性の使用はできません

  • 環境:Drupal7.54、Views7.x3.15
  • モジュール(Views)の各表示フィールドの結果を書き換えることができます
    • フィールド設定画面で「結果の書き換え」リンクをクリックします
    • 「フィールドの出力を変更」チェックボックスをチェックします
    • テキストアリアに出力内容を入力します
  • フィールドの出力を書き換えに「 HTMLを含めることができます 」との説明があります
    モジュール(Views)のフィールドの出力変更するテキストにHTMLタグの制限
  • 上記例ではHTMLタグ(<audio/>)を使用したが、出力が何もありませんでした(このタグの使用はできない)
  • 試してみたところ、いろいろなタグの使用はできないです(例:<div style="...">, <object>, <video>など)。

モジュール(Views)のフィールド出力変更設定テキストを XSS/HTMLとしてフィルダーされています

  • フィールド出力変更設定テキストが危険なスクリプトなどが含まらないようにXSS/HTML(filter_xss_admin)フィルダーしています
      /**
       * Render this field as altered text, from a fieldset set by the user.
       */
      function render_altered($alter, $tokens) {
        // Filter this right away as our substitutions are already sanitized.
        $value = filter_xss_admin($alter['text']);
        $value = strtr($value, $tokens);
    
        return $value;
      }
    
  • filter_xss_adminが許可したHTMLタグは以下のようで: 
    array('a', 'abbr', 'acronym', 'address', 'article', 'aside', 'b', 'bdi', 'bdo', 'big', 'blockquote', 'br', 'caption', 'cite', 'code', 'col', 'colgroup', 'command', 'dd', 'del', 'details', 'dfn', 'div', 'dl', 'dt', 'em', 'figcaption', 'figure', 'footer', 'h1', 'h2', 'h3', 'h4', 'h5', 'h6', 'header', 'hgroup', 'hr', 'i', 'img', 'ins', 'kbd', 'li', 'mark', 'menu', 'meter', 'nav', 'ol', 'output', 'p', 'pre', 'progress', 'q', 'rp', 'rt', 'ruby', 's', 'samp', 'section', 'small', 'span', 'strong', 'sub', 'summary', 'sup', 'table', 'tbody', 'td', 'tfoot', 'th', 'thead', 'time', 'tr', 'tt', 'u', 'ul', 'var', 'wbr')

制限されたタグを利用したい場合PHPフィールドで回避することができます

  • 利用モジュール:Views PHP7.x-1.0 のインストールと有効化
  • 出力を書き換えしたいフィールドを非表示にします
  • 新規フィールド(グローバル:PHP)を追加して、「Output code」のテキストエリア内で出力を書き換えたいフィールドの内容を「AVAILABLE VARIABLES」から取得して、必要なHTMLタグに書き換えることができます
  • PHPフィールドが任意のPHPスクリプトの実行ができるので、セキュリティ、パフォーマンスへの影響を慎重に見極める使用すべきです。
ホーム

古松

検索

Article Category

  • apache(7)
  • css(19)
  • drupal(295)
  • Electron(4)
  • html(34)
  • javascript(27)
  • laravel(4)
  • linux(5)
  • macOS(2)
  • mysql(13)
  • php(19)
  • python(4)
  • SEO(12)
  • video(72)
  • Visual Studio Code(4)
  • windows(13)
  • wordpress(32)