CERT/CCによる対XSS用推奨Filterについての文章の誤読をあえてしてみる話


Attribute values

In attribute values enclosed with double quotes, the double quotes are special because they mark the end of the attribute value.

In attribute values enclosed with single quote, the single quotes are special because they mark the end of the attribute value.

Attribute values without any quotes make the white-space characters such as space and tab special.

"&" is special when used in conjunction with some attributes because it introduces a character entity.

上記のアドバイザリーをあえて誤読しちゃってみるテストです。属性の値の出力部分において double quotes や single quote で括らない時には、(XSS的にはセキュリティ対策として、括るのが鉄則ですが) space and tab special なものとみなしなさいと、誤読してみます。そして、文脈上、special なものは、filterで削除しなさいよ、というアドバイザリなんですね。

そして、filterの具体的な姿としては、上記アドバイザリにあるサーバーサイド?のJavaScript用のものとして、以下に引用するものを使います。エスケープじゃぁないことにご注意ください。あと、フィルターに追加してスペースとタブも削除しちゃってください。


JavaScript Example

function RemoveBad(InStr){
InStr = InStr.replace(/\</g,"");
InStr = InStr.replace(/\>/g,"");
InStr = InStr.replace(/\"/g,"");
InStr = InStr.replace(/\'/g,"");
InStr = InStr.replace(/\%/g,"");
InStr = InStr.replace(/\;/g,"");
InStr = InStr.replace(/\(/g,"");
InStr = InStr.replace(/\)/g,"");
InStr = InStr.replace(/\&/g,"");
InStr = InStr.replace(/\+/g,"");
return InStr;
}

さて、上のようなフィルターがあったときに、下記のような様式でサーバサイドが文字列 $useroutput を出力しているとします。


<img src=$useroutput>

このときに、XSS脆弱性をついて、
I am the Α and the Ω.
という英文をalertしてみる、ということを正月休みに試みたのでした。この文章にはギリシャ文字のアルファとオメガがあるわけです。あと、スペースとピリオドとが(謎)。で、JavaScriptでこの文章をalertしてみるという遊びを正月休みにしたのでした。ヒマ人だなぁ。なお、私にはスペースとピリオドの出力とが結構むずかったのした。なお、使ったブラウザはFirefox1.508でした。

で、実はこの課題の克服のために、先んじて、ばけらさんちの掲示板に書いたようなことをしたのでした。

教訓。アドバイザリの誤読って怖いなぁと・・・というか、属性の値は括れ!あと、改行とかもなんとかしましょう!