legacy-knowledge-base
公開されました Jul. 2, 2025

編集者が Web コンテンツ フィールドに実行可能コードを挿入するのを防ぐことはできますか?

written-by

Daniel Couso

How To articles are not official guidelines or officially supported documentation. They are community-contributed content and may not always reflect the latest updates to Liferay DXP. We welcome your feedback to improve How To articles!

While we make every effort to ensure this Knowledge Base is accurate, it may not always reflect the most recent updates or official guidelines.We appreciate your understanding and encourage you to reach out with any feedback or concerns.

legacy-article

learn-legacy-article-disclaimer-text

問題

  • Web コンテンツ テンプレートを介して Web コンテンツ用に保存されたテキスト フィールドをレンダリングすると、エディターが次のような実行可能コードを導入した場合、結果のマークアップで望ましくないコードが実行される可能性があります。
    • <img src=x onerror=alert("Hello")>

Environment

  • Liferay DXP 7.0+

解決策

  • これは、ユーティリティ クラス $htmlUtilを使用することで簡単に防ぐことができます。
  • $htmlUtil 保存されたテキストをエスケープできる $htmlUtil.escape()のようなメソッドが含まれています。

追加情報

did-this-article-resolve-your-issue

legacy-knowledge-base