Skip to content

Commit 33d10f8

Browse files
authored
Don't allow overriding token ID with the same token ID (#2917)
Fixes #2916
1 parent a00c9e5 commit 33d10f8

File tree

2 files changed

+9
-0
lines changed

2 files changed

+9
-0
lines changed

vault/token_store.go

+6
Original file line numberDiff line numberDiff line change
@@ -682,6 +682,12 @@ func (ts *TokenStore) create(entry *TokenEntry) error {
682682
entry.ID = entryUUID
683683
}
684684

685+
saltedId := ts.SaltID(entry.ID)
686+
exist, _ := ts.lookupSalted(saltedId, true)
687+
if exist != nil {
688+
return fmt.Errorf("cannot create a token with a duplicate ID")
689+
}
690+
685691
entry.Policies = policyutil.SanitizePolicies(entry.Policies, policyutil.DoNotAddDefaultPolicy)
686692

687693
err := ts.createAccessor(entry)

vault/token_store_test.go

+3
Original file line numberDiff line numberDiff line change
@@ -465,6 +465,9 @@ func TestTokenStore_CreateLookup_ProvidedID(t *testing.T) {
465465
if ent.ID != "foobarbaz" {
466466
t.Fatalf("bad: ent.ID: expected:\"foobarbaz\"\n actual:%s", ent.ID)
467467
}
468+
if err := ts.create(ent); err == nil {
469+
t.Fatal("expected error creating token with the same ID")
470+
}
468471

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

0 commit comments

Comments
 (0)