1 16 package org.directwebremoting; 17 18 import org.directwebremoting.util.LocalUtil; 19 20 28 public class Security 29 { 30 44 public static String escapeHtml(String original) 45 { 46 String reply = original; 47 reply = LocalUtil.replace(reply, "&", "&"); 48 reply = LocalUtil.replace(reply, "<", "<"); 49 reply = LocalUtil.replace(reply, ">", ">"); 50 reply = LocalUtil.replace(reply, "\'", "'"); 51 reply = LocalUtil.replace(reply, "\"", """); 52 return reply; 53 } 54 55 69 public static String unescapeHtml(String original) 70 { 71 String reply = original; 72 reply = LocalUtil.replace(reply, "&", "&"); 73 reply = LocalUtil.replace(reply, "<", "<"); 74 reply = LocalUtil.replace(reply, ">", ">"); 75 reply = LocalUtil.replace(reply, "'", "\'"); 76 reply = LocalUtil.replace(reply, """, "\""); 77 return reply; 78 } 79 80 93 public static String replaceXmlCharacters(String original) 94 { 95 String reply = original; 96 reply = LocalUtil.replace(reply, "&", "+"); 97 reply = LocalUtil.replace(reply, "<", "\u2039"); 98 reply = LocalUtil.replace(reply, ">", "\u203A"); 99 reply = LocalUtil.replace(reply, "\'", "\u2018"); 100 reply = LocalUtil.replace(reply, "\"", "\u201C"); 101 return reply; 102 } 103 104 110 public static boolean containsXssRiskyCharacters(String original) 111 { 112 return (original.indexOf('&') != -1 113 || original.indexOf('<') != -1 114 || original.indexOf('>') != -1 115 || original.indexOf('\'') != -1 116 || original.indexOf('\"') != -1); 117 } 118 } 119 | Popular Tags |