File tree 2 files changed +12
-2
lines changed
src/main/java/org/joychou/controller
2 files changed +12
-2
lines changed Original file line number Diff line number Diff line change 31
31
- [ XXE] ( https://github.com/JoyChou93/java-sec-code/wiki/XXE )
32
32
- [ SQLI] ( https://github.com/JoyChou93/java-sec-code/wiki/SQL-Inject )
33
33
- [ Fastjson] ( https://github.com/JoyChou93/java-sec-code/wiki/Fastjson )
34
+ - [ CORS] ( https://github.com/JoyChou93/java-sec-code/wiki/CORS )
34
35
- [ Others] ( https://github.com/JoyChou93/java-sec-code/wiki/others )
35
36
36
37
Original file line number Diff line number Diff line change @@ -26,7 +26,7 @@ public class CORS {
26
26
*
27
27
* @param request
28
28
* @param response
29
- * @desc: 当origin为空,即直接访问的情况下,response的header中不会出现Access-Control-Allow-Origin
29
+ * @desc https://github.com/JoyChou93/java-sec-code/wiki/CORS
30
30
*/
31
31
@ RequestMapping ("/vuls1" )
32
32
@ ResponseBody
@@ -61,7 +61,16 @@ private static String vuls3(HttpServletResponse response) {
61
61
private static String seccode (HttpServletRequest request , HttpServletResponse response ) {
62
62
String origin = request .getHeader ("Origin" );
63
63
Security sec = new Security ();
64
- if (!sec .checkSafeUrl (origin , urlwhitelist )) {
64
+ Boolean origin_safe = false ;
65
+
66
+ // 如果origin为空,表示是同域过来的请求或者浏览器直接发起的请求,这种直接放过,没有安全问题。
67
+ if (origin == null ) {
68
+ origin_safe = true ;
69
+ }else if (sec .checkSafeUrl (origin , urlwhitelist )) {
70
+ origin_safe = true ;
71
+ }
72
+
73
+ if (!origin_safe ) {
65
74
return "Origin is not safe." ;
66
75
}
67
76
response .setHeader ("Access-Control-Allow-Origin" , "*" );
You can’t perform that action at this time.
0 commit comments