Skip to content

Commit 8db67c1

Browse files
authored
terraform: Patch CVE-2024-6104 for bundled hashicorp/go-retryablehttp. (#9959)
1 parent a80826b commit 8db67c1

2 files changed

Lines changed: 86 additions & 1 deletion

File tree

Lines changed: 81 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,81 @@
1+
From 00480c91b6411db4c687813853ab5dda8b12797c Mon Sep 17 00:00:00 2001
2+
From: Sumynwa <sumsharma@microsoft.com>
3+
Date: Mon, 29 Jul 2024 18:51:28 +0530
4+
Subject: [PATCH] Fix CVE-2024-6104
5+
6+
---
7+
.../hashicorp/go-retryablehttp/client.go | 28 ++++++++++++++-----
8+
1 file changed, 21 insertions(+), 7 deletions(-)
9+
10+
diff --git a/vendor/github.com/hashicorp/go-retryablehttp/client.go b/vendor/github.com/hashicorp/go-retryablehttp/client.go
11+
index 57116e9..5ad5046 100644
12+
--- a/vendor/github.com/hashicorp/go-retryablehttp/client.go
13+
+++ b/vendor/github.com/hashicorp/go-retryablehttp/client.go
14+
@@ -577,9 +577,9 @@ func (c *Client) Do(req *Request) (*http.Response, error) {
15+
if logger != nil {
16+
switch v := logger.(type) {
17+
case LeveledLogger:
18+
- v.Debug("performing request", "method", req.Method, "url", req.URL)
19+
+ v.Debug("performing request", "method", req.Method, "url", redactURL(req.URL))
20+
case Logger:
21+
- v.Printf("[DEBUG] %s %s", req.Method, req.URL)
22+
+ v.Printf("[DEBUG] %s %s", req.Method, redactURL(req.URL))
23+
}
24+
}
25+
26+
@@ -634,9 +634,9 @@ func (c *Client) Do(req *Request) (*http.Response, error) {
27+
if err != nil {
28+
switch v := logger.(type) {
29+
case LeveledLogger:
30+
- v.Error("request failed", "error", err, "method", req.Method, "url", req.URL)
31+
+ v.Error("request failed", "error", err, "method", req.Method, "url", redactURL(req.URL))
32+
case Logger:
33+
- v.Printf("[ERR] %s %s request failed: %v", req.Method, req.URL, err)
34+
+ v.Printf("[ERR] %s %s request failed: %v", req.Method, redactURL(req.URL), err)
35+
}
36+
} else {
37+
// Call this here to maintain the behavior of logging all requests,
38+
@@ -672,7 +672,7 @@ func (c *Client) Do(req *Request) (*http.Response, error) {
39+
40+
wait := c.Backoff(c.RetryWaitMin, c.RetryWaitMax, i, resp)
41+
if logger != nil {
42+
- desc := fmt.Sprintf("%s %s", req.Method, req.URL)
43+
+ desc := fmt.Sprintf("%s %s", req.Method, redactURL(req.URL))
44+
if resp != nil {
45+
desc = fmt.Sprintf("%s (status: %d)", desc, resp.StatusCode)
46+
}
47+
@@ -728,11 +728,11 @@ func (c *Client) Do(req *Request) (*http.Response, error) {
48+
// communicate why
49+
if err == nil {
50+
return nil, fmt.Errorf("%s %s giving up after %d attempt(s)",
51+
- req.Method, req.URL, attempt)
52+
+ req.Method, redactURL(req.URL), attempt)
53+
}
54+
55+
return nil, fmt.Errorf("%s %s giving up after %d attempt(s): %w",
56+
- req.Method, req.URL, attempt, err)
57+
+ req.Method, redactURL(req.URL), attempt, err)
58+
}
59+
60+
// Try to read the response body so we can reuse this connection.
61+
@@ -813,3 +813,17 @@ func (c *Client) StandardClient() *http.Client {
62+
Transport: &RoundTripper{Client: c},
63+
}
64+
}
65+
+
66+
+// Taken from url.URL#Redacted() which was introduced in go 1.15.
67+
+// We can switch to using it directly if we'll bump the minimum required go version.
68+
+func redactURL(u *url.URL) string {
69+
+ if u == nil {
70+
+ return ""
71+
+ }
72+
+
73+
+ ru := *u
74+
+ if _, has := ru.User.Password(); has {
75+
+ ru.User = url.UserPassword(ru.User.Username(), "xxxxx")
76+
+ }
77+
+ return ru.String()
78+
+}
79+
--
80+
2.25.1
81+

SPECS/terraform/terraform.spec

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
Summary: Infrastructure as code deployment management tool
22
Name: terraform
33
Version: 1.3.2
4-
Release: 15%{?dist}
4+
Release: 16%{?dist}
55
License: MPLv2.0
66
Vendor: Microsoft Corporation
77
Distribution: Mariner
@@ -29,6 +29,7 @@ Source0: https://github.com/hashicorp/terraform/archive/refs/tags/v%{vers
2929
Source1: %{name}-%{version}-vendor.tar.gz
3030
Patch0: CVE-2023-44487.patch
3131
Patch1: CVE-2024-3817.patch
32+
Patch2: CVE-2024-6104.patch
3233

3334
%global debug_package %{nil}
3435
%define our_gopath %{_topdir}/.gopath
@@ -62,6 +63,9 @@ install -p -m 755 -t %{buildroot}%{_bindir} ./terraform
6263
%{_bindir}/terraform
6364

6465
%changelog
66+
* Mon Jul 29 2024 Sumedh Sharma <sumsharma@microsoft.com> - 1.3.2-16
67+
- Patch CVE-2024-6104
68+
6569
* Thu Jun 06 2024 CBL-Mariner Servicing Account <cblmargh@microsoft.com> - 1.3.2-15
6670
- Bump release to rebuild with go 1.21.11
6771

0 commit comments

Comments
 (0)