-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathjwt-debugger.html
More file actions
977 lines (895 loc) · 58.1 KB
/
jwt-debugger.html
File metadata and controls
977 lines (895 loc) · 58.1 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
<!DOCTYPE html>
<html lang="en" data-theme="dark">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>JWT Debugger: Decode, Verify, Sign HMAC JWTs | Secutils.dev</title>
<meta name="description" content="Free JWT debugger. Decode, verify, and sign HMAC JSON Web Tokens (HS256, HS384, HS512) directly in your browser. State stays in the URL fragment. No signup.">
<meta name="robots" content="index, follow, max-image-preview:large">
<link rel="canonical" href="https://{{TOOLS_HOST}}/jwt">
<meta name="su-tool-path" content="/jwt">
<meta name="su-tool-name" content="JWT Debugger">
<meta name="su-tool-description" content="Decode, verify, and sign HMAC JSON Web Tokens (HS256, HS384, HS512). Real-time signature validation, shareable URL state, no signup.">
<meta name="su-tool-promote" content="true">
<meta property="og:type" content="website">
<meta property="og:site_name" content="Secutils.dev">
<meta property="og:title" content="JWT Debugger: Decode, Verify, Sign HMAC JWTs">
<meta property="og:description" content="Free JWT debugger. Decode, verify, and sign HMAC JSON Web Tokens (HS256, HS384, HS512) directly in your browser. State stays in the URL fragment.">
<meta property="og:url" content="https://{{TOOLS_HOST}}/jwt">
<meta property="og:image" content="https://secutils.dev/docs/img/og/og-jwt.png">
<meta property="og:image:width" content="1200">
<meta property="og:image:height" content="630">
<meta property="og:image:alt" content="JWT Debugger on Secutils.dev: decode, verify, sign HMAC JSON Web Tokens.">
<meta property="og:locale" content="en_US">
<meta name="twitter:card" content="summary_large_image">
<meta name="twitter:title" content="JWT Debugger: Decode, Verify, Sign HMAC JWTs">
<meta name="twitter:description" content="Free JWT debugger. Decode, verify, and sign HMAC JSON Web Tokens directly in your browser. No signup.">
<meta name="twitter:image" content="https://secutils.dev/docs/img/og/og-jwt.png">
<script type="application/ld+json">{"@context":"https://schema.org","@type":"WebApplication","name":"JWT Debugger","url":"https://{{TOOLS_HOST}}/jwt","applicationCategory":"SecurityApplication","operatingSystem":"Any","browserRequirements":"Requires JavaScript","isAccessibleForFree":true,"offers":{"@type":"Offer","price":"0","priceCurrency":"USD"},"publisher":{"@type":"Organization","name":"Secutils.dev","url":"https://secutils.dev"},"sameAs":"https://github.com/secutils-dev/secutils/blob/main/dev/tools/jwt-debugger.html","description":"Free JWT debugger. Decode, verify, and sign HMAC JSON Web Tokens (HS256, HS384, HS512) directly in your browser. State stays in the URL fragment so tokens never leave your machine."}</script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/jose/4.14.4/index.umd.min.js"></script>
<link rel="preconnect" href="https://fonts.googleapis.com">
<link rel="preconnect" href="https://fonts.gstatic.com" crossorigin>
<link href="https://fonts.googleapis.com/css2?family=Inter:wght@300..700&family=Roboto+Mono:wght@400..700&display=swap" rel="stylesheet">
<!-- Privacy-friendly analytics by Plausible -->
<script defer src="https://tools.secutils.dev/js/script.js"></script>
<script>
window.plausible = window.plausible || function () { (plausible.q = plausible.q || []).push(arguments) };
plausible.init = plausible.init || function (i) { plausible.o = i || {} };
plausible.init();
</script>
<style>
:root, [data-theme="dark"] {
--bg: #141519;
--surface: #1d1e24;
--surface-hover: #2c2d33;
--border: #343741;
--text: #dfe5ef;
--text-muted: #98a2b3;
--primary: #fed047;
--primary-hover: #fdc615;
--primary-text: #642340;
--accent: #642340;
--badge-bg: #2B394F;
--badge-text: #98A8C3;
--header-color: #fb7185;
--payload-color: #c084fc;
--signature-color: #60a5fa;
--input-bg: #25262c;
--input-border: #343741;
--focus-ring: #fed047;
--success-bg: rgba(16,185,129,0.15);
--success-text: #6ee7b7;
--error-bg: rgba(239,68,68,0.15);
--error-text: #fca5a5;
--radius: 8px;
--font: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
--mono: 'Roboto Mono', 'SF Mono', 'Fira Code', Consolas, monospace;
}
[data-theme="light"] {
--bg: #f5f7fa;
--surface: #ffffff;
--surface-hover: #f1f3f5;
--border: #d3dae6;
--text: #343741;
--text-muted: #69707d;
--primary: #fed047;
--primary-hover: #fdc615;
--primary-text: #642340;
--accent: #642340;
--badge-bg: #E3E8F2;
--badge-text: #505F79;
--header-color: #e11d48;
--payload-color: #9333ea;
--signature-color: #2563eb;
--input-bg: #f5f7fa;
--input-border: #d3dae6;
--focus-ring: #642340;
--success-bg: rgba(16,185,129,0.1);
--success-text: #059669;
--error-bg: rgba(239,68,68,0.1);
--error-text: #dc2626;
}
*, *::before, *::after { box-sizing: border-box; }
body { font-family: var(--font); background: var(--bg); color: var(--text); margin: 0; min-height: 100vh; display: flex; flex-direction: column; transition: background .3s, color .3s; }
/* Header */
header { height: 48px; padding: 0 16px; background: var(--surface); border-bottom: 1px solid var(--border); position: sticky; top: 0; z-index: 100; display: flex; align-items: center; justify-content: space-between; transition: background .25s, border-color .25s; }
.header-left { display: flex; align-items: center; gap: 12px; }
.logo { display: flex; align-items: center; text-decoration: none; }
.logo-svg .logo-text-fill { fill: var(--text); }
.logo-badge { display: inline-flex; align-items: center; padding: 4px 16px; border-radius: 4px; border: none; background: var(--badge-bg); color: var(--badge-text); font-size: 12px; font-weight: 450; line-height: 16px; white-space: nowrap; }
.header-right { display: flex; align-items: center; gap: 8px; }
.skill-link { height: 36px; display: inline-flex; align-items: center; gap: 6px; padding: 0 12px; border: 1px solid var(--border); border-radius: 18px; background: var(--surface); color: var(--text-muted); font: 12px var(--font); text-decoration: none; transition: all .15s; cursor: pointer; }
.skill-link:hover { color: var(--text); border-color: var(--text-muted); background: var(--surface-hover); }
.skill-link svg { width: 14px; height: 14px; fill: none; stroke: currentColor; }
/* Theme toggle */
.theme-toggle { width: 36px; height: 36px; padding: 0; display: flex; align-items: center; justify-content: center; border-radius: 50%; border: 1px solid var(--border); background: var(--surface); color: var(--text-muted); cursor: pointer; transition: all .2s; }
.theme-toggle:hover { background: var(--surface-hover); color: var(--text); }
.theme-toggle svg { width: 16px; height: 16px; fill: currentColor; }
.theme-toggle .icon-sun { display: none; }
.theme-toggle .icon-moon { display: block; }
[data-theme="dark"] .theme-toggle .icon-sun { display: block; }
[data-theme="dark"] .theme-toggle .icon-moon { display: none; }
/* Noscript banner */
.su-noscript { max-width: 720px; margin: 24px auto; padding: 16px; border: 1px solid var(--border); border-radius: 8px; font: 14px/1.5 var(--font); background: var(--surface); color: var(--text); }
/* Main + grid */
main { flex: 1; padding: 24px 16px; display: flex; flex-direction: column; max-width: 1400px; width: 100%; margin: 0 auto; }
.grid { display: grid; grid-template-columns: 1fr 12px 1fr; gap: 0; flex: 1; min-height: 0; }
.panel { display: flex; flex-direction: column; min-height: 0; }
.panel-bar { display: flex; align-items: center; justify-content: space-between; padding: 0 0 8px; gap: 8px; height: 38px; box-sizing: content-box; flex-shrink: 0; }
.panel-actions { display: flex; align-items: center; gap: 8px; }
.panel-label { font-size: 13px; font-weight: 600; color: var(--text); }
.link-btn { border: none; background: none; font: 12px var(--font); color: var(--text-muted); cursor: pointer; padding: 2px 4px; transition: color .15s; }
.link-btn:hover { color: var(--text); }
/* Buttons */
/* `height` pins the outer size so `.btn-primary`'s `font-weight: 600` doesn't
render 1-2 px taller than the regular variant via expanded bold strut
metrics. See dev/tools/AGENTS.md -> "Buttons". */
.btn { padding: 7px 14px; height: 29px; border-radius: 8px; border: 1px solid var(--border); background: var(--surface); color: var(--text); font: 13px/1 var(--font); cursor: pointer; transition: all .15s; display: inline-flex; align-items: center; gap: 5px; white-space: nowrap; }
.btn:hover:not(:disabled) { background: var(--surface-hover); border-color: var(--text-muted); }
.btn-primary { background: var(--primary); border-color: var(--primary-text); color: var(--primary-text); font-weight: 500; }
.btn-primary:hover:not(:disabled) { background: var(--primary-hover); border-color: var(--primary-hover); }
.btn-sm { padding: 5px 10px; height: 24px; font-size: 12px; }
.icon-btn { padding: 4px; border: none; background: none; color: var(--text-muted); cursor: pointer; border-radius: 4px; transition: all .15s; display: inline-flex; align-items: center; justify-content: center; }
.icon-btn:hover { color: var(--text); background: var(--surface-hover); }
.icon-btn svg { width: 16px; height: 16px; }
/* Encoded pane */
.encoded-area { flex: 1; min-height: 400px; padding: 14px; background: var(--input-bg); border: 1px solid var(--input-border); border-radius: var(--radius); font: 0.875rem/1.6 var(--mono); color: var(--text); white-space: pre-wrap; word-break: break-all; outline: none; overflow: auto; transition: border-color .15s, background .25s, color .25s; }
.encoded-area:focus { border-color: var(--focus-ring); }
.encoded-area:empty::before { content: attr(data-placeholder); color: var(--text-muted); }
.token-part-header { color: var(--header-color); }
.token-part-payload { color: var(--payload-color); }
.token-part-signature { color: var(--signature-color); }
.token-dot { color: var(--text-muted); }
/* Transform info banner (above the encoded area when prefix is stripped) */
.transform-info { margin-bottom: 8px; padding: 8px 12px; border-radius: 8px; background: var(--badge-bg); color: var(--badge-text); font-size: 0.8rem; line-height: 1.4; }
.transform-info code { font-family: var(--mono); font-size: 0.75rem; background: var(--input-bg); padding: 1px 5px; border-radius: 3px; }
/* Algorithm select (compact, lives in the left panel-bar) */
.algo-select { background: var(--input-bg); border: 1px solid var(--input-border); border-radius: 6px; padding: 4px 10px; color: var(--text); font: 12px var(--font); cursor: pointer; transition: border-color .15s; }
.algo-select:focus { outline: none; border-color: var(--focus-ring); }
/* Decoded pane */
.decoded-stack { flex: 1; display: flex; flex-direction: column; gap: 16px; min-height: 0; overflow-y: auto; padding-right: 4px; position: relative; }
.card { background: var(--surface); border: 1px solid var(--border); border-radius: 12px; overflow: hidden; transition: background .25s, border-color .25s; display: flex; flex-direction: column; }
.card-header { padding: 10px 14px; border-bottom: 1px solid var(--border); font-weight: 600; font-size: 0.75rem; text-transform: uppercase; letter-spacing: 0.5px; }
.card-body { padding: 12px 14px; }
/* The last card (Verify Signature) absorbs any leftover vertical space so the
stack doesn't end with a gap below it on tall viewports. */
.verify-card { flex: 1; min-height: 200px; }
.verify-card .card-body { flex: 1; display: flex; flex-direction: column; gap: 12px; }
.verify-card #secret-input { flex: 1; min-height: 80px; }
.verify-card #signature-status { margin-top: 0; }
/* View tabs (segmented pill) - same as md-to-html / saml-decoder */
.view-tabs { display: inline-flex; gap: 2px; padding: 2px; background: var(--input-bg); border: 1px solid var(--border); border-radius: 6px; }
.view-tab { padding: 3px 10px; border: none; background: transparent; color: var(--text-muted); font: 12px/1 var(--font); font-weight: 500; cursor: pointer; border-radius: 4px; transition: all .15s; }
.view-tab:hover { color: var(--text); }
.view-tab.active { background: var(--surface-hover); color: var(--text); font-weight: 600; }
.tab-content { display: none; }
.tab-content.active { display: block; }
/* JSON editors inside cards */
.json-editor { width: 100%; min-height: 140px; padding: 10px 12px; border: 1px solid var(--input-border); border-radius: var(--radius); background: var(--input-bg); color: var(--text); font: 0.875rem/1.5 var(--mono); resize: vertical; outline: none; transition: border-color .15s; }
.json-editor:focus { border-color: var(--focus-ring); }
.json-editor.invalid { border-color: var(--error-text); }
/* Claims table */
.claims-table { width: 100%; border-collapse: collapse; }
.claims-table td { padding: 6px 8px; border-bottom: 1px solid var(--border); font: 0.8rem/1.4 var(--mono); vertical-align: top; }
.claims-table tr:last-child td { border-bottom: none; }
.claims-table td:first-child { color: var(--text-muted); white-space: nowrap; }
.claims-table td:last-child { color: var(--text); word-break: break-word; }
.claims-desc { font-size: 0.7rem; color: var(--text-muted); display: block; margin-top: 2px; font-family: var(--font); }
/* Verify Signature card */
#secret-input { width: 100%; min-height: 80px; padding: 10px 12px; border: 1px solid var(--input-border); border-radius: var(--radius); background: var(--input-bg); color: var(--text); font: 0.875rem/1.5 var(--mono); resize: vertical; outline: none; transition: border-color .15s; }
#secret-input:focus { border-color: var(--focus-ring); }
#signature-status { margin-top: 12px; text-align: center; font-weight: 600; padding: 8px 16px; border-radius: var(--radius); font-size: 0.875rem; min-height: 32px; }
.sig-valid { background: var(--success-bg); color: var(--success-text); }
.sig-invalid { background: var(--error-bg); color: var(--error-text); }
/* Parse error overlay (above decoded stack when JWT can't be parsed) */
.parse-error-overlay { padding: 28px 24px; border: 1px dashed var(--error-text); border-radius: 12px; background: var(--error-bg); color: var(--error-text); font-size: 0.9rem; line-height: 1.5; text-align: center; }
.parse-error-overlay::before { content: ''; display: block; width: 36px; height: 36px; margin: 0 auto 12px; border-radius: 50%; background: var(--error-bg); background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 16 16'%3E%3Cpath d='M8 1a7 7 0 1 1 0 14A7 7 0 0 1 8 1Zm0 1a6 6 0 1 0 0 12A6 6 0 0 0 8 2Zm0 3a.5.5 0 0 1 .5.5v3a.5.5 0 0 1-1 0v-3A.5.5 0 0 1 8 5Zm0 5.5a.75.75 0 1 1 0 1.5.75.75 0 0 1 0-1.5Z' fill='%23fca5a5'/%3E%3C/svg%3E"); background-repeat: no-repeat; background-position: center; background-size: 22px; }
[data-theme="light"] .parse-error-overlay::before { background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 16 16'%3E%3Cpath d='M8 1a7 7 0 1 1 0 14A7 7 0 0 1 8 1Zm0 1a6 6 0 1 0 0 12A6 6 0 0 0 8 2Zm0 3a.5.5 0 0 1 .5.5v3a.5.5 0 0 1-1 0v-3A.5.5 0 0 1 8 5Zm0 5.5a.75.75 0 1 1 0 1.5.75.75 0 0 1 0-1.5Z' fill='%23dc2626'/%3E%3C/svg%3E"); }
/* Splitter */
.splitter { cursor: col-resize; background: transparent; position: relative; z-index: 1; }
.splitter::after { content: ''; position: absolute; top: 0; bottom: 0; left: 50%; width: 1px; background: var(--border); transition: width .15s, background .15s; transform: translateX(-50%); }
.splitter:hover::after, .splitter.active::after { width: 3px; background: var(--primary); border-radius: 2px; }
.splitter-overlay { position: fixed; inset: 0; z-index: 9999; cursor: col-resize; }
/* Fullscreen the right (decoded) pane */
#decodedPane:fullscreen { background: var(--bg); padding: 16px; display: flex; flex-direction: column; overflow: hidden; }
#decodedPane:fullscreen .decoded-stack { flex: 1; min-height: 0; }
/* "More free tools" CTA */
.su-more-tools { margin: 16px 0 0; padding: 12px 18px; text-align: center; border: 1px solid rgba(254, 208, 71, 0.35); border-radius: 12px; background: rgba(254, 208, 71, 0.06); font: 13px/1.55 var(--font); color: var(--text); transition: border-color .25s, background-color .25s, color .25s; }
.su-more-tools p { margin: 0; }
.su-more-tools a { color: var(--primary); font-weight: 700; text-decoration: none; white-space: nowrap; }
.su-more-tools a:hover { color: var(--primary-hover); text-decoration: underline; }
/* Footer */
.su-footer { text-align: center; padding: 16px; border-top: 1px solid var(--border); color: var(--text-muted); font-size: 0.8rem; transition: border-color .25s, color .25s; }
.su-footer p { margin: 0; }
.su-footer-fineprint { margin-top: 6px !important; font-size: 0.7rem; opacity: 0.75; }
.su-footer-link { background: none; border: none; padding: 0; color: inherit; font: inherit; cursor: pointer; text-decoration: underline; text-underline-offset: 2px; }
.su-footer-link:hover { color: var(--text); }
.su-dialog { max-width: 520px; width: calc(100% - 32px); max-height: calc(100% - 32px); inset: 0; margin: auto; padding: 0; border: 1px solid var(--border); border-radius: 12px; background: var(--surface); color: var(--text); box-shadow: 0 20px 60px rgba(0,0,0,0.4); }
.su-dialog::backdrop { background: rgba(0,0,0,0.45); backdrop-filter: blur(2px); }
.su-dialog-header { display: flex; align-items: center; justify-content: space-between; padding: 14px 18px; border-bottom: 1px solid var(--border); }
.su-dialog-header h2 { font-size: 1rem; font-weight: 600; }
.su-dialog-close { width: 28px; height: 28px; padding: 0; display: flex; align-items: center; justify-content: center; border-radius: 50%; border: 1px solid var(--border); background: var(--surface); color: var(--text-muted); cursor: pointer; transition: all .15s; }
.su-dialog-close:hover { background: var(--surface-hover); color: var(--text); }
.su-dialog-body { padding: 16px 18px; font-size: 0.875rem; line-height: 1.55; color: var(--text); }
.su-dialog-body p { margin-bottom: 12px; }
.su-dialog-body p:last-child { margin-bottom: 0; }
.su-dialog-body code { font-family: var(--mono); background: var(--surface-hover); padding: 1px 5px; border-radius: 4px; font-size: 0.85em; }
.su-dialog-body a { color: var(--primary); text-decoration: none; }
.su-dialog-body a:hover { text-decoration: underline; }
.su-dialog-fineprint { font-size: 0.8rem; color: var(--text-muted); }
.su-credits-list { margin: 0 0 12px; padding-left: 20px; }
.su-credits-list li { margin-bottom: 6px; }
.su-credits-list li:last-child { margin-bottom: 0; }
/* Toast */
.toast { position: fixed; bottom: 20px; right: 20px; background: var(--surface); color: var(--text); padding: 10px 18px; border-radius: 8px; border: 1px solid var(--border); font-size: 13px; z-index: 200; box-shadow: 0 4px 12px rgba(0,0,0,0.3); display: flex; align-items: center; gap: 8px; animation: toastIn .2s ease; }
@keyframes toastIn { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: translateY(0); } }
/* Scrollbar */
::-webkit-scrollbar { width: 8px; height: 8px; }
::-webkit-scrollbar-track { background: var(--bg); }
::-webkit-scrollbar-thumb { background: var(--border); border-radius: 4px; }
::-webkit-scrollbar-thumb:hover { background: var(--text-muted); }
/* Responsive */
@media (max-width: 900px) {
.grid { grid-template-columns: 1fr; row-gap: 24px; }
.splitter { display: none; }
.encoded-area { min-height: 240px; }
.decoded-stack { overflow-y: visible; padding-right: 0; }
.panel-bar { flex-wrap: wrap; row-gap: 8px; height: auto; min-height: 38px; }
.panel-actions { flex-wrap: wrap; justify-content: flex-end; }
}
@media (max-width: 600px) { .su-more-tools { padding: 12px 14px; } .su-more-tools a { white-space: normal; } }
@media (max-width: 640px) {
header { padding: 0 12px; }
.logo-svg { height: 20px; }
.logo-badge { font-size: 11px; padding: 2px 7px; }
main { padding: 16px 12px; }
.btn { padding: 6px 10px; font-size: 12px; }
.skill-link span { display: none; }
.skill-link { padding: 0 10px; }
.algo-select { padding: 4px 8px; font-size: 11px; }
}
</style>
</head>
<body>
<noscript>
<p class="su-noscript"><strong>JWT Debugger</strong> — Decode, verify, and sign HMAC JSON Web Tokens (HS256, HS384, HS512) directly in your browser. Tokens stay in the URL fragment and never reach the server. This tool requires JavaScript; please enable it. Source on <a href="https://github.com/secutils-dev/secutils/blob/main/dev/tools/jwt-debugger.html">GitHub</a>.</p>
</noscript>
<header>
<div class="header-left">
<a class="logo" href="https://secutils.dev" target="_blank" rel="noopener">
<svg class="logo-svg" height="24" role="img" viewBox="0 0 98 16" xmlns="http://www.w3.org/2000/svg">
<path d="m3 0h10c1.662 0 3 1.338 3 3v10c0 1.662-1.338 3-3 3h-10c-1.662 0-3-1.338-3-3v-10c0-1.662 1.338-3 3-3z" fill="#fed047"/>
<path aria-label="SU" d="m11.285 12q-1.12 0-1.728-0.608-0.608-0.61867-0.608-1.6747v-5.6107h1.152v5.6q0 0.59733 0.29867 0.93867 0.29867 0.34133 0.88534 0.34133 0.58667 0 0.88534-0.34133 0.29867-0.34134 0.29867-0.93867v-5.6h1.152v5.6107q0 1.0667-0.608 1.6747t-1.728 0.608zm-6.368 0q-1.152 0-1.8453-0.608-0.69334-0.608-0.69334-1.664h1.1307q0 0.58667 0.384 0.928 0.384 0.33067 1.024 0.33067 0.62934 0 0.992-0.34133 0.36267-0.34134 0.36267-0.90667 0-0.42667-0.23467-0.74667t-0.672-0.43733l-1.12-0.29867q-0.78934-0.21333-1.248-0.77867-0.448-0.56534-0.448-1.3547 0-0.64 0.27733-1.1093 0.288-0.48 0.81067-0.74667t1.216-0.26667 1.216 0.26667q0.53334 0.26667 0.82134 0.74667 0.29867 0.46933 0.29867 1.0987h-1.1307q0-0.50133-0.34133-0.8-0.33067-0.30933-0.864-0.30933t-0.864 0.30933q-0.32 0.29867-0.32 0.78934 0 0.39467 0.21333 0.66134 0.224 0.26667 0.61867 0.37333l1.152 0.30933q0.81067 0.21333 1.28 0.832t0.46933 1.4613q0 0.69334-0.30933 1.2053-0.30933 0.50133-0.864 0.77867-0.55467 0.27733-1.312 0.27733z" fill="#642340"/>
<path class="logo-text-fill" aria-label="SECUTILS.DEV" d="m93.158 12.117-1.9733-7.7867h1.1733l1.2587 5.184q0.11733 0.46933 0.20267 0.91734 0.08533 0.448 0.128 0.69334 0.04267-0.24533 0.128-0.69334 0.096-0.45867 0.21333-0.928l1.2053-5.1733h1.184l-1.984 7.7867zm-7.8294 0v-7.7867h4.576v1.024h-3.4453v2.2187h3.072v0.992h-3.072v2.528h3.4453v1.024zm-6.5174 0v-7.7867h2.176q0.768 0 1.3333 0.29867 0.56534 0.288 0.87467 0.832 0.32 0.53334 0.32 1.248v3.008q0 0.736-0.32 1.2693-0.30933 0.53334-0.87467 0.832-0.56534 0.29867-1.3333 0.29867zm1.152-1.0347h1.024q0.62934 0 1.0027-0.36267 0.37333-0.36267 0.37333-1.0027v-3.008q0-0.61867-0.37333-0.98134-0.37334-0.37333-1.0027-0.37333h-1.024zm-5.2374 1.1413q-0.416 0-0.68267-0.24533-0.256-0.256-0.256-0.672 0-0.416 0.256-0.672 0.26667-0.26667 0.68267-0.26667 0.416 0 0.672 0.26667 0.26667 0.256 0.26667 0.672 0 0.416-0.26667 0.672-0.256 0.24533-0.672 0.24533zm-6.368 0q-1.152 0-1.8453-0.608-0.69334-0.608-0.69334-1.664h1.1307q0 0.58667 0.384 0.928 0.384 0.33067 1.024 0.33067 0.62934 0 0.992-0.34133 0.36267-0.34134 0.36267-0.90667 0-0.42667-0.23467-0.74667t-0.672-0.43733l-1.12-0.29867q-0.78934-0.21333-1.248-0.77867-0.448-0.56534-0.448-1.3547 0-0.64 0.27733-1.1093 0.288-0.48 0.81067-0.74667 0.52267-0.26667 1.216-0.26667 0.69334 0 1.216 0.26667 0.53334 0.26667 0.82134 0.74667 0.29867 0.46933 0.29867 1.0987h-1.1307q0-0.50134-0.34133-0.8-0.33067-0.30933-0.864-0.30933t-0.864 0.30933q-0.32 0.29867-0.32 0.78934 0 0.39467 0.21333 0.66134 0.224 0.26667 0.61867 0.37333l1.152 0.30933q0.81067 0.21333 1.28 0.832 0.46934 0.61867 0.46934 1.4613 0 0.69334-0.30934 1.2053-0.30933 0.50134-0.864 0.77867-0.55467 0.27733-1.312 0.27733zm-8.288-0.10667v-7.7867h1.152v6.7414h3.4027v1.0453zm-6.6987 0v-1.0453h1.568v-5.696h-1.568v-1.0453h4.32v1.0453h-1.5787v5.696h1.5787v1.0453zm-4.8214 0v-6.7414h-2.08v-1.0453h5.3227v1.0453h-2.0907v6.7414zm-5.824 0.10667q-1.12 0-1.728-0.608-0.608-0.61867-0.608-1.6747v-5.6107h1.152v5.6q0 0.59733 0.29867 0.93867 0.29867 0.34133 0.88534 0.34133 0.58667 0 0.88534-0.34133 0.29867-0.34134 0.29867-0.93867v-5.6h1.152v5.6107q0 1.0667-0.608 1.6747t-1.728 0.608zm-6.3147 0q-1.0987 0-1.7493-0.608-0.64-0.61867-0.64-1.664v-3.456q0-1.056 0.64-1.664 0.65067-0.608 1.7493-0.608 1.088 0 1.728 0.61867 0.65067 0.608 0.65067 1.6533h-1.152q0-0.608-0.33067-0.928-0.32-0.32-0.896-0.32-0.58667 0-0.91734 0.32-0.32 0.32-0.32 0.928v3.456q0 0.608 0.32 0.928 0.33067 0.32 0.91734 0.32 0.576 0 0.896-0.32 0.33067-0.32 0.33067-0.928h1.152q0 1.0453-0.65067 1.664-0.64 0.608-1.728 0.608zm-8.6827-0.10667v-7.7867h4.576v1.024h-3.4453v2.2187h3.072v0.992h-3.072v2.528h3.4453v1.024zm-4.1707 0.10667q-1.152 0-1.8453-0.608-0.69334-0.608-0.69334-1.664h1.1307q0 0.58667 0.384 0.928 0.384 0.33067 1.024 0.33067 0.62934 0 0.992-0.34133 0.36267-0.34134 0.36267-0.90667 0-0.42667-0.23467-0.74667-0.23467-0.32-0.672-0.43733l-1.12-0.29867q-0.78934-0.21333-1.248-0.77867-0.448-0.56534-0.448-1.3547 0-0.64 0.27733-1.1093 0.288-0.48 0.81067-0.74667 0.52267-0.26667 1.216-0.26667 0.69334 0 1.216 0.26667 0.53334 0.26667 0.82134 0.74667 0.29867 0.46933 0.29867 1.0987h-1.1307q0-0.50134-0.34134-0.8-0.33067-0.30933-0.864-0.30933t-0.864 0.30933q-0.32 0.29867-0.32 0.78934 0 0.39467 0.21333 0.66134 0.224 0.26667 0.61867 0.37333l1.152 0.30933q0.81067 0.21333 1.28 0.832 0.46934 0.61867 0.46934 1.4613 0 0.69334-0.30934 1.2053-0.30933 0.50134-0.864 0.77867-0.55467 0.27733-1.312 0.27733z"/>
</svg>
</a>
<span class="logo-badge">JWT Debugger</span>
</div>
<div class="header-right">
<a id="skillLink" class="skill-link" href="#" target="_blank" rel="noopener"
title="View AI agent skill (skill.md, opens in new tab)"
aria-label="View AI agent skill (opens in new tab)">
<svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true">
<path d="M9.937 15.5A2 2 0 0 0 8.5 14.063l-6.135-1.582a.5.5 0 0 1 0-.962L8.5 9.936A2 2 0 0 0 9.937 8.5l1.582-6.135a.5.5 0 0 1 .963 0L14.063 8.5A2 2 0 0 0 15.5 9.937l6.135 1.582a.5.5 0 0 1 0 .962L15.5 14.063a2 2 0 0 0-1.437 1.437l-1.582 6.135a.5.5 0 0 1-.963 0z"/>
<path d="M20 3v4"/><path d="M22 5h-4"/><path d="M4 17v2"/><path d="M5 18H3"/>
</svg>
<span>Skill</span>
</a>
<button class="theme-toggle" id="themeToggle" aria-label="Toggle theme">
<svg class="icon-sun" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 16 16"><path d="M8.5 15h-1v-2h1v2Zm-3.674-3.107-1.414 1.414-.707-.707 1.414-1.415.707.708Zm8.479.707-.707.707-1.414-1.414.707-.708 1.414 1.415Z"/><path fill-rule="evenodd" d="M8 4a4 4 0 1 1 0 8 4 4 0 0 1 0-8Zm0 1a3 3 0 1 0 0 6 3 3 0 0 0 0-6Z" clip-rule="evenodd"/><path d="M3.005 8.505h-2v-1h2v1Zm12 0h-2v-1h2v1ZM4.82 4.114l-.708.707-1.414-1.414.707-.707L4.82 4.114Zm8.492-.707-1.414 1.414-.708-.707L12.605 2.7l.707.707ZM8.5 3h-1V1h1v2Z"/></svg>
<svg class="icon-moon" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 16 16"><path d="M4.05 12.95A6.982 6.982 0 0 1 2 8c0-1.79.684-3.583 2.05-4.95A6.982 6.982 0 0 1 9 1a1 1 0 0 1 .708 1.707 4.982 4.982 0 0 0-1.465 3.536 4.98 4.98 0 0 0 1.465 3.535 4.98 4.98 0 0 0 3.535 1.465 1 1 0 0 1 .707 1.707A6.981 6.981 0 0 1 9 15a6.983 6.983 0 0 1-4.95-2.05Zm.708-.707A5.983 5.983 0 0 0 9 14c1.535 0 3.07-.586 4.242-1.757a5.98 5.98 0 0 1-4.018-1.545L9 10.485a5.982 5.982 0 0 1-1.758-4.242A5.986 5.986 0 0 1 9 2a5.983 5.983 0 0 0-4.243 1.757A5.98 5.98 0 0 0 3 8l.006.288a5.978 5.978 0 0 0 1.75 3.955Z"/></svg>
</button>
</div>
</header>
<main>
<div class="grid">
<!-- Encoded pane -->
<div class="panel">
<div class="panel-bar">
<span class="panel-label">Encoded</span>
<div class="panel-actions">
<select id="algorithm-select" class="algo-select" aria-label="Algorithm">
<option>HS256</option>
<option>HS384</option>
<option>HS512</option>
<option disabled>--- RS/ES/PS algorithms require key pairs ---</option>
</select>
<button class="link-btn" id="exampleBtn">Example</button>
<button class="link-btn" id="clearBtn">Clear</button>
<button id="share-button" class="btn btn-primary btn-sm" title="Copy a shareable link with the JWT and secret encoded in the URL">Share</button>
</div>
</div>
<div id="transform-info" class="transform-info" style="display:none"></div>
<div id="encoded-output" contenteditable="true" spellcheck="false" class="encoded-area" data-placeholder="Paste a JWT (header.payload.signature). Bearer prefixes and base64-wrapped tokens are unwrapped automatically." aria-label="Encoded JWT"></div>
</div>
<div class="splitter" id="splitter"></div>
<!-- Decoded pane -->
<div id="decodedPane" class="panel">
<div class="panel-bar">
<div class="view-tabs" id="view-tabs" role="tablist" aria-label="Decoded view (applies to header and payload)">
<button class="view-tab active" data-view="json" role="tab" aria-selected="true" title="Show JSON editors">JSON</button>
<button class="view-tab" data-view="table" role="tab" aria-selected="false" title="Show claim tables">Table</button>
</div>
<div class="panel-actions">
<button id="copy-button" class="btn btn-sm" title="Copy the encoded token to your clipboard">
<svg viewBox="0 0 16 16" width="14" height="14" fill="none" stroke="currentColor" stroke-width="1.6" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"><rect x="4" y="4" width="9" height="10" rx="1.5"/><path d="M3 11V3.5A1.5 1.5 0 0 1 4.5 2H10"/></svg>
<span class="btn-label">Copy</span>
</button>
<button id="fullscreenBtn" class="icon-btn" title="Toggle fullscreen" aria-label="Toggle fullscreen">
<svg id="fullscreenEnterIcon" xmlns="http://www.w3.org/2000/svg" width="16" height="16" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><path d="M8 3H5a2 2 0 0 0-2 2v3m18 0V5a2 2 0 0 0-2-2h-3m0 18h3a2 2 0 0 0 2-2v-3M3 16v3a2 2 0 0 0 2 2h3"/></svg>
<svg id="fullscreenExitIcon" xmlns="http://www.w3.org/2000/svg" width="16" height="16" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" style="display:none"><path d="M8 3v3a2 2 0 0 1-2 2H3m18 0h-3a2 2 0 0 1-2-2V3m0 18v-3a2 2 0 0 1 2-2h3M3 16h3a2 2 0 0 1 2 2v3"/></svg>
</button>
</div>
</div>
<div class="decoded-stack">
<div id="parse-error" class="parse-error-overlay" style="display:none"></div>
<!-- Header card -->
<div class="card">
<div class="card-header" style="color: var(--header-color);">Header: Algorithm & Token Type</div>
<div class="card-body" id="header-tab-content"></div>
</div>
<!-- Payload card -->
<div class="card">
<div class="card-header" style="color: var(--payload-color);">Payload: Data</div>
<div class="card-body" id="payload-tab-content"></div>
</div>
<!-- Verify Signature card (grows to fill remaining vertical space) -->
<div class="card verify-card">
<div class="card-header" style="color: var(--signature-color);">Verify Signature</div>
<div class="card-body">
<textarea id="secret-input" spellcheck="false" placeholder="Your-256-bit-secret"></textarea>
<div id="signature-status"></div>
</div>
</div>
</div>
</div>
</div>
<aside class="su-more-tools" aria-label="More free tools">
<p>Other free, no-signup Secutils.dev tools for SAML, certificates, Markdown, HTTP echo, and more - <a href="https://{{TOOLS_HOST}}/">Browse all tools →</a></p>
</aside>
</main>
<footer class="su-footer">
<p>A single-file JWT debugger for decoding, verifying, and signing JSON Web Tokens.</p>
<p class="su-footer-fineprint">
<button type="button" class="su-footer-link" id="privacyOpen">Privacy</button>
<span aria-hidden="true"> · </span>
<button type="button" class="su-footer-link" id="creditsOpen">Credits</button>
</p>
</footer>
<dialog id="privacyDialog" class="su-dialog" aria-labelledby="privacyDialogTitle">
<header class="su-dialog-header">
<h2 id="privacyDialogTitle">Privacy</h2>
<button type="button" class="su-dialog-close" id="privacyClose" aria-label="Close">
<svg viewBox="0 0 16 16" width="14" height="14" fill="none" stroke="currentColor" stroke-width="1.8" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"><path d="M3 3l10 10M13 3L3 13"/></svg>
</button>
</header>
<div class="su-dialog-body">
<p><strong>Your data stays in your browser.</strong> These tools run entirely client-side. Tokens, PEMs, SAML payloads, Markdown source, and mock-response bodies are never sent to the Secutils.dev server. State that needs to survive a reload (or be shared) lives in the URL fragment (<code>#…</code>), which browsers never transmit to the server.</p>
<p><strong>Anonymous usage analytics.</strong> We use <a href="https://plausible.io/" target="_blank" rel="noopener noreferrer">Plausible Analytics</a>, a privacy-first, GDPR-compliant tool, to collect aggregate usage data. No cookies, no personal data, no individual tracking. The data is limited to top pages, referral sources, visit duration, and device-class metadata (device type, OS, country, browser). Full details in the <a href="https://plausible.io/data-policy" target="_blank" rel="noopener noreferrer">Plausible Data Policy</a>.</p>
<p class="su-dialog-fineprint">See the full <a href="https://secutils.dev/privacy" target="_blank" rel="noopener noreferrer">Secutils.dev privacy policy</a> for details on the wider service.</p>
</div>
</dialog>
<dialog id="creditsDialog" class="su-dialog" aria-labelledby="creditsDialogTitle">
<header class="su-dialog-header">
<h2 id="creditsDialogTitle">Credits</h2>
<button type="button" class="su-dialog-close" id="creditsClose" aria-label="Close">
<svg viewBox="0 0 16 16" width="14" height="14" fill="none" stroke="currentColor" stroke-width="1.8" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"><path d="M3 3l10 10M13 3L3 13"/></svg>
</button>
</header>
<div class="su-dialog-body">
<p>This tool is powered by the following open-source libraries:</p>
<ul class="su-credits-list">
<li><a href="https://github.com/panva/jose" target="_blank" rel="noopener noreferrer"><strong>jose</strong></a> - JSON Object Signing and Encryption for the Web Crypto API, used to decode, verify, and sign JWTs.</li>
</ul>
<p class="su-dialog-fineprint">All trademarks are property of their respective owners.</p>
</div>
</dialog>
<div id="toast" class="toast" role="status" aria-live="polite" style="display:none">
<span id="toastMsg"></span>
</div>
<script>
(function() {
const skillLinkEl = document.getElementById('skillLink');
if (skillLinkEl) {
const p = location.pathname;
skillLinkEl.href = (p === '/' || p === '') ? '/llms.txt' : p.replace(/\/$/, '') + '.md';
}
const toggle = document.getElementById('themeToggle');
const root = document.documentElement;
const setTheme = (t) => {
root.setAttribute('data-theme', t);
try { localStorage.setItem('su-tool-theme', t); } catch (e) {}
};
toggle.addEventListener('click', () => {
setTheme(root.getAttribute('data-theme') === 'dark' ? 'light' : 'dark');
});
try {
const saved = localStorage.getItem('su-tool-theme');
if (saved) setTheme(saved);
else if (window.matchMedia('(prefers-color-scheme: light)').matches) setTheme('light');
} catch (e) {}
})();
(() => {
const dlg = document.getElementById('privacyDialog');
document.getElementById('privacyOpen').addEventListener('click', () => dlg.showModal());
document.getElementById('privacyClose').addEventListener('click', () => dlg.close());
})();
(() => {
const dlg = document.getElementById('creditsDialog');
document.getElementById('creditsOpen').addEventListener('click', () => dlg.showModal());
document.getElementById('creditsClose').addEventListener('click', () => dlg.close());
})();
// URL state encoding: see dev/tools/AGENTS.md → "URL state encoding".
const utf8Enc = new TextEncoder();
const utf8Dec = new TextDecoder();
const toBase64Url = (bytes) => {
let s = '';
for (const b of bytes) s += String.fromCharCode(b);
return btoa(s).replace(/\+/g, '-').replace(/\//g, '_').replace(/=+$/, '');
};
const fromBase64UrlBytes = (str) => {
const b64 = str.replace(/-/g, '+').replace(/_/g, '/');
const padded = b64 + '==='.slice(0, (4 - b64.length % 4) % 4);
const bin = atob(padded);
const out = new Uint8Array(bin.length);
for (let i = 0; i < bin.length; i++) out[i] = bin.charCodeAt(i);
return out;
};
const encodeState = async (text) => {
const bytes = utf8Enc.encode(text);
const stream = new Blob([bytes]).stream().pipeThrough(new CompressionStream('deflate-raw'));
const deflated = new Uint8Array(await new Response(stream).arrayBuffer());
const out = new Uint8Array(4 + deflated.length);
new DataView(out.buffer).setUint32(0, bytes.length, true);
out.set(deflated, 4);
return toBase64Url(out);
};
const decodeState = async (str) => {
try {
const bytes = fromBase64UrlBytes(str);
if (bytes.length < 4) return null;
const stream = new Blob([bytes.subarray(4)]).stream()
.pipeThrough(new DecompressionStream('deflate-raw'));
const inflated = new Uint8Array(await new Response(stream).arrayBuffer());
return utf8Dec.decode(inflated);
} catch { return null; }
};
document.addEventListener('DOMContentLoaded', () => {
const algorithmSelect = document.getElementById('algorithm-select');
const encodedOutput = document.getElementById('encoded-output');
const secretInput = document.getElementById('secret-input');
const signatureStatus = document.getElementById('signature-status');
const copyButton = document.getElementById('copy-button');
const shareButton = document.getElementById('share-button');
const exampleBtn = document.getElementById('exampleBtn');
const clearBtn = document.getElementById('clearBtn');
const fullscreenBtn = document.getElementById('fullscreenBtn');
const fullscreenEnterIcon = document.getElementById('fullscreenEnterIcon');
const fullscreenExitIcon = document.getElementById('fullscreenExitIcon');
const decodedPane = document.getElementById('decodedPane');
const transformInfo = document.getElementById('transform-info');
const parseError = document.getElementById('parse-error');
const toastEl = document.getElementById('toast');
const toastMsgEl = document.getElementById('toastMsg');
let toastTimer;
const toast = (msg) => {
toastMsgEl.textContent = msg;
toastEl.style.display = 'flex';
clearTimeout(toastTimer);
toastTimer = setTimeout(() => { toastEl.style.display = 'none'; }, 2000);
};
const defaultState = {
header: { alg: 'HS256', typ: 'JWT' },
payload: { sub: '1234567890', name: 'John Doe', iat: Math.floor(Date.now() / 1000) },
secret: 'your-secret-key'
};
const JWT_CLAIMS = {
iss: '(Issuer) Claim', sub: '(Subject) Claim', aud: '(Audience) Claim',
exp: '(Expiration Time) Claim', nbf: '(Not Before) Claim', iat: '(Issued At) Claim', jti: '(JWT ID) Claim'
};
const base64UrlDecode = (str) => {
str = str.replace(/-/g, '+').replace(/_/g, '/');
while (str.length % 4) { str += '='; }
try { return decodeURIComponent(escape(atob(str))); } catch (e) { return null; }
};
const isValidJWT = (str) => {
const parts = str.split('.');
if (parts.length !== 3) return false;
if (!parts.every(p => p.length > 0 && /^[A-Za-z0-9_-]+$/.test(p))) return false;
try {
const header = JSON.parse(base64UrlDecode(parts[0]));
return header && typeof header === 'object' && ('alg' in header || 'typ' in header);
} catch (e) { return false; }
};
const tryBase64Decode = (str) => {
let padded = str.replace(/-/g, '+').replace(/_/g, '/');
while (padded.length % 4) padded += '=';
try { return atob(padded); } catch (e) { return null; }
};
const findJWTInString = (str) => {
const re = /[A-Za-z0-9_-]+\.[A-Za-z0-9_-]+\.[A-Za-z0-9_-]+/g;
let match;
while ((match = re.exec(str)) !== null) {
if (isValidJWT(match[0])) return match[0];
}
return null;
};
// Unwraps Bearer prefixes, opaque session tokens, and base64-wrapped envelopes
// around a real JWT, so users can paste whatever their HTTP tooling shows.
const extractJWT = (input) => {
input = input.trim();
if (!input) return null;
if (isValidJWT(input)) return { jwt: input, transforms: [] };
const segments = input.split('_');
for (let i = 1; i < segments.length && i <= 5; i++) {
const remainder = segments.slice(i).join('_');
const prefix = segments.slice(0, i).join('_') + '_';
if (isValidJWT(remainder)) {
return { jwt: remainder, transforms: [`Stripped prefix <code>${prefix}</code>`] };
}
const decoded = tryBase64Decode(remainder);
if (decoded) {
const jwt = findJWTInString(decoded);
if (jwt) {
return { jwt, transforms: [`Stripped prefix <code>${prefix}</code>`, 'Base64-decoded', 'Extracted JWT from decoded payload'] };
}
}
}
const decoded = tryBase64Decode(input);
if (decoded) {
const jwt = findJWTInString(decoded);
if (jwt) {
return { jwt, transforms: ['Base64-decoded', 'Extracted JWT from decoded payload'] };
}
}
return null;
};
const showTransformInfo = (transforms) => {
if (transforms && transforms.length > 0) {
transformInfo.innerHTML = '<strong>Unwrapped token:</strong> ' + transforms.join(' \u2192 ');
transformInfo.style.display = '';
} else {
transformInfo.style.display = 'none';
transformInfo.innerHTML = '';
}
};
const showParseError = (message) => {
if (message) {
parseError.textContent = message;
parseError.style.display = '';
} else {
parseError.style.display = 'none';
parseError.textContent = '';
}
};
// Rewrites the encoded pane with the three colored segment spans. Used by
// every code path that produces a clean token without a live caret to
// preserve - `loadDefaults` / `updateEncoded` (signing), `extractJWT`
// unwrap, and the paste/drop handlers. Typing into the pane intentionally
// does NOT call this, because rewriting `innerHTML` on every keystroke
// would reset the caret to position 0.
const renderColoredToken = (jwt) => {
const [h, p, s] = jwt.split('.');
encodedOutput.innerHTML = `<span class="token-part-header">${h}</span><span class="token-dot">.</span><span class="token-part-payload">${p}</span><span class="token-dot">.</span><span class="token-part-signature">${s}</span>`;
};
const clearDecodedPanels = () => {
const headerEl = document.getElementById('decoded-header');
const payloadEl = document.getElementById('decoded-payload');
if (headerEl) headerEl.value = '';
if (payloadEl) payloadEl.value = '';
populateTable('header-claims-table', null);
populateTable('payload-claims-table', null);
signatureStatus.textContent = '';
signatureStatus.className = '';
};
const updateSignatureStatusUI = (isValid) => {
signatureStatus.textContent = isValid ? 'Signature Verified' : 'Invalid Signature';
signatureStatus.className = isValid ? 'sig-valid' : 'sig-invalid';
};
const updateDecodedFromToken = () => {
const rawInput = encodedOutput.innerText;
showParseError(null);
const result = extractJWT(rawInput);
if (!result) {
showTransformInfo(null);
if (rawInput.trim()) {
clearDecodedPanels();
showParseError('Could not parse as JWT. Expected format: header.payload.signature (base64url-encoded, dot-separated).');
}
return;
}
const { jwt, transforms } = result;
showTransformInfo(transforms);
if (transforms.length > 0) {
renderColoredToken(jwt);
}
const parts = jwt.split('.');
try {
const headerJson = JSON.parse(base64UrlDecode(parts[0]));
document.getElementById('decoded-header').value = JSON.stringify(headerJson, null, 2);
populateTable('header-claims-table', headerJson);
} catch (e) {
document.getElementById('decoded-header').value = base64UrlDecode(parts[0]) || '';
populateTable('header-claims-table', null);
}
try {
const payloadJson = JSON.parse(base64UrlDecode(parts[1]));
document.getElementById('decoded-payload').value = JSON.stringify(payloadJson, null, 2);
populateTable('payload-claims-table', payloadJson);
} catch (e) {
document.getElementById('decoded-payload').value = base64UrlDecode(parts[1]) || '';
populateTable('payload-claims-table', null);
}
verifyToken();
};
const updateEncoded = async () => {
showTransformInfo(null);
showParseError(null);
let header, payload;
try {
header = JSON.parse(document.getElementById('decoded-header').value);
payload = JSON.parse(document.getElementById('decoded-payload').value);
} catch {
encodedOutput.textContent = 'Invalid JSON';
updateSignatureStatusUI(false);
return;
}
if (header.alg !== algorithmSelect.value) {
header.alg = algorithmSelect.value;
document.getElementById('decoded-header').value = JSON.stringify(header, null, 2);
}
try {
const secretKey = new TextEncoder().encode(secretInput.value);
const jwt = await new jose.SignJWT(payload).setProtectedHeader(header).sign(secretKey);
renderColoredToken(jwt);
updateSignatureStatusUI(true);
} catch (err) {
encodedOutput.textContent = `Error: ${err.message}`;
updateSignatureStatusUI(false);
}
};
const verifyToken = async () => {
const token = encodedOutput.innerText;
const secret = secretInput.value;
if (!token || !secret || token.split('.').length !== 3) {
updateSignatureStatusUI(false); return;
}
try {
const secretKey = new TextEncoder().encode(secret);
await jose.jwtVerify(token, secretKey, { algorithms: [algorithmSelect.value] });
updateSignatureStatusUI(true);
} catch (err) { updateSignatureStatusUI(false); }
};
const populateTable = (tableBodyId, data) => {
const tbody = document.getElementById(tableBodyId);
if (!tbody) return;
tbody.innerHTML = '';
if (!data || typeof data !== 'object') return;
for (const key in data) {
const row = tbody.insertRow();
const cellKey = row.insertCell();
const cellValue = row.insertCell();
let keyHtml = `<div>${key}</div>`;
if (JWT_CLAIMS[key]) {
keyHtml += `<span class="claims-desc">${JWT_CLAIMS[key]}</span>`;
}
cellKey.innerHTML = keyHtml;
const value = data[key];
if ((key === 'iat' || key === 'exp' || key === 'nbf') && typeof value === 'number') {
cellValue.textContent = `${value} (${new Date(value * 1000).toUTCString()})`;
} else {
cellValue.textContent = JSON.stringify(value);
}
}
};
// Renders the JSON editor + claim table inside a card body. Both panes are
// always present in the DOM; the global view-tabs at the panel-bar toggles
// which one is active across all cards at once.
const renderCardBody = (contentContainerId, idPrefix) => {
const contentDiv = document.getElementById(contentContainerId);
contentDiv.innerHTML = `
<div data-tab-content="json" class="tab-content active">
<textarea id="decoded-${idPrefix}" spellcheck="false" class="json-editor"></textarea>
</div>
<div data-tab-content="table" class="tab-content">
<table class="claims-table">
<tbody id="${idPrefix}-claims-table"></tbody>
</table>
</div>`;
document.getElementById(`decoded-${idPrefix}`).addEventListener('input', () => {
try {
const jsonData = JSON.parse(document.getElementById(`decoded-${idPrefix}`).value);
populateTable(`${idPrefix}-claims-table`, jsonData);
updateEncoded();
} catch {
/* invalid JSON - wait for the user to finish typing */
}
});
};
renderCardBody('header-tab-content', 'header');
renderCardBody('payload-tab-content', 'payload');
// Global JSON ↔ Table switcher - applies to every card body in the right
// pane simultaneously, so users don't have to keep both per-card tabs in
// sync manually.
const viewTabsEl = document.getElementById('view-tabs');
viewTabsEl.addEventListener('click', (e) => {
if (!e.target.classList.contains('view-tab')) return;
for (const btn of viewTabsEl.querySelectorAll('.view-tab')) {
btn.classList.remove('active');
btn.setAttribute('aria-selected', 'false');
}
e.target.classList.add('active');
e.target.setAttribute('aria-selected', 'true');
const view = e.target.dataset.view;
for (const content of document.querySelectorAll('[data-tab-content]')) {
content.classList.toggle('active', content.dataset.tabContent === view);
}
});
algorithmSelect.addEventListener('change', updateEncoded);
secretInput.addEventListener('input', updateEncoded);
encodedOutput.addEventListener('input', updateDecodedFromToken);
// The encoded pane is a contenteditable div, so the browser's default
// paste/drop inserts the source's rich HTML (with its own inline styles
// like `white-space: nowrap` or `<pre>` wrappers) which overrides the
// pane's `white-space: pre-wrap; word-break: break-all` and produces a
// single overflowing line. Force plain text on every insertion path so
// the layout stays wrapped regardless of where the token came from.
const insertPlainText = (text) => {
const selection = window.getSelection();
if (!selection || selection.rangeCount === 0) {
encodedOutput.textContent = text;
} else {
const range = selection.getRangeAt(0);
if (!encodedOutput.contains(range.commonAncestorContainer)) {
encodedOutput.textContent = text;
} else {
range.deleteContents();
range.insertNode(document.createTextNode(text));
range.collapse(false);
selection.removeAllRanges();
selection.addRange(range);
}
}
encodedOutput.dispatchEvent(new Event('input', { bubbles: true }));
};
// After a paste/drop produces a clean bare JWT, colorize the three
// segments. `updateDecodedFromToken` (run via the dispatched input event)
// intentionally only colorizes when an envelope was unwrapped, to avoid
// resetting the caret on every keystroke during typing. Paste/drop is the
// one moment where there is no live caret to preserve, so we can safely
// recolor here.
const colorizeIfBareJwt = () => {
const result = extractJWT(encodedOutput.innerText);
if (result && result.transforms.length === 0) renderColoredToken(result.jwt);
};
encodedOutput.addEventListener('paste', (e) => {
e.preventDefault();
const text = (e.clipboardData ?? window.clipboardData)?.getData('text/plain') ?? '';
insertPlainText(text);
colorizeIfBareJwt();
});
encodedOutput.addEventListener('drop', (e) => {
e.preventDefault();
const text = e.dataTransfer?.getData('text/plain') ?? '';
encodedOutput.focus();
insertPlainText(text);
colorizeIfBareJwt();
});
copyButton.addEventListener('click', async () => {
try {
await navigator.clipboard.writeText(encodedOutput.innerText);
toast('Copied to clipboard');
} catch {
toast('Failed to copy');
}
});
shareButton.addEventListener('click', async () => {
const jwtValue = encodedOutput.innerText.trim();
if (!jwtValue || jwtValue === 'Invalid JSON') return;
const encoded = await encodeState(JSON.stringify({ j: jwtValue, s: secretInput.value.trim() }));
const shareUrl = `${window.location.origin}${window.location.pathname}#${encoded}`;
history.replaceState({}, '', shareUrl);
try {
await navigator.clipboard.writeText(shareUrl);
toast('Share link copied');
} catch {
toast('Failed to copy share link');
}
});
exampleBtn.addEventListener('click', () => {
loadDefaults();
});
clearBtn.addEventListener('click', () => {
encodedOutput.innerText = '';
secretInput.value = '';
document.getElementById('decoded-header').value = '';
document.getElementById('decoded-payload').value = '';
populateTable('header-claims-table', null);
populateTable('payload-claims-table', null);
signatureStatus.textContent = '';
signatureStatus.className = '';
showTransformInfo(null);
showParseError(null);
history.replaceState({}, '', location.pathname + location.search);
});
fullscreenBtn.addEventListener('click', async () => {
try {
if (!document.fullscreenElement) await decodedPane.requestFullscreen();
else await document.exitFullscreen();
} catch (e) {
toast(`Fullscreen failed: ${e?.message ?? e}`);
}
});
document.addEventListener('fullscreenchange', () => {
const entering = !!document.fullscreenElement;
fullscreenEnterIcon.style.display = entering ? 'none' : 'block';
fullscreenExitIcon.style.display = entering ? 'block' : 'none';
});
const loadDefaults = () => {
document.getElementById('decoded-header').value = JSON.stringify(defaultState.header, null, 2);
document.getElementById('decoded-payload').value = JSON.stringify(defaultState.payload, null, 2);
populateTable('header-claims-table', defaultState.header);
populateTable('payload-claims-table', defaultState.payload);
secretInput.value = defaultState.secret;
algorithmSelect.value = defaultState.header.alg;
updateEncoded();
};
const initialize = async () => {
if (location.hash.length > 1) {
const raw = await decodeState(location.hash.slice(1));
if (raw) {
try {
const { j, s } = JSON.parse(raw);
if (typeof s === 'string') secretInput.value = s;
if (typeof j === 'string' && j) {
encodedOutput.innerText = j;
updateDecodedFromToken();
return;
}
} catch {}
}
}
loadDefaults();
};
initialize();
// Resizable splitter. A full-viewport overlay is mounted during drag so
// mousemove events aren't swallowed by the contenteditable encoded area
// (otherwise the cursor "sticks" mid-drag).
(() => {
const splitter = document.getElementById('splitter');
const grid = splitter.parentElement;
let dragging = false;
let overlay = null;
const stop = () => {
if (!dragging) return;
dragging = false;
splitter.classList.remove('active');
document.body.style.cursor = '';
document.body.style.userSelect = '';
if (overlay) { overlay.remove(); overlay = null; }
};
splitter.addEventListener('mousedown', (e) => {
e.preventDefault();
dragging = true;
splitter.classList.add('active');
document.body.style.cursor = 'col-resize';
document.body.style.userSelect = 'none';
overlay = document.createElement('div');
overlay.className = 'splitter-overlay';
document.body.appendChild(overlay);
});
document.addEventListener('mousemove', (e) => {
if (!dragging) return;
const rect = grid.getBoundingClientRect();
const offset = e.clientX - rect.left;
let pct = (offset / rect.width) * 100;
pct = Math.max(15, Math.min(85, pct));
grid.style.gridTemplateColumns = `${pct}% 12px ${100 - pct}%`;
});
document.addEventListener('mouseup', stop);
document.addEventListener('mouseleave', stop);
})();
});
</script>
</body>
</html>