Skip to content

Commit

Permalink
Do not escape values added to secrets (#658)
Browse files Browse the repository at this point in the history
Fixes #657
  • Loading branch information
dominikschulz authored Feb 18, 2018
1 parent 3da3d6d commit 927a95e
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 9 deletions.
14 changes: 5 additions & 9 deletions action/create.go
Original file line number Diff line number Diff line change
Expand Up @@ -141,10 +141,6 @@ func (s *Action) createWebsite(ctx context.Context, c *cli.Context) error {
if err != nil {
return err
}
username = fsutil.CleanFilename(username)
if username == "" {
return exitError(ctx, ExitUnknown, nil, "Username must not be empty")
}

genPw, err = termio.AskForBool(ctx, "Do you want to generate a new password?", true)
if err != nil {
Expand Down Expand Up @@ -172,7 +168,7 @@ func (s *Action) createWebsite(ctx context.Context, c *cli.Context) error {
store += "/"
}

name := fmt.Sprintf("%swebsites/%s/%s", store, hostname, username)
name := fmt.Sprintf("%swebsites/%s/%s", store, fsutil.CleanFilename(hostname), fsutil.CleanFilename(username))
if s.Store.Exists(ctx, name) {
name, err = termio.AskForString(ctx, "Secret already exists, please choose another path", name)
if err != nil {
Expand Down Expand Up @@ -262,7 +258,7 @@ func (s *Action) createPIN(ctx context.Context, c *cli.Context) error {
if store != "" {
store += "/"
}
name := fmt.Sprintf("%spins/%s/%s", store, authority, application)
name := fmt.Sprintf("%spins/%s/%s", store, fsutil.CleanFilename(authority), fsutil.CleanFilename(application))
if s.Store.Exists(ctx, name) {
name, err = termio.AskForString(ctx, "Secret already exists, please choose another path", name)
if err != nil {
Expand Down Expand Up @@ -321,7 +317,7 @@ func (s *Action) createAWS(ctx context.Context, c *cli.Context) error {
if store != "" {
store += "/"
}
name := fmt.Sprintf("%saws/iam/%s/%s", store, account, username)
name := fmt.Sprintf("%saws/iam/%s/%s", store, fsutil.CleanFilename(account), fsutil.CleanFilename(username))
if s.Store.Exists(ctx, name) {
name, err = termio.AskForString(ctx, "Secret already exists, please choose another path", name)
if err != nil {
Expand Down Expand Up @@ -386,7 +382,7 @@ func (s *Action) createGCP(ctx context.Context, c *cli.Context) error {
if store != "" {
store += "/"
}
name := fmt.Sprintf("%sgcp/iam/%s/%s", store, project, username)
name := fmt.Sprintf("%sgcp/iam/%s/%s", store, fsutil.CleanFilename(project), fsutil.CleanFilename(username))
if s.Store.Exists(ctx, name) {
name, err = termio.AskForString(ctx, "Secret already exists, please choose another path", name)
if err != nil {
Expand Down Expand Up @@ -456,7 +452,7 @@ func (s *Action) createGeneric(ctx context.Context, c *cli.Context) error {
if store != "" {
store += "/"
}
name := fmt.Sprintf("%smisc/%s", store, shortname)
name := fmt.Sprintf("%smisc/%s", store, fsutil.CleanFilename(shortname))
if s.Store.Exists(ctx, name) {
name, err = termio.AskForString(ctx, "Secret already exists, please choose another path", name)
if err != nil {
Expand Down
4 changes: 4 additions & 0 deletions store/sub/write.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,10 @@ import (
// method can be passed a callback to confirm the recipients immediately
// before encryption.
func (s *Store) Set(ctx context.Context, name string, sec *secret.Secret) error {
if strings.Contains(name, "//") {
return errors.Errorf("invalid secret name: %s", name)
}

p := s.passfile(name)

if !strings.HasPrefix(p, s.path) {
Expand Down

0 comments on commit 927a95e

Please sign in to comment.