From 256e33ed684b910d39e5d17ee24a341475c39116 Mon Sep 17 00:00:00 2001 From: Alan Kennedy Date: Mon, 13 Jul 2026 10:59:42 +0100 Subject: [PATCH 1/2] Make google_gax compatible with tesla >= 1.18.3 Restores compatibility between google_gax and tesla >= 1.18.3 (the CVE-2026-48594 fix made :max_body_size required). Mirrors the upstream fix in googleapis/elixir-google-api#13328, which was closed unmerged because the repo is being archived. - connection.ex: DecompressResponse gets max_body_size: :infinity; multipart field names atom -> string. - mix.exs: drop the {:mime, "~> 1.0"} cap so mime resolves to 2.x under tesla 1.20. - api_test.exs: assert the accept-encoding header the middleware now adds. --- clients/gax/lib/google_api/gax/connection.ex | 6 +++--- clients/gax/mix.exs | 1 - clients/gax/test/gax/api_test.exs | 4 ++-- 3 files changed, 5 insertions(+), 6 deletions(-) diff --git a/clients/gax/lib/google_api/gax/connection.ex b/clients/gax/lib/google_api/gax/connection.ex index 1b7e95edfe..5473916785 100644 --- a/clients/gax/lib/google_api/gax/connection.ex +++ b/clients/gax/lib/google_api/gax/connection.ex @@ -33,7 +33,7 @@ defmodule GoogleApi.Gax.Connection do ) ) - plug(Tesla.Middleware.DecompressResponse, []) + plug(Tesla.Middleware.DecompressResponse, max_body_size: :infinity) plug(Tesla.Middleware.EncodeJson, engine: Poison) @@ -182,7 +182,7 @@ defmodule GoogleApi.Gax.Connection do nil -> body _ -> Tesla.Multipart.add_field( body, - :metadata, + "metadata", Poison.encode!(meta), headers: [{:"Content-Type", "application/json"}] ) @@ -193,7 +193,7 @@ defmodule GoogleApi.Gax.Connection do {res, type} = try_encode_multipart_field(data, meta) Tesla.Multipart.add_field( b, - body_name, + to_string(body_name), res, headers: [{:"Content-Type", type}] ) diff --git a/clients/gax/mix.exs b/clients/gax/mix.exs index b654b6cc49..000e7e1294 100644 --- a/clients/gax/mix.exs +++ b/clients/gax/mix.exs @@ -27,7 +27,6 @@ defmodule GoogleApi.Gax.MixProject do defp deps() do [ {:tesla, "~> 1.2"}, - {:mime, "~> 1.0"}, {:poison, ">= 3.0.0 and < 5.0.0"}, {:ex_doc, "~> 0.16", only: :dev}, {:dialyxir, "~> 0.5", only: [:dev], runtime: false} diff --git a/clients/gax/test/gax/api_test.exs b/clients/gax/test/gax/api_test.exs index fbcc574e14..34a77bfd35 100644 --- a/clients/gax/test/gax/api_test.exs +++ b/clients/gax/test/gax/api_test.exs @@ -35,7 +35,7 @@ defmodule Gax.ApiTest do mock(fn %{ method: :get, url: "https://example.com/v1/stores/store-1/pets", - headers: [{"x-goog-api-client", ^api_client}] + headers: [{"x-goog-api-client", ^api_client}, {"accept-encoding", "gzip, deflate, identity"}] } -> %Tesla.Env{status: 200, body: @pets_json} end) @@ -61,7 +61,7 @@ defmodule Gax.ApiTest do mock(fn %{ method: :get, url: "https://example.com/v1/stores/store-1/pets", - headers: [{"x-goog-api-client", ^api_client}] + headers: [{"x-goog-api-client", ^api_client}, {"accept-encoding", "gzip, deflate, identity"}] } -> %Tesla.Env{status: 200, body: @pets_json_compressed, headers: [{"content-encoding", "gzip"}]} From 7fa25ce54aded1d202852e9e1607d011d1c0e632 Mon Sep 17 00:00:00 2001 From: Alan Kennedy Date: Mon, 13 Jul 2026 11:15:04 +0100 Subject: [PATCH 2/2] test: assert multipart field names are stringified Explicitly covers the atom -> string fix in build_body/3: tesla >= 1.18.3 raises on atom multipart field names, so assert every part's :name disposition is a binary. --- clients/gax/test/gax/connection_test.exs | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/clients/gax/test/gax/connection_test.exs b/clients/gax/test/gax/connection_test.exs index 1c2fef131f..8bfe2dfdfe 100644 --- a/clients/gax/test/gax/connection_test.exs +++ b/clients/gax/test/gax/connection_test.exs @@ -143,6 +143,24 @@ defmodule Gax.ConnectionTest do end) end + # Regression test for tesla >= 1.18.3 compatibility: Tesla.Multipart.add_field/4 + # now requires binary field names and raises on atoms, so build_body/3 must + # stringify the metadata key and every body param name. + test "multipart field names are strings, not atoms" do + request = + Request.new() + |> Request.add_param(:body, :metadata, %{foo: "bar"}) + |> Request.add_param(:body, :data, %{baz: "qux"}) + |> Connection.build_request() + + body = %Tesla.Multipart{} = Keyword.get(request, :body) + names = Enum.map(body.parts, fn part -> Keyword.get(part.dispositions, :name) end) + + assert Enum.all?(names, &is_binary/1) + assert "metadata" in names + assert "data" in names + end + test "creates api client header without library version" do request = Request.new()