2016-03-25 8 views
1

私はOutputCacheを有効にしているし、次の属性を使用している:OutputCacheおよび潜在的に危険なリクエスト

[OutputCache] 
[ValidateInput(false)] 

しかし、私は次のエラーを取得しています:

[HttpRequestValidationException (0x80004005): A potentially dangerous Request.QueryString value was detected from the client (pool="lger<br />/for...").]
System.Web.HttpRequest.ValidateString(String value, String collectionKey, RequestValidationSource requestCollection) +11933898
System.Web.HttpValueCollection.EnsureKeyValidated(String key) +11932776 System.Web.HttpValueCollection.Get(String name) +23 System.Web.Caching.OutputCacheModule.CreateOutputCachedItemKey(String path, HttpVerb verb, HttpContext context, CachedVary cachedVary) +880 System.Web.Caching.OutputCacheModule.OnLeave(Object source, EventArgs eventArgs) +803
System.Web.SyncEventExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute() +142 System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously) +92

なぜこの出来事はありますか? OutputCachedItemKeyを検証する必要がある理由はありませんか?どのようにこれを無効にするには?それだけでOutputCacheを有効にするとうまくいかない

注意。すべてなし

が正常に動作します。 ASP.NET MVCテンプレートを使用して

  1. スタート新しいASP.NETプロジェクト(4.5.2)
  2. [OutputCache(Duration = 1)]
  3. 実行http://localhost:(port)/?test=%3Cscript%3E
を追加します。

更新 本当に簡単reproduciableはそう

結果: 潜在的に危険な要求、それにもかかわらず、あなたがこのパラメータでythingします。

答えて

0

クライアントは、クエリ文字列にpool="lger<br />に渡されたので、問題が発生します。 HTML文字<br />に注目してください。これはXSS攻撃とみなされ、フレームワークはこれをデフォルトで処理します。クライアントは、クエリ文字列の一部として

"<script type='javascript'>//Nasty code</script>" 

に渡す場合は、有効にこのセキュリティを維持したい

は、想像し、それが反射したり、システムのユーザーに永続化することができます。

また、MVC属性AllowHtmlを追加することができます。あなたは本当に要求の検証(Not recommended)を無効にしたい場合は

public class Model 
{ 
    [AllowHtml] 
    public string Pool { get; set; } 
} 

しかし、その後、あなたは[AllowHtml]属性を使用する必要がありますように見えますweb.config

<system.web> 
    <httpRuntime requestValidationMode="2.0" /> 
</system.web> 
+0

'AllowHtml]'は通常、コントローラではないモーダルプロパティになります。 _プロパティの要求の検証をスキップして、モデルバインド中にHTMLマークアップを含める要求を許可します._ – zgood

+0

@zgood - 良い叫びが更新されました。 –

+0

こんにちは@DarrenDavies、あなたの迅速な答えに感謝します。事は私の行動がうまくいっていることです(私は値を読んでいません)。それはそれを処理することができないように見えるOutputCacheです - StackTraceを見てください。 –

0

を経由して行うことができます。

は、参考のためにhereを参照してください。

By default, the ASP.NET MVC framework checks requests during model binding to determine whether they contain potentially dangerous content as HTML markup. If HTML is detected, model binding throws an error. If a property is marked with the AllowHtmlAttribute attribute, the ASP.NET MVC framework skips validation for that property during model binding.

+0

こんにちは@zgood、あなたの素早い答えに感謝します。事は私の行動がうまくいっていることです(私は値を読んでいません)。それは、それを扱うことができないように思われるOutputCacheです - 付属のStackTraceを参照してください。 –