forked from github/dataease
fix: 加强图片校验,防止恶意代码通过合成到图片上传到服务器中引起的攻击行为
This commit is contained in:
parent
64726f1388
commit
8265130531
@ -24,6 +24,8 @@ import java.nio.file.Path;
|
|||||||
import java.nio.file.Paths;
|
import java.nio.file.Paths;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
import java.util.regex.Matcher;
|
||||||
|
import java.util.regex.Pattern;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Author: wangjiahao
|
* Author: wangjiahao
|
||||||
@ -65,9 +67,12 @@ public class StaticResourceService {
|
|||||||
LogUtil.error(e.getMessage(), e);
|
LogUtil.error(e.getMessage(), e);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
if (image == null || image.getWidth() <= 0 || image.getHeight() <= 0) {
|
Pattern pattern = Pattern.compile("\\.(png|jpg|jpeg|gif)$");
|
||||||
|
Matcher matcher = pattern.matcher(file.getOriginalFilename().toLowerCase());
|
||||||
|
if (image == null || image.getWidth() <= 0 || image.getHeight() <= 0 || !matcher.find()) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -110,7 +110,7 @@
|
|||||||
<el-col style="width: 130px!important;">
|
<el-col style="width: 130px!important;">
|
||||||
<el-upload
|
<el-upload
|
||||||
action=""
|
action=""
|
||||||
accept=".jpeg,.jpg,.png,.gif,.svg"
|
accept=".jpeg,.jpg,.png,.gif"
|
||||||
class="avatar-uploader"
|
class="avatar-uploader"
|
||||||
list-type="picture-card"
|
list-type="picture-card"
|
||||||
:class="{disabled:uploadDisabled}"
|
:class="{disabled:uploadDisabled}"
|
||||||
|
@ -86,7 +86,7 @@
|
|||||||
<el-col style="width: 148px!important;height: 148px!important;overflow: hidden">
|
<el-col style="width: 148px!important;height: 148px!important;overflow: hidden">
|
||||||
<el-upload
|
<el-upload
|
||||||
action=""
|
action=""
|
||||||
accept=".jpeg,.jpg,.png,.gif,.svg"
|
accept=".jpeg,.jpg,.png,.gif"
|
||||||
class="avatar-uploader"
|
class="avatar-uploader"
|
||||||
list-type="picture-card"
|
list-type="picture-card"
|
||||||
:class="{disabled:uploadDisabled}"
|
:class="{disabled:uploadDisabled}"
|
||||||
|
Loading…
Reference in New Issue
Block a user