Skip to content

Commit cb9344b

Browse files
authored
Update OpenApiMiddleware.java
This line: final NormalisedPath openApiPathString = maybeApiPath.get(); Would introduce NoSuchElementException and will be caught as "UnhandledException" by the end, which would respond with 500 Internal Server Error. The fix is to check if the path is present on the spec, and if not, return a 401 status invalid request path.
1 parent 7d54715 commit cb9344b

File tree

1 file changed

+4
-0
lines changed

1 file changed

+4
-0
lines changed

src/main/java/com/networknt/aws/lambda/handler/middleware/specification/OpenApiMiddleware.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ public class OpenApiMiddleware implements MiddlewareHandler {
2525
public static final String OPENAPI_CONFIG_NAME = "openapi-validator";
2626
private static final Logger LOG = LoggerFactory.getLogger(OpenApiMiddleware.class);
2727
private static final String STATUS_METHOD_NOT_ALLOWED = "ERR10008";
28+
private static final String STATUS_INVALID_REQUEST_PATH = "ERR10007";
2829
private static final String CONFIG_NAME = "openapi";
2930
static ValidatorConfig CONFIG = ValidatorConfig.load();
3031
private static final String SPEC_INJECT = "openapi-inject";
@@ -58,6 +59,9 @@ public Status execute(LightLambdaExchange exchange) {
5859
}
5960
final Optional<NormalisedPath> maybeApiPath = helper.findMatchingApiPath(requestPath);
6061

62+
if (maybeApiPath.isEmpty()) {
63+
return new Status(STATUS_INVALID_REQUEST_PATH, requestPath.normalised());
64+
}
6165
final NormalisedPath openApiPathString = maybeApiPath.get();
6266
final Path path = helper.openApi3.getPath(openApiPathString.original());
6367

0 commit comments

Comments
 (0)