Skip to content

Commit afae65c

Browse files
committed
feat(connector)_: do not allow override clientId for http connection
1 parent 41f230e commit afae65c

File tree

4 files changed

+19
-11
lines changed

4 files changed

+19
-11
lines changed

services/connector/api.go

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,8 @@ import (
1010
)
1111

1212
var (
13-
ErrInvalidResponseFromForwardedRpc = errors.New("invalid response from forwarded RPC")
13+
ErrInvalidResponseFromForwardedRpc = errors.New("invalid response from forwarded RPC")
14+
ErrCannotOverrideClientIDForHttpConnection = errors.New("cannot override clientId for HTTP connection")
1415
)
1516

1617
type API struct {
@@ -96,6 +97,11 @@ func (api *API) CallRPC(ctx context.Context, inputJSON string) (interface{}, err
9697
return "", err
9798
}
9899

100+
// This prevents external clients from spoofing ClientID to impersonate trusted clients
101+
if IsUntrustedConnection(ctx) && request.ClientID != "" {
102+
return "", ErrCannotOverrideClientIDForHttpConnection
103+
}
104+
99105
if command, exists := api.r.GetCommand(request.Method); exists {
100106
return command.Execute(ctx, request)
101107
}

services/connector/api_test.go

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,9 +37,20 @@ func TestCallRPC(t *testing.T) {
3737
request: "{\"method\": \"wallet_switchEthereumChain\", \"params\": []}",
3838
expectError: commands.ErrRequestMissingDAppData,
3939
},
40+
{
41+
request: `{
42+
"method": "eth_chainId",
43+
"params": [],
44+
"url": "https://example.com",
45+
"name": "Example DApp",
46+
"iconUrl": "https://example.com/icon.png",
47+
"clientId": "wallet-connect"
48+
}`,
49+
expectError: ErrCannotOverrideClientIDForHttpConnection,
50+
},
4051
}
4152

42-
ctx := context.Background()
53+
ctx := WithConnectionType(context.Background(), ConnectionTypeHTTP)
4354
for _, tt := range tests {
4455
t.Run(tt.request, func(t *testing.T) {
4556
_, err := state.api.CallRPC(ctx, tt.request)

services/connector/commands/client_handler.go

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -126,11 +126,6 @@ func (c *ClientSideHandler) RecallDAppPermissions(args RecallDAppPermissionsArgs
126126
return ErrEmptyUrl
127127
}
128128

129-
// For backward compatibility with old clients(browser extension) that don't provide clientId
130-
if args.ClientID == "" {
131-
args.ClientID = DefaultClientID
132-
}
133-
134129
dApp, err := persistence.SelectDApp(c.Db, args.URL, args.ClientID)
135130
if err != nil {
136131
return err

services/connector/commands/rpc_traits.go

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -113,9 +113,5 @@ func (r *RPCRequest) Validate() error {
113113
return ErrRequestMissingDAppData
114114
}
115115

116-
// Browser extension doesn't send ClientID
117-
if r.ClientID == "" {
118-
r.ClientID = DefaultClientID
119-
}
120116
return nil
121117
}

0 commit comments

Comments
 (0)