http://www.atmarkit.co.jp/ait/articles/1312/17/news010_2.html
こちらのページ後半で
// 安全なコードの例。★★★決して最適な方法ではない(後述)★★★ function escape_html( s ){ return s.replace( /&/g, "&" ) .replace( /</g, "<" ) .replace( />/g, ">" ) .replace( /"/g, """ ) .replace( /'/g, "'" ); } var div = document.getElementById( "msg" ); // some_text は外部からコントロール可能な文字列 div.innerHTML = escape_html( some_text );
// ★★★安全な例★★★ var div = document.getElementById( "msg" ); var url = "http://example.jp/" + some_page; // some_page は外部からコントロール可能な文字列 var elm = document.createElement( "a" ); elm.setAttribute( "href", url ); elm.appendChild( document.createTextNode( url ) ); div.appendChild( elm );
とゆうものが出てきますが
これ、後半の安全な例のほうはエスケープ処理がされていないような気がするのですが、なぜ安全と言えるのでしょうか?
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
2017/04/14 17:16
2017/04/14 17:17
2017/04/14 17:37
2017/04/15 00:36