Skip to content

Commit 88b0e9d

Browse files
committed
errorFilteredFallbackClient: avoids leaking URL in fallback client
1 parent 8070936 commit 88b0e9d

File tree

1 file changed

+27
-0
lines changed

1 file changed

+27
-0
lines changed

arbitrum/apibackend.go

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import (
55
"errors"
66
"fmt"
77
"math/big"
8+
"net/url"
89
"strconv"
910
"strings"
1011
"time"
@@ -51,6 +52,22 @@ type APIBackend struct {
5152
sync SyncProgressBackend
5253
}
5354

55+
type errorFilteredFallbackClient struct {
56+
impl types.FallbackClient
57+
url string
58+
}
59+
60+
func (c *errorFilteredFallbackClient) CallContext(ctx context.Context, result interface{}, method string, args ...interface{}) error {
61+
err := c.impl.CallContext(ctx, result, method, args...)
62+
if err != nil && strings.Contains(err.Error(), c.url) {
63+
// avoids leaking the URL in the error message.
64+
// URL can contain sensitive information such as API keys.
65+
log.Warn("fallback client error", "error", err)
66+
return errors.New("Failed to call fallback API")
67+
}
68+
return err
69+
}
70+
5471
type timeoutFallbackClient struct {
5572
impl types.FallbackClient
5673
timeout time.Duration
@@ -77,12 +94,22 @@ func CreateFallbackClient(fallbackClientUrl string, fallbackClientTimeout time.D
7794
types.SetFallbackError(strings.Join(fields, ":"), int(errNumber))
7895
return nil, nil
7996
}
97+
8098
var fallbackClient types.FallbackClient
8199
var err error
82100
fallbackClient, err = rpc.Dial(fallbackClientUrl)
83101
if err != nil {
84102
return nil, fmt.Errorf("failed creating fallback connection: %w", err)
85103
}
104+
url, err := url.Parse(fallbackClientUrl)
105+
if err != nil {
106+
return nil, fmt.Errorf("failed parsing fallback URL: %w", err)
107+
}
108+
fallbackClient = &errorFilteredFallbackClient{
109+
impl: fallbackClient,
110+
url: url.String(),
111+
}
112+
86113
if fallbackClientTimeout != 0 {
87114
fallbackClient = &timeoutFallbackClient{
88115
impl: fallbackClient,

0 commit comments

Comments
 (0)