This repository has been archived by the owner on May 21, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 994
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix security issue with aud validation
Aud validation on the JWT was being bypassed if a list of claims was presented to the server. This commit checks if the aud claim is a list of strings, if not it checks if its a single string, if not it will return invalid Signed-off-by: Alistair Hey <alistair.hey@form3.tech>
- Loading branch information
Showing
4 changed files
with
90 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,5 @@ | ||
.DS_Store | ||
bin | ||
.idea/ | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
package jwt | ||
|
||
import "testing" | ||
|
||
func Test_mapClaims_list_aud(t *testing.T){ | ||
mapClaims := MapClaims{ | ||
"aud": []string{"foo"}, | ||
} | ||
want := true | ||
got := mapClaims.VerifyAudience("foo", true) | ||
|
||
if want != got { | ||
t.Fatalf("Failed to verify claims, wanted: %v got %v", want, got) | ||
} | ||
} | ||
func Test_mapClaims_string_aud(t *testing.T){ | ||
mapClaims := MapClaims{ | ||
"aud": "foo", | ||
} | ||
want := true | ||
got := mapClaims.VerifyAudience("foo", true) | ||
|
||
if want != got { | ||
t.Fatalf("Failed to verify claims, wanted: %v got %v", want, got) | ||
} | ||
} | ||
|
||
func Test_mapClaims_list_aud_no_match(t *testing.T){ | ||
mapClaims := MapClaims{ | ||
"aud": []string{"bar"}, | ||
} | ||
want := false | ||
got := mapClaims.VerifyAudience("foo", true) | ||
|
||
if want != got { | ||
t.Fatalf("Failed to verify claims, wanted: %v got %v", want, got) | ||
} | ||
} | ||
func Test_mapClaims_string_aud_fail(t *testing.T){ | ||
mapClaims := MapClaims{ | ||
"aud": "bar", | ||
} | ||
want := false | ||
got := mapClaims.VerifyAudience("foo", true) | ||
|
||
if want != got { | ||
t.Fatalf("Failed to verify claims, wanted: %v got %v", want, got) | ||
} | ||
} | ||
|
||
func Test_mapClaims_string_aud_no_claim(t *testing.T){ | ||
mapClaims := MapClaims{ | ||
} | ||
want := false | ||
got := mapClaims.VerifyAudience("foo", true) | ||
|
||
if want != got { | ||
t.Fatalf("Failed to verify claims, wanted: %v got %v", want, got) | ||
} | ||
} | ||
|
||
func Test_mapClaims_string_aud_no_claim_not_required(t *testing.T){ | ||
mapClaims := MapClaims{ | ||
} | ||
want := false | ||
got := mapClaims.VerifyAudience("foo", false) | ||
|
||
if want != got { | ||
t.Fatalf("Failed to verify claims, wanted: %v got %v", want, got) | ||
} | ||
} |