私がこれを正しく行っているかどうかはわかりません。
ページへの攻撃を防ぐために初めて何かを構築します。
私は下から始めます:
私は財産を持っています:
public string Description {get;set;}
ユーザーはtinyMCEを介して値を設定できます
tinyMCE.init({
mode: "textareas",
theme: "advanced",
encoding : "xml"...
これをデータベースに保存する前に、コントローラーで次のことを行います。
model.Description = HttpUtility.HtmlDecode(model.Description);
データベースには、次のような値があります。
<p>bla bla bla</p>
プロジェクトに AntiXSS ライブラリを追加しました。
public class AntiXssEncoder : HttpEncoder
{
public AntiXssEncoder() { }
protected override void HtmlEncode(string value, TextWriter output)
{
output.Write(Encoder.HtmlEncode(value)); // on breakpoint code always get in here
}
...
データベースからデータを表示するときは、次を使用します。
@Html.Raw(Model.Place.Description)
そして、それは正常に機能します。テキストしか表示されません。Html タグはありません。ブレークラインは正常に機能します。太字、斜体などでテキストのスタイルを設定できます。
しかし、私が入力した場合:
<script>alert(open to attack);</script>
アラートウィンドウが表示されました。
これを防ぐためにもっと何かをする必要があるのか わかりませんか?