Explorar el Código

定时任务屏蔽http(s)远程调用

RuoYi hace 4 años
padre
commit
8057dcc4fc

+ 5 - 0
ruoyi-common/ruoyi-common-core/src/main/java/com/ruoyi/common/core/constant/Constants.java

@@ -18,6 +18,11 @@ public class Constants
18 18
     public static final String GBK = "GBK";
19 19
 
20 20
     /**
21
+     * RMI 远程方法调用
22
+     */
23
+    public static final String LOOKUP_RMI = "rmi://";
24
+
25
+    /**
21 26
      * http请求
22 27
      */
23 28
     public static final String HTTP = "http://";

+ 28 - 10
ruoyi-modules/ruoyi-job/src/main/java/com/ruoyi/job/controller/SysJobController.java

@@ -13,8 +13,10 @@ import org.springframework.web.bind.annotation.PutMapping;
13 13
 import org.springframework.web.bind.annotation.RequestBody;
14 14
 import org.springframework.web.bind.annotation.RequestMapping;
15 15
 import org.springframework.web.bind.annotation.RestController;
16
+import com.ruoyi.common.core.constant.Constants;
16 17
 import com.ruoyi.common.core.exception.job.TaskException;
17 18
 import com.ruoyi.common.core.utils.SecurityUtils;
19
+import com.ruoyi.common.core.utils.StringUtils;
18 20
 import com.ruoyi.common.core.utils.poi.ExcelUtil;
19 21
 import com.ruoyi.common.core.web.controller.BaseController;
20 22
 import com.ruoyi.common.core.web.domain.AjaxResult;
@@ -79,14 +81,22 @@ public class SysJobController extends BaseController
79 81
     @PreAuthorize(hasPermi = "monitor:job:add")
80 82
     @Log(title = "定时任务", businessType = BusinessType.INSERT)
81 83
     @PostMapping
82
-    public AjaxResult add(@RequestBody SysJob sysJob) throws SchedulerException, TaskException
84
+    public AjaxResult add(@RequestBody SysJob job) throws SchedulerException, TaskException
83 85
     {
84
-        if (!CronUtils.isValid(sysJob.getCronExpression()))
86
+        if (!CronUtils.isValid(job.getCronExpression()))
85 87
         {
86
-            return AjaxResult.error("cron表达式不正确");
88
+            return error("新增任务'" + job.getJobName() + "'失败,Cron表达式不正确");
87 89
         }
88
-        sysJob.setCreateBy(SecurityUtils.getUsername());
89
-        return toAjax(jobService.insertJob(sysJob));
90
+        else if (StringUtils.containsIgnoreCase(job.getInvokeTarget(), Constants.LOOKUP_RMI))
91
+        {
92
+            return error("新增任务'" + job.getJobName() + "'失败,目标字符串不允许'rmi://'调用");
93
+        }
94
+        else if (StringUtils.containsAnyIgnoreCase(job.getInvokeTarget(), new String[] { Constants.HTTP, Constants.HTTPS }))
95
+        {
96
+            return error("新增任务'" + job.getJobName() + "'失败,目标字符串不允许'http(s)//'调用");
97
+        }
98
+        job.setCreateBy(SecurityUtils.getUsername());
99
+        return toAjax(jobService.insertJob(job));
90 100
     }
91 101
 
92 102
     /**
@@ -95,14 +105,22 @@ public class SysJobController extends BaseController
95 105
     @PreAuthorize(hasPermi = "monitor:job:edit")
96 106
     @Log(title = "定时任务", businessType = BusinessType.UPDATE)
97 107
     @PutMapping
98
-    public AjaxResult edit(@RequestBody SysJob sysJob) throws SchedulerException, TaskException
108
+    public AjaxResult edit(@RequestBody SysJob job) throws SchedulerException, TaskException
99 109
     {
100
-        if (!CronUtils.isValid(sysJob.getCronExpression()))
110
+        if (!CronUtils.isValid(job.getCronExpression()))
111
+        {
112
+            return error("修改任务'" + job.getJobName() + "'失败,Cron表达式不正确");
113
+        }
114
+        else if (StringUtils.containsIgnoreCase(job.getInvokeTarget(), Constants.LOOKUP_RMI))
115
+        {
116
+            return error("修改任务'" + job.getJobName() + "'失败,目标字符串不允许'rmi://'调用");
117
+        }
118
+        else if (StringUtils.containsAnyIgnoreCase(job.getInvokeTarget(), new String[] { Constants.HTTP, Constants.HTTPS }))
101 119
         {
102
-            return AjaxResult.error("cron表达式不正确");
120
+            return error("修改任务'" + job.getJobName() + "'失败,目标字符串不允许'http(s)//'调用");
103 121
         }
104
-        sysJob.setUpdateBy(SecurityUtils.getUsername());
105
-        return toAjax(jobService.updateJob(sysJob));
122
+        job.setUpdateBy(SecurityUtils.getUsername());
123
+        return toAjax(jobService.updateJob(job));
106 124
     }
107 125
 
108 126
     /**