クロスサイト スクリプティング (XSS) から保護するために、OWASP が推奨するESAPI (Enterprise Security API)を使用しています。 esapi.jar ファイルは以前のバージョンの ColdFusion に含まれていましたが、CF10では、 encodeForJavascript()
、encodeForHTML()
、encodeForURL()
、encodeForCSS()
、およびencodeForHTMLAttribute()
.
で問題が発生しencodeForJavascript()
ています。バックスラッシュが失われています...
<cfoutput>
<cfif isDefined("url.name")>
<!--- Here is the problem, this is identical to the original ascii32to126 string except for one char is missing, the backslash between the brackets ...Z[]... --->
#url.name#
<cfabort>
</cfif>
<!---
ASCII 32 thru 126
!"#$%&'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\]^_`abcdefghijklmnopqrstuvwxyz{|}~
In the line below I double up on the double-quotes and pounds in order to get the cfset to work
--->
<cfset ascii32to126 = "!""##$%&'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\]^_`abcdefghijklmnopqrstuvwxyz{|}~">
<script>
function locateTo(value)
{
window.location='thisPage.cfm?name='+encodeURIComponent(value);
//alert('thisPage.cfm?name='+encodeURIComponent(value));
}
locateTo('#encodeForJavaScript(ascii32to126)#');
</script>
</cfoutput>
encodeForJavaScript()
JavaScript コンテキストにいるため、最初に呼び出します。
encodeURIComponent()
次に、URL が適切に構築されていることを確認するために呼び出します。
すべて正常に動作しますが、結果のページでバックスラッシュが失われました\
。ここで何が欠けていますか?
(はい、出力する場所も保護する必要があることは承知しています#url.name#
。この実験では、ソースを表示して文字列が元の文字列と一致するかどうかを確認する必要があったため、保護しませんでした。)
**更新** - 最新のパッチがすべて適用された ColdFusion 10 を実行しています。に問題があるようですencodeForJavaScript()
。
も失敗しJSStringFormat()
ます。これを行うと、バックスラッシュが両方にないことがわかります...
<cfset ascii32to126 = "!""##$%&'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\]^_`abcdefghijklmnopqrstuvwxyz{|}~">
<cfoutput>
#encodeForHTML(encodeForJavaScript(ascii32to126))#
<br><br>
#encodeForHTML(JSStringFormat(ascii32to126))#
</cfoutput>