Skip to content

Commit

Permalink
fix(api): don't allow short passwords in setup
Browse files Browse the repository at this point in the history
  • Loading branch information
glinton committed Sep 18, 2020
1 parent 6d7f079 commit 77c4bba
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 0 deletions.
9 changes: 9 additions & 0 deletions onboarding.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ package influxdb

import "context"

const minPasswordLength = 8

// OnboardingService represents a service for the first run.
type OnboardingService interface {
// IsOnboarding determine if onboarding request is allowed.
Expand Down Expand Up @@ -54,5 +56,12 @@ func (r *OnboardingRequest) Valid() error {
Msg: "bucket name is empty",
}
}

if len(r.Password) < minPasswordLength {
return &Error{
Code: EInvalid,
Msg: "password too short",
}
}
return nil
}
7 changes: 7 additions & 0 deletions tenant/http_client_onboarding.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,15 @@ package tenant

import (
"context"
"fmt"
"path"

"github.com/influxdata/influxdb/v2"
"github.com/influxdata/influxdb/v2/pkg/httpc"
)

const minPasswordLength = 8

// OnboardClientService connects to Influx via HTTP to perform onboarding operations
type OnboardClientService struct {
Client *httpc.Client
Expand Down Expand Up @@ -54,6 +57,10 @@ func (s *OnboardClientService) OnboardInitialUser(ctx context.Context, or *influ
}

func (s *OnboardClientService) OnboardUser(ctx context.Context, or *influxdb.OnboardingRequest) (*influxdb.OnboardingResults, error) {
if len(or.Password) < minPasswordLength {
return nil, fmt.Errorf("password must be at least %d characters long", minPasswordLength)
}

res := &onboardingResponse{}

err := s.Client.
Expand Down

0 comments on commit 77c4bba

Please sign in to comment.