Skip to content

Commit

Permalink
Don't allow overriding token ID with the same token ID (#2917)
Browse files Browse the repository at this point in the history
Fixes #2916
  • Loading branch information
jefferai committed Jun 24, 2017
1 parent a00c9e5 commit 33d10f8
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 0 deletions.
6 changes: 6 additions & 0 deletions vault/token_store.go
Original file line number Diff line number Diff line change
Expand Up @@ -682,6 +682,12 @@ func (ts *TokenStore) create(entry *TokenEntry) error {
entry.ID = entryUUID
}

saltedId := ts.SaltID(entry.ID)
exist, _ := ts.lookupSalted(saltedId, true)
if exist != nil {
return fmt.Errorf("cannot create a token with a duplicate ID")
}

entry.Policies = policyutil.SanitizePolicies(entry.Policies, policyutil.DoNotAddDefaultPolicy)

err := ts.createAccessor(entry)
Expand Down
3 changes: 3 additions & 0 deletions vault/token_store_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -465,6 +465,9 @@ func TestTokenStore_CreateLookup_ProvidedID(t *testing.T) {
if ent.ID != "foobarbaz" {
t.Fatalf("bad: ent.ID: expected:\"foobarbaz\"\n actual:%s", ent.ID)
}
if err := ts.create(ent); err == nil {
t.Fatal("expected error creating token with the same ID")
}

out, err := ts.Lookup(ent.ID)
if err != nil {
Expand Down

0 comments on commit 33d10f8

Please sign in to comment.