From 736ba35acdebace0bdc6395e9147c42e3bdebbf1 Mon Sep 17 00:00:00 2001 From: Clemens Classen Date: Fri, 24 Mar 2023 11:40:43 +0100 Subject: [PATCH] Prevent splitting of cookie header values when using AWS Lambda --- .../quarkus/amazon/lambda/runtime/MockHttpEventServer.java | 5 +++++ .../io/quarkus/amazon/lambda/http/LambdaHttpHandler.java | 5 +++++ 2 files changed, 10 insertions(+) diff --git a/extensions/amazon-lambda-http/http-event-server/src/main/java/io/quarkus/amazon/lambda/runtime/MockHttpEventServer.java b/extensions/amazon-lambda-http/http-event-server/src/main/java/io/quarkus/amazon/lambda/runtime/MockHttpEventServer.java index e7b438422ea0c..69fe6e67955fe 100644 --- a/extensions/amazon-lambda-http/http-event-server/src/main/java/io/quarkus/amazon/lambda/runtime/MockHttpEventServer.java +++ b/extensions/amazon-lambda-http/http-event-server/src/main/java/io/quarkus/amazon/lambda/runtime/MockHttpEventServer.java @@ -128,6 +128,11 @@ public void processResponse(RoutingContext ctx, RoutingContext pending, Buffer b } } } + if (res.getCookies() != null) { + for (String cookie : res.getCookies()) { + response.headers().add("set-cookie", cookie); + } + } response.setStatusCode(res.getStatusCode()); String body = res.getBody(); if (body != null) { diff --git a/extensions/amazon-lambda-http/runtime/src/main/java/io/quarkus/amazon/lambda/http/LambdaHttpHandler.java b/extensions/amazon-lambda-http/runtime/src/main/java/io/quarkus/amazon/lambda/http/LambdaHttpHandler.java index c7c9b7f10920b..8b5c2654937cd 100644 --- a/extensions/amazon-lambda-http/runtime/src/main/java/io/quarkus/amazon/lambda/http/LambdaHttpHandler.java +++ b/extensions/amazon-lambda-http/runtime/src/main/java/io/quarkus/amazon/lambda/http/LambdaHttpHandler.java @@ -108,6 +108,11 @@ public void handleMessage(Object msg) { if (allForName == null || allForName.isEmpty()) { continue; } + // Handle cookies separately to preserve commas in the header values + if ("set-cookie".equals(name)) { + responseBuilder.setCookies(allForName); + continue; + } final StringBuilder sb = new StringBuilder(); for (Iterator valueIterator = allForName.iterator(); valueIterator.hasNext();) { sb.append(valueIterator.next());