Answers for "JAVA - Potential Path Traversal (file read)"

0

JAVA - Potential Path Traversal (file read)

import org.apache.commons.io.FilenameUtils;

@GET
@Path("/images/{image}")
@Produces("images/*")
public Response getImage(@javax.ws.rs.PathParam("image") String image) {
    File file = new File("resources/images/", FilenameUtils.getName(image)); //Fix

    if (!file.exists()) {
        return Response.status(Status.NOT_FOUND).build();
    }

    return Response.ok().entity(new FileInputStream(file)).build();
}
Posted by: Guest on August-25-2021

Code answers related to "Java"

Java Answers by Framework

Browse Popular Code Answers by Language