-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Move isInvalidFilenameBlocked check - Subclass Multipart Resolver so we can more easily check the file extension - fix typos and messaging
- Loading branch information
1 parent
b5ba290
commit ef580e1
Showing
5 changed files
with
67 additions
and
23 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
43 changes: 43 additions & 0 deletions
43
api/src/org/labkey/api/premium/DefaultAVMultipartResolver.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
package org.labkey.api.premium; | ||
|
||
import jakarta.servlet.ServletException; | ||
import jakarta.servlet.http.HttpServletRequest; | ||
import jakarta.servlet.http.Part; | ||
import org.jetbrains.annotations.NotNull; | ||
import org.labkey.api.util.FileUtil; | ||
import org.springframework.web.multipart.MultipartException; | ||
import org.springframework.web.multipart.MultipartHttpServletRequest; | ||
import org.springframework.web.multipart.support.StandardMultipartHttpServletRequest; | ||
import org.springframework.web.multipart.support.StandardServletMultipartResolver; | ||
|
||
import java.io.IOException; | ||
|
||
public class DefaultAVMultipartResolver extends StandardServletMultipartResolver | ||
{ | ||
@Override | ||
public @NotNull MultipartHttpServletRequest resolveMultipart(HttpServletRequest request) throws MultipartException | ||
{ | ||
try | ||
{ | ||
for (Part part : request.getParts()) | ||
{ | ||
// Filter to just file uploads | ||
if (part.getSubmittedFileName() != null) | ||
{ | ||
FileUtil.checkAllowedFileName(part.getSubmittedFileName()); | ||
validate(part); | ||
} | ||
} | ||
} | ||
catch (IOException | ServletException e) | ||
{ | ||
throw new MultipartException("Couldn't get uploaded files", e); | ||
} | ||
return new StandardMultipartHttpServletRequest(request, false); | ||
} | ||
|
||
protected void validate(Part part) | ||
{ | ||
//do nothing by default, but give subclasses a chance to override | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters