mirror of
https://github.com/201206030/novel.git
synced 2025-04-27 07:30:50 +00:00
fix: XSS 替换
This commit is contained in:
parent
3a0a8d6b52
commit
85f6ad957b
@ -22,7 +22,7 @@ public interface AuthStrategy {
|
|||||||
* 如果后面需要扩展到对每一个URI都进行权限控制,那么此方法可以加一个参数来接收用户请求的URI
|
* 如果后面需要扩展到对每一个URI都进行权限控制,那么此方法可以加一个参数来接收用户请求的URI
|
||||||
*
|
*
|
||||||
* @param token 登录 token
|
* @param token 登录 token
|
||||||
* @throws BusinessException 认证失败则抛出义务异常
|
* @throws BusinessException 认证失败则抛出业务异常
|
||||||
*/
|
*/
|
||||||
void auth(String token) throws BusinessException;
|
void auth(String token) throws BusinessException;
|
||||||
|
|
||||||
|
@ -40,4 +40,5 @@ public class CorsConfig {
|
|||||||
configurationSource.registerCorsConfiguration("/**",config);
|
configurationSource.registerCorsConfiguration("/**",config);
|
||||||
return new CorsFilter(configurationSource);
|
return new CorsFilter(configurationSource);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -14,12 +14,15 @@ import java.util.Map;
|
|||||||
*/
|
*/
|
||||||
public class XssHttpServletRequestWrapper extends HttpServletRequestWrapper {
|
public class XssHttpServletRequestWrapper extends HttpServletRequestWrapper {
|
||||||
|
|
||||||
private final Map<String,String> replaceRule = new HashMap<>();
|
private static final Map<String,String> REPLACE_RULE = new HashMap<>();
|
||||||
|
|
||||||
|
static {
|
||||||
|
REPLACE_RULE.put("<", "<");
|
||||||
|
REPLACE_RULE.put(">", ">");
|
||||||
|
}
|
||||||
|
|
||||||
public XssHttpServletRequestWrapper(HttpServletRequest request) {
|
public XssHttpServletRequestWrapper(HttpServletRequest request) {
|
||||||
super(request);
|
super(request);
|
||||||
replaceRule.put("<", "<");
|
|
||||||
replaceRule.put(">", ">");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -29,9 +32,9 @@ public class XssHttpServletRequestWrapper extends HttpServletRequestWrapper {
|
|||||||
int length = values.length;
|
int length = values.length;
|
||||||
String[] escapeValues = new String[length];
|
String[] escapeValues = new String[length];
|
||||||
for (int i = 0; i < length; i++) {
|
for (int i = 0; i < length; i++) {
|
||||||
String raw = values[i];
|
escapeValues[i] = values[i];
|
||||||
int index = i;
|
int index = i;
|
||||||
replaceRule.forEach((k, v)-> escapeValues[index] = raw.replaceAll(k, v));
|
REPLACE_RULE.forEach((k, v)-> escapeValues[index] = escapeValues[index].replaceAll(k, v));
|
||||||
}
|
}
|
||||||
return escapeValues;
|
return escapeValues;
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user