Share via


schemeSettings 的 <add> 項目 (Uri 設定)

加入結構描述名稱的結構描述設定。

<add 
   name = "http|https" genericUriParserOptions="DontUnescapePathDotsAndSlashes"
/>

屬性和項目

下列章節描述屬性 、子項目和父項目

屬性

屬性

描述

name

此設定適用的結構描述名稱。 唯一支援的值是名稱="http" 和名稱="https"。

{屬性名稱} 屬性

描述

genericUriParserOptions

這個結構描述的剖析器選項。 唯一支援的值是 genericUriParserOptions = "DontUnescapePathDotsAndSlashes"。

子項目

父項目

項目

描述

<schemeSettings>

指定如何針對特定配置剖析 Uri

備註

根據預設,System.Uri 類別會在執行路徑壓縮前,取消逸出百分比編碼路徑分隔符號。 這會實作為安全機制,以防禦下列攻擊:

https://www.contoso.com/.. %2F.. %2F/Windows/System32/cmd.exe?/c+dir+c:\

如果此 URI 傳遞到未正確處理百分比編碼字元的模組,可能會導致伺服器執行下列命令:

c:\Windows\System32\cmd.exe /c dir c:\

因此,System.Uri 類別會先取消逸出路徑分隔符號,然後再套用路徑壓縮。 將惡意 URL 傳遞至 System.Uri 類別建構函式的結果,會產生下列 URI:

https://www.microsoft.com/Windows/System32/cmd.exe?/c+dir+c:\\

可以使用特定結構描述的 schemeSettings 組態選項,將這個預設行為修改為不取消逸出百分比編碼路徑分隔符號。

組態檔

這個項目可以用於應用程式組態檔或電腦組態檔 (Machine.config)。

範例

下列程式碼範例示範 Uri 類別所使用的組態,該組態支援不逸出的 HTTP 結構描述的百分比編碼路徑分隔符號。

<configuration>
  <uri>
    <schemeSettings>
      <add name="http" genericUriParserOptions="DontUnescapePathDotsAndSlashes"/>
    </schemeSettings>
  </uri>
</configuration>

請參閱

參考

網路設定結構描述

System.Configuration.SchemeSettingElement

System.Configuration.SchemeSettingElementCollection

System.Configuration.UriSection

UriSection.SchemeSettings

System.GenericUriParserOptions

System.Uri