[ 
https://issues.apache.org/jira/browse/FILEUPLOAD-212?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel
 ]

Thomas Neidhart updated FILEUPLOAD-212:
---------------------------------------

    Attachment: FILEUPLOAD-212_test.patch

I worked on unit tests (see the attached patch) for the maxSize check and 
detected in the process that a SizeException could be the cause of these 
"Stream ended unexpectedly" problems some people have received.

This is due to the fact that in some internal methods of MultipartStream any 
IOException is caught and re-thrown as MalformedStreamException. Any of the 
SizeExceptions is thrown inside a FileUploadIOException (derived from 
IOException), to conform to the InputStream interface, which is good, but we 
need to handle them separately and propagate the correct exception to the user.

The patch also includes this change, please review.

The maxSize test also changes the MockHttpServletRequest to allow a readLimit: 
read at maximum the given amount of bytes at a time, to better test the 
streaming API. Otherwise the full buffer would be filled in one go.
                
> Insecure request size checking
> ------------------------------
>
>                 Key: FILEUPLOAD-212
>                 URL: https://issues.apache.org/jira/browse/FILEUPLOAD-212
>             Project: Commons FileUpload
>          Issue Type: Bug
>    Affects Versions: 1.2.2
>         Environment: Default configuration default environment.
>            Reporter: Damian Kolasa
>            Assignee: Thomas Neidhart
>            Priority: Critical
>              Labels: max_upload_size, resource_depletion, security
>             Fix For: 1.3
>
>         Attachments: FILEUPLOAD-212_fix.patch, FILEUPLOAD-212_test.patch
>
>   Original Estimate: 48h
>  Remaining Estimate: 48h
>
> In FileUploadBase there is an issue when checking for upload request size, 
> the check is based on presence of Content-Length header in request and FALSE 
> assumption that when present it will represent the actual request size. Using 
> this fact, attacker can supply request with defined Content-Length of 60 and 
> bypass file upload restrictions, which can lead to successful Resource 
> Depletion type attack. 
> IMHO by default file upload should return the LimitedInputStream 
> implementation for file upload.

--
This message is automatically generated by JIRA.
If you think it was sent incorrectly, please contact your JIRA administrators
For more information on JIRA, see: http://www.atlassian.com/software/jira

Reply via email to