From 68ded87434bcead37c60bb097ba4492dd2ec050e Mon Sep 17 00:00:00 2001 From: "brian.mulier" Date: Thu, 7 Mar 2024 10:34:51 +0100 Subject: [PATCH] fix(webserver): multi-cookies in a single header decoder part of #3228 --- .../cookies/ServerMultipleCookiesDecoder.java | 44 +++++++++++++++++++ ....micronaut.http.cookie.ServerCookieDecoder | 1 + 2 files changed, 45 insertions(+) create mode 100644 webserver/src/main/java/io/kestra/webserver/cookies/ServerMultipleCookiesDecoder.java create mode 100644 webserver/src/main/resources/META-INF/services/io.micronaut.http.cookie.ServerCookieDecoder diff --git a/webserver/src/main/java/io/kestra/webserver/cookies/ServerMultipleCookiesDecoder.java b/webserver/src/main/java/io/kestra/webserver/cookies/ServerMultipleCookiesDecoder.java new file mode 100644 index 0000000000..e9e4afd907 --- /dev/null +++ b/webserver/src/main/java/io/kestra/webserver/cookies/ServerMultipleCookiesDecoder.java @@ -0,0 +1,44 @@ +/* + * Copyright 2017-2024 original authors + * + * Licensed 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 + * + * https://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 io.kestra.webserver.cookies; + +import io.micronaut.core.annotation.Internal; +import io.micronaut.core.annotation.NonNull; +import io.micronaut.http.cookie.Cookie; +import io.micronaut.http.cookie.DefaultServerCookieDecoder; +import io.micronaut.http.cookie.ServerCookieDecoder; + +import java.util.List; + +/** + * Workaround for multi-cookies header parsing issue + */ +@Internal +public final class ServerMultipleCookiesDecoder implements ServerCookieDecoder { + + public static final DefaultServerCookieDecoder DEFAULT_SERVER_COOKIE_DECODER = new DefaultServerCookieDecoder(); + + @Override + @NonNull + public List decode(@NonNull String header) { + String cookie2Header = header; + if (!header.toLowerCase().startsWith("set-cookie2:")) { + cookie2Header = "Set-Cookie2:" + header.replace(";", ","); + } + + return DEFAULT_SERVER_COOKIE_DECODER.decode(cookie2Header); + } +} diff --git a/webserver/src/main/resources/META-INF/services/io.micronaut.http.cookie.ServerCookieDecoder b/webserver/src/main/resources/META-INF/services/io.micronaut.http.cookie.ServerCookieDecoder new file mode 100644 index 0000000000..3a6d652ff3 --- /dev/null +++ b/webserver/src/main/resources/META-INF/services/io.micronaut.http.cookie.ServerCookieDecoder @@ -0,0 +1 @@ +io.kestra.webserver.cookies.ServerMultipleCookiesDecoder \ No newline at end of file