Skip to content

Instantly share code, notes, and snippets.

@taku0
Created May 3, 2012 04:44
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save taku0/2583211 to your computer and use it in GitHub Desktop.
Save taku0/2583211 to your computer and use it in GitHub Desktop.
Re: 平成24年度春期情報セキュリティスペシャリスト試験のXSS問題 / 単引用符のエスケープだけではだめな場合
public class EscapeTest {
protected static String escape(String word) {
return word.replaceAll("'", "\\u0027"); // '等のエスケープは省略
}
public static void main(String [] args) {
String word = "\" onmouseover=\"alert(document.cookie)\" onmousedown=\"";
System.out.println("<a name=\"#\" onclick=\"alert('" + escape(word) + "')\">");
System.out.println("previous search word");
System.out.println("</a>");
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment