Skip to content

Commit 441d8ce

Browse files
committed
Fixed scripted JWT generation, updated regex to match: it was incorrect
1 parent a919ab1 commit 441d8ce

File tree

3 files changed

+18
-4
lines changed

3 files changed

+18
-4
lines changed

jwt/generate_jwt.py

+13-3
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,10 @@
66
from typing import Generator, Optional
77
from enum import Enum
88
from argparse import ArgumentParser
9+
import logging
910

1011

12+
LOG = logging.getLogger(__name__)
1113
PADDING_CHARS = ('', "\t", "\n", ' ')
1214

1315

@@ -32,7 +34,7 @@ def leading_json_as_base64() -> Generator:
3234

3335

3436
def trailing_json_as_base64() -> Generator:
35-
for json_type in JSONTypes:
37+
for json_type in [JSONTypes.NUMBER]:
3638
if json_type == JSONTypes.STRING:
3739
for c in range(0x01, 0xf4):
3840
for d in range(0x01, 0xf4):
@@ -66,13 +68,15 @@ def trailing_json_as_base64() -> Generator:
6668

6769

6870
def output_trailing_json(obj: str) -> Generator:
69-
for slide in range(0, 2):
71+
for slide in range(0, 3):
7072
for e in PADDING_CHARS:
7173
for f in PADDING_CHARS:
7274
for g in PADDING_CHARS:
7375
for h in PADDING_CHARS:
7476
padding = e + f + g + h
75-
yield b64(('A' * slide) + obj + padding + '}')
77+
plain = ('A' * slide) + obj + padding + '}'
78+
LOG.debug(plain)
79+
yield b64(plain)
7680

7781

7882
def b64(text: str) -> str:
@@ -84,6 +88,11 @@ def main() -> None:
8488
add_args(parser)
8589
args = parser.parse_args()
8690

91+
logging.basicConfig()
92+
93+
if args.debug:
94+
LOG.setLevel(logging.DEBUG)
95+
8796
if args.leading:
8897
for token in leading_json_as_base64():
8998
print(token)
@@ -98,6 +107,7 @@ def main() -> None:
98107
def add_args(parser: ArgumentParser) -> None:
99108
parser.add_argument('--leading', action='store_true')
100109
parser.add_argument('--trailing', action='store_true')
110+
parser.add_argument('--debug', '-d', action='store_true')
101111

102112

103113
if __name__ == '__main__':

jwt/patterns.yml

+4-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ patterns:
77
description: "JSON Web Tokens are an open, industry standard RFC 7519 method for representing claims securely between two parties."
88
regex:
99
pattern: |
10-
e(?:y[IJ]|yL[CD]|yA[JKgi]|w[koA][JKgi])[A-Za-z0-9_-]{10,}(?:[0-59JKdgilsw-z]fQ|[3HXn]0|[1BJVlpx]9)={0,2}\.e(?:y[IJ]|yL[CD]|yA[JKgi]|w[koA][JKgi])[A-Za-z0-9_-]{10,}(?:[0-59JKdgilsw-z]fQ|[3HXn]0|[1BJVlpx]9)={0,2}\.?[A-Za-z0-9_-]*={0,2}
10+
e(?:y[IJ]|yL[CD]|yA[JKgi]|w[koA][JKgi])[A-Za-z0-9_-]{10,}(?:[0-5JKgw-z]fQ|[3HXn]0|[BFJNRVZdhlp]9)={0,2}\.e(?:y[IJ]|yL[CD]|yA[JKgi]|w[koA][JKgi])[A-Za-z0-9_-]{10,}(?:[0-5JKgw-z]fQ|[3HXn]0|[BFJNRVZdhlp]9)={0,2}\.?[A-Za-z0-9_-]*={0,2}
1111
start: |
1212
[^0-9A-Za-z_.-]|\A
1313
end: |
@@ -20,4 +20,7 @@ patterns:
2020
- name: example.txt
2121
start_offset: 16
2222
end_offset: 171
23+
- name: test_supabase.txt
24+
start_offset: 6
25+
end_offset: 163
2326

jwt/test_supabase.txt

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
token=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJyb2xlIjoic2VydmljZV9yb2xlIiwiaWF0IjoxNjM2MzcxNDkzLCJleHAiOjE5NTE5NDc0OTN9.T365h6AcgnvibAWvN_rIiaFnOK5R1ZGqdEkPI45zsNs

0 commit comments

Comments
 (0)