java - 经常误用:Java 和 JSP 文件中的文件上传
问题描述
我在下面的几行中得到“经常被误用:文件上传”。任何人都可以建议修复。
JAVA 文件:
**public void setAttachedFile(FormFile formFile) { // File upload error at this line** attachedFile = formFile; if (attachedFile != null) { formData.put("attachedFile", attachedFile); } else { formData.remove("attachedFile"); } }
JSP 文件:
<table width="100%" border="0" cellspacing="0" cellpadding="3"> <tr> <td class="label" width="1%"> </td> <td class="label" width="22%">Select File Name</td> <td class="field" width="26%"> **<input class="textfield width450" type="file" name="File_Name" maxlength="255" value=""> // Getting the fortify here** </td> </tr> </table>
谁能建议修复/解决方案
解决方案
您的后端代码是否验证文件的扩展名?
如果您的后端代码必须检查并验证文件的扩展名,那么您可以毫无问题地进行扫描。
C# 中的示例如下:
string extension = Path.GetExtension(file.FileName);
if (extension.ToLower().Trim() != ".xlsx" && extension.ToLower().Trim() != ".xls")
{
throw new Exception("Check the extension!");
}
和 JSP 文件:
<input class="textfield width450"
type="file" name="File_Name"
maxlength="255" value=""
accept=".xlsx,.xls">
推荐阅读
- magento - 当 AWS Elasticache 实例用作 FPC 与 FishPig Bold 和 Cachewarmer 对时,超过 50 GB 的峰值是什么原因?
- ansible - 使用 Ansible 根据环境停止 Tomcat 服务
- php - elasticserach中如何处理版本冲突引擎异常
- spring-boot - JWT 拦截器 Springboot
- maven - 每次我运行 gitlab CI/CD 管道时,它都会抛出错误:
- python - 在动态变化的 html 中抓取隐藏元素
- html - django 的本地化酒吧
- java - 如何在 Spring Boot 分段上传中修复“所需的请求部分不存在”
- java - 为什么扫描仪读取没有输入并退出功能?
- nlp - “微调 BERT 模型”指的是什么?