Skip to content

Commit d95dcf9

Browse files
authored
chore: Add warning for insecure connection (#58)
1 parent c80d8d6 commit d95dcf9

File tree

2 files changed

+29
-0
lines changed

2 files changed

+29
-0
lines changed

core/client.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ package core
1717
import (
1818
"context"
1919
"fmt"
20+
"log"
2021
"net/http"
2122
"strings"
2223

@@ -150,6 +151,10 @@ func (tc *ToolboxClient) newToolboxTool(
150151
finalConfig.AuthTokenSources,
151152
)
152153

154+
if (len(remainingAuthnParams) > 0 || len(remainingAuthzTokens) > 0 || len(tc.clientHeaderSources) > 0) && !strings.HasPrefix(tc.baseURL, "https://") {
155+
log.Println("WARNING: Sending ID token over HTTP. User data may be exposed. Use HTTPS for secure communication.")
156+
}
157+
153158
// Construct the final tool object.
154159
tt := &ToolboxTool{
155160
name: name,

core/client_test.go

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,11 @@
1717
package core
1818

1919
import (
20+
"bytes"
2021
"context"
2122
"encoding/json"
2223
"errors"
24+
"log"
2325
"net/http"
2426
"net/http/httptest"
2527
"strings"
@@ -558,6 +560,28 @@ func TestLoadToolAndLoadToolset_ErrorPaths(t *testing.T) {
558560
}))
559561
defer server.Close()
560562

563+
// Buffer to capture logs
564+
var buf bytes.Buffer
565+
566+
originalOutput := log.Writer()
567+
log.SetOutput(&buf)
568+
defer log.SetOutput(originalOutput)
569+
570+
t.Run("logs warning for HTTP with headers", func(t *testing.T) {
571+
buf.Reset()
572+
573+
client, _ := NewToolboxClient(server.URL,
574+
WithHTTPClient(server.Client()),
575+
)
576+
577+
_, _ = client.LoadTool("toolA", context.Background())
578+
579+
expectedLog := "WARNING: Sending ID token over HTTP"
580+
if !strings.Contains(buf.String(), expectedLog) {
581+
t.Errorf("expected log message '%s' not found in output: '%s'", expectedLog, buf.String())
582+
}
583+
})
584+
561585
t.Run("LoadTool fails when a default option is invalid", func(t *testing.T) {
562586
// Setup client with duplicate default options
563587
client, _ := NewToolboxClient(server.URL,

0 commit comments

Comments
 (0)