-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: added filter for post request size and disabled chunked requests
* add a simple filter which prevents BSI issue #55 (Missing request size limitation leads to memory exhaustion) * cleanup * cleanup (sorry) * feat: add a filter which filters large requests and chunked reuqests * *feat: Removed HTTP method filter from PostSizeLimitFilter. PostSizeLimitFilter was changed to RequestSizeLimitFilter. Added check to deny all chunked request independently of their HTTP method. * Manually merged request size filter with master branch * feat: Added BSI's Chunked-Encoding test to test suite Co-authored-by: Maximilian Laue <65015235+mlaue-tech@users.noreply.github.com> Co-authored-by: Felix Dittrich <31076102+f11h@users.noreply.github.com> Co-authored-by: Maximilian Laue <Maximilian.Laue@t-systems.com> Co-authored-by: Felix Dittrich <felix.dittrich@t-systems.com>
- Loading branch information
1 parent
8ad9b32
commit 9faea01
Showing
6 changed files
with
192 additions
and
43 deletions.
There are no files selected for viewing
68 changes: 68 additions & 0 deletions
68
src/main/java/app/coronawarn/verification/config/RequestSizeLimitFilter.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,68 @@ | ||
/* | ||
* Corona-Warn-App / cwa-verification | ||
* | ||
* (C) 2020, T-Systems International GmbH | ||
* | ||
* Deutsche Telekom AG, SAP AG and all other contributors / | ||
* copyright owners license this file to you under the Apache | ||
* License, Version 2.0 (the "License"); you may not use this | ||
* file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, | ||
* software distributed under the License is distributed on an | ||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
* KIND, either express or implied. See the License for the | ||
* specific language governing permissions and limitations | ||
* under the License. | ||
*/ | ||
|
||
package app.coronawarn.verification.config; | ||
|
||
import java.io.IOException; | ||
import javax.servlet.FilterChain; | ||
import javax.servlet.ServletException; | ||
import javax.servlet.http.HttpServletRequest; | ||
import javax.servlet.http.HttpServletResponse; | ||
import liquibase.util.StringUtils; | ||
import lombok.NonNull; | ||
import lombok.RequiredArgsConstructor; | ||
import lombok.extern.slf4j.Slf4j; | ||
import org.apache.http.HttpHeaders; | ||
import org.springframework.http.HttpStatus; | ||
import org.springframework.stereotype.Component; | ||
import org.springframework.web.filter.OncePerRequestFilter; | ||
|
||
/** | ||
* A filter to avoid requests with a large content and chunked requests. | ||
*/ | ||
@Component | ||
@Slf4j | ||
@RequiredArgsConstructor | ||
public class RequestSizeLimitFilter extends OncePerRequestFilter { | ||
|
||
@NonNull | ||
private final VerificationApplicationConfig verificationApplicationConfig; | ||
|
||
@Override | ||
protected void doFilterInternal(HttpServletRequest request, | ||
HttpServletResponse response, FilterChain filterChain) | ||
throws ServletException, IOException { | ||
long maxPostSize = verificationApplicationConfig.getRequest().getSizelimit(); | ||
if (request.getContentLengthLong() > maxPostSize || isChunkedRequest(request)) { | ||
log.warn("The request size is too large or the request was sent via chunks."); | ||
response.setStatus(HttpStatus.NOT_ACCEPTABLE.value()); | ||
return; | ||
} | ||
filterChain.doFilter(request, response); | ||
} | ||
|
||
private boolean isChunkedRequest(HttpServletRequest request) { | ||
String header = request.getHeader(HttpHeaders.TRANSFER_ENCODING); | ||
|
||
return !StringUtils.isEmpty(header) && header.equalsIgnoreCase("chunked"); | ||
} | ||
|
||
} |
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
Oops, something went wrong.