Skip to content

Commit b5cafba

Browse files
committed
sasl: validate non-empty user/pass/token
This avoids sending empty credentials to the user. It is difficult to validate this up front because all mechanisms are designed for hot-reloading credentials, but we can validate at the time just before we connect and issue a request. Closes #472.
1 parent 76d2e71 commit b5cafba

File tree

4 files changed

+12
-2
lines changed

4 files changed

+12
-2
lines changed

‎pkg/sasl/oauth/oauth.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,9 @@ func (fn oauth) Authenticate(ctx context.Context, _ string) (sasl.Session, []byt
5252
if err != nil {
5353
return nil, nil, err
5454
}
55+
if auth.Token == "" {
56+
return nil, nil, errors.New("OAUTHBEARER token must be non-empty")
57+
}
5558

5659
// We sort extensions for consistency, but it is not required.
5760
type kv struct {

‎pkg/sasl/plain/plain.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ package plain
33

44
import (
55
"context"
6+
"errors"
67

78
"github.com/twmb/franz-go/pkg/sasl"
89
)
@@ -46,6 +47,9 @@ func (fn plain) Authenticate(ctx context.Context, _ string) (sasl.Session, []byt
4647
if err != nil {
4748
return nil, nil, err
4849
}
50+
if auth.User == "" || auth.Pass == "" {
51+
return nil, nil, errors.New("PLAIN user and pass must be non-empty")
52+
}
4953
return session{}, []byte(auth.Zid + "\x00" + auth.User + "\x00" + auth.Pass), nil
5054
}
5155

‎pkg/sasl/sasl.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// Package sasl specifies interfaces that any sasl authentication must provide
1+
// Package sasl specifies interfaces that any SASL authentication must provide
22
// to interop with Kafka SASL.
33
package sasl
44

@@ -32,7 +32,7 @@ type Mechanism interface {
3232
Authenticate(ctx context.Context, host string) (Session, []byte, error)
3333
}
3434

35-
// ClosingMechanism is an optional interface for sasl mechanism's. Implementing
35+
// ClosingMechanism is an optional interface for SASL mechanisms. Implementing
3636
// this interface signals that the mechanism should be closed if it will never
3737
// be used again.
3838
type ClosingMechanism interface {

‎pkg/sasl/scram/scram.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,9 @@ func (s scram) Authenticate(ctx context.Context, _ string) (sasl.Session, []byte
105105
if err != nil {
106106
return nil, nil, err
107107
}
108+
if auth.User == "" || auth.Pass == "" {
109+
return nil, nil, errors.New(s.name + " user and pass must be non-empty")
110+
}
108111
if len(auth.Nonce) == 0 {
109112
buf := make([]byte, 20)
110113
if _, err = rand.Read(buf); err != nil {

0 commit comments

Comments
 (0)