line / armeria

Your go-to microservice framework for any situation, from the creator of Netty et al. You can build any type of microservice leveraging your favorite technologies, including gRPC, Thrift, Kotlin, Retrofit, Reactive Streams, Spring Boot and Dropwizard.
https://armeria.dev
Apache License 2.0
4.81k stars 914 forks source link

Make annotated services reject the multipart requests that contain an uninjectable file upload #5549

Open trustin opened 6 months ago

trustin commented 6 months ago

Given the following service:

@Consumes("multipart/form-data")
public class FileUploadService {
    @Post("/upload")
    public HttpResponse upload(@Param String text, @Param File file) throws IOException {
        ...
    }
}

A client can send a multipart request that contains more than one file, even if /upload expects the request to contains one single file in the file field. Regardless of whether the received multipart request contains the file field or not, FileAggregatedMultipart.aggregateMultipart() will decode and store all file fields into the upload location (filesystem). It means, a client can incur unnecessary disk writes by sending the multipart requests like the following:

We could:

We might reject the requests with unnecessary fields only for a certain type of requests such as multipart file uploads, though, because sending an unnecessary fields are often harmless.

Alternatively, we might want to silently discard the body part of unnecessary fields, given that we limit the total content length anyway.

Bue-von-hon commented 6 months ago

If it's not urgent, I'll give it a try.

trustin commented 6 months ago

Sure. Why not? :smile: