File tree Expand file tree Collapse file tree 2 files changed +17
-3
lines changed Expand file tree Collapse file tree 2 files changed +17
-3
lines changed Original file line number Diff line number Diff line change @@ -210,7 +210,8 @@ class JWT {
210210 static JWT decode (String token) {
211211 try {
212212 final parts = token.split ('.' );
213- final header = jsonBase64.decode (base64Padded (parts[0 ]));
213+ var header =
214+ jsonBase64.decode (base64Padded (parts[0 ])) as Map <String , dynamic >;
214215
215216 final payload =
216217 (jsonBase64.decode (base64Padded (parts[1 ])) as Map <String , dynamic >);
@@ -222,8 +223,8 @@ class JWT {
222223
223224 return JWT (
224225 payload,
225- header: header is ! Map < String , dynamic > ? null : header ,
226- audience: audience ,
226+ header: header,
227+ audience: audiance ,
227228 issuer: issuer,
228229 subject: subject,
229230 jwtId: jwtId,
Original file line number Diff line number Diff line change @@ -147,5 +147,18 @@ void main() {
147147 });
148148 });
149149 });
150+
151+ group ('invalid header' , () {
152+ test ('invalid (non map) header should fail to decode' , () {
153+ final token =
154+ 'W10' + // base64 for `[]`, which can JSON decode but is not valid
155+ '.eyJmb28iOiJiYXIifQ' +
156+ '.' ; // signature is not checked here
157+
158+ final jwt = JWT .tryDecode (token);
159+
160+ expect (jwt, isNull);
161+ });
162+ });
150163 });
151164}
You can’t perform that action at this time.
0 commit comments