jwt-toolkit 1.1.0__tar.gz → 1.2.0__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (96) hide show
  1. {jwt_toolkit-1.1.0 → jwt_toolkit-1.2.0}/.github/workflows/ci.yml +4 -4
  2. {jwt_toolkit-1.1.0 → jwt_toolkit-1.2.0}/.pre-commit-config.yaml +4 -4
  3. {jwt_toolkit-1.1.0 → jwt_toolkit-1.2.0}/CONTRIBUTING.md +21 -12
  4. {jwt_toolkit-1.1.0 → jwt_toolkit-1.2.0}/PKG-INFO +32 -26
  5. {jwt_toolkit-1.1.0 → jwt_toolkit-1.2.0}/README.md +31 -25
  6. jwt_toolkit-1.2.0/jwt_toolkit/cli/__init__.py +93 -0
  7. {jwt_toolkit-1.1.0 → jwt_toolkit-1.2.0}/jwt_toolkit/cli/algorithms.py +4 -3
  8. {jwt_toolkit-1.1.0 → jwt_toolkit-1.2.0}/jwt_toolkit/cli/banner.py +25 -32
  9. jwt_toolkit-1.2.0/jwt_toolkit/cli/console.py +47 -0
  10. {jwt_toolkit-1.1.0 → jwt_toolkit-1.2.0}/jwt_toolkit/cli/decoding.py +31 -21
  11. {jwt_toolkit-1.1.0 → jwt_toolkit-1.2.0}/jwt_toolkit/cli/panels.py +2 -2
  12. jwt_toolkit-1.2.0/jwt_toolkit/cli/wordlists.py +14 -0
  13. {jwt_toolkit-1.1.0 → jwt_toolkit-1.2.0}/jwt_toolkit/commands/audit.py +61 -27
  14. jwt_toolkit-1.2.0/jwt_toolkit/commands/crack.py +327 -0
  15. {jwt_toolkit-1.1.0 → jwt_toolkit-1.2.0}/jwt_toolkit/commands/decode.py +3 -4
  16. {jwt_toolkit-1.1.0 → jwt_toolkit-1.2.0}/jwt_toolkit/commands/diff.py +5 -4
  17. {jwt_toolkit-1.1.0 → jwt_toolkit-1.2.0}/jwt_toolkit/commands/download_wordlists.py +106 -65
  18. {jwt_toolkit-1.1.0 → jwt_toolkit-1.2.0}/jwt_toolkit/commands/forge.py +13 -13
  19. {jwt_toolkit-1.1.0 → jwt_toolkit-1.2.0}/jwt_toolkit/commands/generate_secret.py +2 -2
  20. {jwt_toolkit-1.1.0 → jwt_toolkit-1.2.0}/jwt_toolkit/commands/sign.py +66 -27
  21. jwt_toolkit-1.2.0/jwt_toolkit/commands/verify.py +270 -0
  22. {jwt_toolkit-1.1.0 → jwt_toolkit-1.2.0}/jwt_toolkit/core/auditor.py +205 -62
  23. jwt_toolkit-1.2.0/jwt_toolkit/core/claims.py +102 -0
  24. {jwt_toolkit-1.1.0 → jwt_toolkit-1.2.0}/jwt_toolkit/core/cracker.py +14 -16
  25. {jwt_toolkit-1.1.0 → jwt_toolkit-1.2.0}/jwt_toolkit/core/crypto.py +83 -47
  26. {jwt_toolkit-1.1.0 → jwt_toolkit-1.2.0}/jwt_toolkit/core/decoder.py +9 -6
  27. {jwt_toolkit-1.1.0 → jwt_toolkit-1.2.0}/jwt_toolkit/core/diff.py +7 -6
  28. {jwt_toolkit-1.1.0 → jwt_toolkit-1.2.0}/jwt_toolkit/core/encoding.py +9 -2
  29. {jwt_toolkit-1.1.0 → jwt_toolkit-1.2.0}/jwt_toolkit/core/errors.py +1 -0
  30. {jwt_toolkit-1.1.0 → jwt_toolkit-1.2.0}/jwt_toolkit/core/forge.py +17 -25
  31. {jwt_toolkit-1.1.0 → jwt_toolkit-1.2.0}/jwt_toolkit/core/jwks.py +69 -27
  32. {jwt_toolkit-1.1.0 → jwt_toolkit-1.2.0}/jwt_toolkit/core/lifetime.py +2 -1
  33. {jwt_toolkit-1.1.0 → jwt_toolkit-1.2.0}/jwt_toolkit/core/timestamps.py +3 -1
  34. jwt_toolkit-1.2.0/jwt_toolkit/core/wordlist.py +81 -0
  35. {jwt_toolkit-1.1.0 → jwt_toolkit-1.2.0}/pyproject.toml +3 -6
  36. {jwt_toolkit-1.1.0 → jwt_toolkit-1.2.0}/tests/test_auditor.py +106 -0
  37. jwt_toolkit-1.2.0/tests/test_claims.py +89 -0
  38. {jwt_toolkit-1.1.0 → jwt_toolkit-1.2.0}/tests/test_cmd_audit.py +59 -0
  39. {jwt_toolkit-1.1.0 → jwt_toolkit-1.2.0}/tests/test_cmd_crack.py +92 -1
  40. {jwt_toolkit-1.1.0 → jwt_toolkit-1.2.0}/tests/test_cmd_decode.py +44 -0
  41. {jwt_toolkit-1.1.0 → jwt_toolkit-1.2.0}/tests/test_cmd_download_wordlists.py +61 -0
  42. {jwt_toolkit-1.1.0 → jwt_toolkit-1.2.0}/tests/test_cmd_forge.py +15 -0
  43. {jwt_toolkit-1.1.0 → jwt_toolkit-1.2.0}/tests/test_cmd_generate_secret.py +1 -3
  44. jwt_toolkit-1.2.0/tests/test_cmd_global_flags.py +67 -0
  45. {jwt_toolkit-1.1.0 → jwt_toolkit-1.2.0}/tests/test_cmd_sign.py +59 -0
  46. {jwt_toolkit-1.1.0 → jwt_toolkit-1.2.0}/tests/test_cmd_verify.py +67 -24
  47. {jwt_toolkit-1.1.0 → jwt_toolkit-1.2.0}/tests/test_crypto.py +4 -0
  48. {jwt_toolkit-1.1.0 → jwt_toolkit-1.2.0}/tests/test_crypto_asymmetric.py +29 -0
  49. {jwt_toolkit-1.1.0 → jwt_toolkit-1.2.0}/tests/test_decoder.py +6 -0
  50. {jwt_toolkit-1.1.0 → jwt_toolkit-1.2.0}/tests/test_jwks.py +63 -0
  51. jwt_toolkit-1.2.0/tests/test_wordlist.py +55 -0
  52. {jwt_toolkit-1.1.0 → jwt_toolkit-1.2.0}/uv.lock +23 -23
  53. jwt_toolkit-1.1.0/jwt_toolkit/cli/__init__.py +0 -110
  54. jwt_toolkit-1.1.0/jwt_toolkit/cli/console.py +0 -33
  55. jwt_toolkit-1.1.0/jwt_toolkit/commands/crack.py +0 -314
  56. jwt_toolkit-1.1.0/jwt_toolkit/commands/verify.py +0 -351
  57. {jwt_toolkit-1.1.0 → jwt_toolkit-1.2.0}/.editorconfig +0 -0
  58. {jwt_toolkit-1.1.0 → jwt_toolkit-1.2.0}/.github/ISSUE_TEMPLATE/bug_report.yml +0 -0
  59. {jwt_toolkit-1.1.0 → jwt_toolkit-1.2.0}/.github/ISSUE_TEMPLATE/config.yml +0 -0
  60. {jwt_toolkit-1.1.0 → jwt_toolkit-1.2.0}/.github/ISSUE_TEMPLATE/documentation.yml +0 -0
  61. {jwt_toolkit-1.1.0 → jwt_toolkit-1.2.0}/.github/ISSUE_TEMPLATE/feature_request.yml +0 -0
  62. {jwt_toolkit-1.1.0 → jwt_toolkit-1.2.0}/.github/PULL_REQUEST_TEMPLATE.md +0 -0
  63. {jwt_toolkit-1.1.0 → jwt_toolkit-1.2.0}/.github/dependabot.yml +0 -0
  64. {jwt_toolkit-1.1.0 → jwt_toolkit-1.2.0}/.github/workflows/publish.yml +0 -0
  65. {jwt_toolkit-1.1.0 → jwt_toolkit-1.2.0}/.gitignore +0 -0
  66. {jwt_toolkit-1.1.0 → jwt_toolkit-1.2.0}/.python-version +0 -0
  67. {jwt_toolkit-1.1.0 → jwt_toolkit-1.2.0}/LICENSE +0 -0
  68. {jwt_toolkit-1.1.0 → jwt_toolkit-1.2.0}/Makefile +0 -0
  69. {jwt_toolkit-1.1.0 → jwt_toolkit-1.2.0}/SECURITY.md +0 -0
  70. {jwt_toolkit-1.1.0 → jwt_toolkit-1.2.0}/docs/plans/01-correctness-and-robustness.md +0 -0
  71. {jwt_toolkit-1.1.0 → jwt_toolkit-1.2.0}/docs/plans/02-verification-policies.md +0 -0
  72. {jwt_toolkit-1.1.0 → jwt_toolkit-1.2.0}/docs/plans/03-reports-and-automation.md +0 -0
  73. {jwt_toolkit-1.1.0 → jwt_toolkit-1.2.0}/docs/plans/04-jwks-and-discovery.md +0 -0
  74. {jwt_toolkit-1.1.0 → jwt_toolkit-1.2.0}/docs/plans/05-developer-workflows.md +0 -0
  75. {jwt_toolkit-1.1.0 → jwt_toolkit-1.2.0}/docs/plans/06-quality-and-releases.md +0 -0
  76. {jwt_toolkit-1.1.0 → jwt_toolkit-1.2.0}/docs/plans/07-delivery-and-handoff.md +0 -0
  77. {jwt_toolkit-1.1.0 → jwt_toolkit-1.2.0}/docs/plans/08-architecture-refactor.md +0 -0
  78. {jwt_toolkit-1.1.0 → jwt_toolkit-1.2.0}/docs/plans/README.md +0 -0
  79. {jwt_toolkit-1.1.0 → jwt_toolkit-1.2.0}/jwt_toolkit/__init__.py +0 -0
  80. {jwt_toolkit-1.1.0 → jwt_toolkit-1.2.0}/jwt_toolkit/cli/credentials.py +0 -0
  81. {jwt_toolkit-1.1.0 → jwt_toolkit-1.2.0}/jwt_toolkit/commands/__init__.py +0 -0
  82. {jwt_toolkit-1.1.0 → jwt_toolkit-1.2.0}/jwt_toolkit/core/__init__.py +0 -0
  83. {jwt_toolkit-1.1.0 → jwt_toolkit-1.2.0}/jwt_toolkit/py.typed +0 -0
  84. {jwt_toolkit-1.1.0 → jwt_toolkit-1.2.0}/tests/__init__.py +0 -0
  85. {jwt_toolkit-1.1.0 → jwt_toolkit-1.2.0}/tests/conftest.py +0 -0
  86. {jwt_toolkit-1.1.0 → jwt_toolkit-1.2.0}/tests/helpers.py +0 -0
  87. {jwt_toolkit-1.1.0 → jwt_toolkit-1.2.0}/tests/test_cmd_diff.py +0 -0
  88. {jwt_toolkit-1.1.0 → jwt_toolkit-1.2.0}/tests/test_cracker.py +0 -0
  89. {jwt_toolkit-1.1.0 → jwt_toolkit-1.2.0}/tests/test_credentials.py +0 -0
  90. {jwt_toolkit-1.1.0 → jwt_toolkit-1.2.0}/tests/test_diff.py +0 -0
  91. {jwt_toolkit-1.1.0 → jwt_toolkit-1.2.0}/tests/test_forge.py +0 -0
  92. {jwt_toolkit-1.1.0 → jwt_toolkit-1.2.0}/tests/test_lifetime.py +0 -0
  93. {jwt_toolkit-1.1.0 → jwt_toolkit-1.2.0}/tests/test_markup_escaping.py +0 -0
  94. {jwt_toolkit-1.1.0 → jwt_toolkit-1.2.0}/tests/test_package.py +0 -0
  95. {jwt_toolkit-1.1.0 → jwt_toolkit-1.2.0}/tests/test_timestamps.py +0 -0
  96. {jwt_toolkit-1.1.0 → jwt_toolkit-1.2.0}/wordlists/common-secrets.txt +0 -0
@@ -19,7 +19,7 @@ jobs:
19
19
  with:
20
20
  enable-cache: true
21
21
  - name: Install dev dependencies
22
- run: uv sync --group dev
22
+ run: uv sync --locked --group dev
23
23
  - name: Ruff format (check only)
24
24
  run: uv run ruff format --check .
25
25
  - name: Ruff lint
@@ -33,7 +33,7 @@ jobs:
33
33
  - uses: astral-sh/setup-uv@v7
34
34
  with:
35
35
  enable-cache: true
36
- - run: uv sync --group dev
36
+ - run: uv sync --locked --group dev
37
37
  - run: uv run mypy
38
38
 
39
39
  security:
@@ -44,7 +44,7 @@ jobs:
44
44
  - uses: astral-sh/setup-uv@v7
45
45
  with:
46
46
  enable-cache: true
47
- - run: uv sync --group dev
47
+ - run: uv sync --locked --group dev
48
48
  - name: Bandit static analysis
49
49
  run: uv run bandit -c pyproject.toml -r jwt_toolkit --severity-level medium
50
50
  - name: pip-audit dependency CVEs
@@ -63,7 +63,7 @@ jobs:
63
63
  with:
64
64
  enable-cache: true
65
65
  python-version: ${{ matrix.python-version }}
66
- - run: uv sync --group dev
66
+ - run: uv sync --locked --group dev
67
67
  - name: Run tests with coverage
68
68
  run: uv run pytest --cov --cov-report=term-missing --cov-report=xml -n auto
69
69
  - name: Upload coverage artifact
@@ -8,7 +8,7 @@
8
8
  repos:
9
9
  # General hygiene
10
10
  - repo: https://github.com/pre-commit/pre-commit-hooks
11
- rev: v5.0.0
11
+ rev: v6.0.0
12
12
  hooks:
13
13
  - id: trailing-whitespace
14
14
  - id: end-of-file-fixer
@@ -21,15 +21,15 @@ repos:
21
21
  # Ruff — formatter + linter (replaces black, flake8, isort).
22
22
  # Order matters: format first, then lint so the linter sees formatted code.
23
23
  - repo: https://github.com/astral-sh/ruff-pre-commit
24
- rev: v0.15.14
24
+ rev: v0.17.1
25
25
  hooks:
26
26
  - id: ruff-format
27
- - id: ruff
27
+ - id: ruff-check
28
28
  args: ["--fix"]
29
29
 
30
30
  # Bandit static security scan. Source-only, no network — safe to run on commit.
31
31
  - repo: https://github.com/PyCQA/bandit
32
- rev: 1.8.6
32
+ rev: 1.9.4
33
33
  hooks:
34
34
  - id: bandit
35
35
  args: ["-c", "pyproject.toml", "--severity-level", "medium"]
@@ -46,28 +46,37 @@ jwt-toolkit/
46
46
  │ ├── __init__.py # Package version
47
47
  │ ├── cli/ # CLI plumbing: banner, console, panels, decoding helpers
48
48
  │ │ ├── __init__.py # Click root group, global flags, command registration
49
- │ │ ├── algorithms.py # CLI-side algorithm validation and listing
50
- │ │ ├── banner.py # Startup banner and custom help renderer
51
- │ │ ├── console.py # Rich console wiring (quiet, no-color, JSON modes)
52
- │ │ ├── decoding.py # Shared CLI helpers for decoding input
53
- │ │ └── panels.py # Reusable Rich panels (header, payload, verdicts, findings)
49
+ │ │ ├── algorithms.py # CLI-side algorithm validation
50
+ │ │ ├── banner.py # Startup banner, help screen, and the COMMANDS/EXAMPLES lists
51
+ │ │ ├── console.py # Result, error, and status consoles (quiet, no-color)
52
+ │ │ ├── credentials.py # --secret / --secret-file handling
53
+ │ │ ├── decoding.py # Token input (argument, @file, stdin) and error envelopes
54
+ │ │ ├── panels.py # Reusable Rich panels for errors and results
55
+ │ │ └── wordlists.py # Location of the bundled wordlist
54
56
  │ ├── commands/ # One file per `jwt-toolkit <command>`
55
57
  │ │ ├── audit.py
56
58
  │ │ ├── crack.py
57
59
  │ │ ├── decode.py
60
+ │ │ ├── diff.py
58
61
  │ │ ├── download_wordlists.py
59
62
  │ │ ├── forge.py
60
63
  │ │ ├── generate_secret.py
61
64
  │ │ ├── sign.py
62
65
  │ │ └── verify.py
63
66
  │ └── core/ # Pure logic, no Click and no Rich
64
- │ ├── auditor.py # Static audit rules and verdict scoring
67
+ │ ├── auditor.py # Static audit rules, key-material checks, and grading
68
+ │ ├── claims.py # Claim and critical-header checks used by verify
69
+ │ ├── cracker.py # Batched, optionally parallel HMAC secret search
65
70
  │ ├── crypto.py # HMAC and asymmetric signing and verification
66
- │ ├── decoder.py # JWT parsing and base64url helpers
67
- │ ├── encoding.py # base64url, JSON canonicalization
68
- │ ├── errors.py # Domain-specific exceptions
71
+ │ ├── decoder.py # JWT splitting and decoding
72
+ │ ├── diff.py # Field-by-field token comparison
73
+ │ ├── encoding.py # base64url and strict JSON helpers
74
+ │ ├── errors.py # Domain-specific exceptions with stable codes
69
75
  │ ├── forge.py # Defensive attack-shaped variant generation
70
- │ └── jwks.py # JWKS fetching, caching, and key selection
76
+ │ ├── jwks.py # JWKS fetching and key selection
77
+ │ ├── lifetime.py # --expires-in parsing
78
+ │ ├── timestamps.py # Human-readable time claims
79
+ │ └── wordlist.py # Streaming wordlist reader and candidate expansion
71
80
  ├── tests/ # Pytest suite mirroring the source layout
72
81
  │ ├── conftest.py # Shared fixtures (keys, tokens, tmp wordlists)
73
82
  │ ├── helpers.py # Test helpers
@@ -189,8 +198,8 @@ We follow [Conventional Commits](https://www.conventionalcommits.org/). The form
189
198
 
190
199
  `<scope>` is a short identifier for the area of the codebase. Use a command name, a `core/` module name, or a high-level area:
191
200
 
192
- - Command scopes: `audit`, `crack`, `decode`, `verify`, `sign`, `forge`, `generate-secret`, `download-wordlists`
193
- - Core scopes: `core`, `auditor`, `crypto`, `decoder`, `forge`, `jwks`, `jwks-cache`
201
+ - Command scopes: `audit`, `crack`, `decode`, `diff`, `verify`, `sign`, `forge`, `generate-secret`, `download-wordlists`
202
+ - Core scopes: `core`, `auditor`, `claims`, `cracker`, `crypto`, `decoder`, `forge`, `jwks`, `wordlist`
194
203
  - Other scopes: `cli`, `readme`, `ci`, `deps`, `release`
195
204
 
196
205
  Rules:
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.5
2
2
  Name: jwt-toolkit
3
- Version: 1.1.0
3
+ Version: 1.2.0
4
4
  Summary: A command-line toolkit for inspecting, verifying, cracking, and securing JSON Web Tokens. Built to expose how JWT signing works and where it breaks.
5
5
  Project-URL: Homepage, https://github.com/KhaledSaeed18/jwt-toolkit
6
6
  Project-URL: Repository, https://github.com/KhaledSaeed18/jwt-toolkit
@@ -32,7 +32,7 @@ Description-Content-Type: text/markdown
32
32
  # JWT Toolkit
33
33
 
34
34
  <p align="center">
35
- <a href="https://pypi.org/project/jwt-toolkit/"><img src="https://raw.githubusercontent.com/KhaledSaeed18/jwt-toolkit/main/assets/images/hero.png" alt="jwt-toolkit: audit flags a weak HS256 token, crack finds its secret in the bundled wordlist, and verify checks a strong token's signature and claims" width="900"></a>
35
+ <a href="https://pypi.org/project/jwt-toolkit/"><img src="https://raw.githubusercontent.com/KhaledSaeed18/jwt-toolkit/main/assets/images/hero.png" alt="jwt-toolkit: an HS256 token split into header, payload, and signature, with the signature highlighted because crack recovered its secret from the bundled wordlist" width="900"></a>
36
36
  </p>
37
37
 
38
38
  <p align="center">
@@ -68,12 +68,12 @@ The JWS logic is implemented in the open on top of [`cryptography`](https://cryp
68
68
  | | |
69
69
  | --- | --- |
70
70
  | **Decode** | Pretty-print the header, payload, and signature, with `iat`/`nbf`/`exp` shown in UTC and relative to now. |
71
- | **Audit** | Static analysis with no key required. Flags `alg: none`, weak HMAC use, embedded `jwk`, `jku`/`x5u` over HTTP, `kid` injection shapes, `crit` misuse, missing or excessive lifetimes, and PII in the payload, with CVE references and an A to F grade. |
71
+ | **Audit** | Static analysis with no key required. Flags `alg: none`, stripped signatures, weak HMAC use, embedded `jwk`, `jku`/`x5u` over HTTP, `kid` injection shapes, `crit` misuse, missing or excessive lifetimes, and PII in the payload, with CVE references and an A to F grade. Given the key, it also flags guessable secrets and RSA keys under 2048 bits. |
72
72
  | **Verify** | Signature plus `exp`, `nbf`, `iat`, `iss`, and `aud` checks against an HMAC secret, a PEM key, an X.509 certificate, or a JWKS endpoint. |
73
73
  | **Diff** | Compare two tokens field by field, with JSON Pointer paths and identity, permission, and lifetime fields highlighted. |
74
74
  | **Sign** | Mint test tokens with HMAC, RSA, RSA-PSS, ECDSA, or EdDSA keys, including encrypted private keys, payload files, and lifetimes such as `--expires-in 15m`. |
75
75
  | **Forge** | Generate attack-shaped variants of a token (`alg: none`, algorithm confusion, tampered payloads) to check that your verifier rejects them. |
76
- | **Crack** | Test an HMAC secret against a wordlist across worker processes. A curated list ships with the package. |
76
+ | **Crack** | Test an HMAC secret against a wordlist across worker processes, with `--json` for CI. A curated list ships with the package. |
77
77
  | **Generate** | Produce cryptographically strong secrets, raw for scripts or formatted for humans. |
78
78
 
79
79
  ## Installation
@@ -170,7 +170,7 @@ jwt-toolkit audit <token> --strict --require iss,aud --json
170
170
  ┏━━━━━━━━━━━━┳━━━━━━━━━━━━━━━━┳━━━━━━━━━━━━━━━━━━━━━━━┳━━━━━━━━━━━━━━━━━━━━━━━━┓
171
171
  ┃ Severity ┃ Field ┃ Detail ┃ Recommendation ┃
172
172
  ┡━━━━━━━━━━━━╇━━━━━━━━━━━━━━━━╇━━━━━━━━━━━━━━━━━━━━━━━╇━━━━━━━━━━━━━━━━━━━━━━━━┩
173
- │ WARN │ alg │ HS256 is symmetric — │ Use a │
173
+ │ WARN │ alg │ HS256 is symmetric: │ Use a │
174
174
  │ │ │ the shared secret │ cryptographically │
175
175
  │ │ │ must be strong or it │ strong secret │
176
176
  │ │ │ can be brute-forced │ (jwt-toolkit │
@@ -178,7 +178,7 @@ jwt-toolkit audit <token> --strict --require iss,aud --json
178
178
  │ │ │ │ migrate to an │
179
179
  │ │ │ │ asymmetric algorithm. │
180
180
  ├────────────┼────────────────┼───────────────────────┼────────────────────────┤
181
- │ WARN │ exp │ No exp claim — token │ Always set exp; │
181
+ │ WARN │ exp │ No exp claim: token │ Always set exp; │
182
182
  │ │ │ never expires │ short-lived tokens │
183
183
  │ │ │ │ limit blast radius if │
184
184
  │ │ │ │ leaked. │
@@ -189,8 +189,8 @@ jwt-toolkit audit <token> --strict --require iss,aud --json
189
189
  | --- | --- |
190
190
  | `--strict` | Treat WARN findings as failures (exit 1). |
191
191
  | `--require CLAIMS` | Comma-separated claims that must be present, such as `iss,aud,sub`. Each missing one is a WARN finding. |
192
- | `--secret`, `--secret-file` | Also verify an HMAC signature. |
193
- | `--public-key FILE` | Also verify an asymmetric signature with a PEM key or X.509 certificate. |
192
+ | `--secret`, `--secret-file` | Also verify an HMAC signature. When the secret verifies the token, it is also checked against the bundled common-secrets list and the RFC 7518 minimum length. |
193
+ | `--public-key FILE` | Also verify an asymmetric signature with a PEM key or X.509 certificate, and check the RSA key size. |
194
194
  | `--json` | Print the full report, including every finding and its recommendation. |
195
195
 
196
196
  **What it checks**
@@ -198,10 +198,12 @@ jwt-toolkit audit <token> --strict --require iss,aud --json
198
198
  | Area | Findings |
199
199
  | --- | --- |
200
200
  | Algorithm | `alg: none` in any casing (CRITICAL, CVE-2015-2951); non-registered spellings such as `hs256`; symmetric algorithms that depend on secret strength; unknown or missing `alg`; the deprecated `EdDSA` name. |
201
- | Key smuggling | `jwk` embedded in the header (CRITICAL, CVE-2018-0114); `jku` or `x5u` over plain HTTP (CRITICAL) or pointing at external keys (WARN); HMAC combined with key-bearing headers, the HS/RS confusion shape (CRITICAL, CVE-2016-10555). |
201
+ | Signature | A signed `alg` with the signature removed, the stripped-signature shape (CRITICAL). |
202
+ | Key smuggling | `jwk` embedded in the header (CRITICAL, CVE-2018-0114); `jku` or `x5u` over plain HTTP (CRITICAL) or pointing at external keys (WARN); an `x5c` certificate chain that a verifier must validate against a pinned root (WARN); HMAC combined with key-bearing headers, the HS/RS confusion shape (CRITICAL, CVE-2016-10555). |
202
203
  | Header parameters | `kid` containing path traversal, SQL, or command injection sequences; non-string `kid`; `crit` that is malformed or lists missing parameters; non-boolean `b64`; unexpected `typ`. |
203
204
  | Lifetime | Missing `exp`; expired tokens; `nbf` in the future; `iat` in the future or implausible; very long lifetimes; non-numeric time claims. |
204
- | Claims | Missing `iss`, `aud`, `iat`, or `jti` (INFO), and any claim named in `--require` (WARN). |
205
+ | Claims | Missing `iss`, `aud`, `iat`, or `jti` (INFO), and any claim named in `--require` (WARN); `iss` or `sub` that is not a string, and `aud` that is not a string or list of strings (WARN). |
206
+ | Key material | With `--secret`: a secret in the bundled common-secrets list (CRITICAL) or shorter than the hash output, which RFC 7518 3.2 requires (WARN). With `--public-key`: an RSA key under 2048 bits (CRITICAL, NIST SP 800-131A). Findings never include the secret. |
205
207
  | Payload contents | Sensitive field names such as `password` or `secret`; email addresses; Luhn-valid card numbers anywhere in nested data. |
206
208
 
207
209
  **Grades**: any CRITICAL finding gives **F**, three or more WARN give **C**, one or two WARN give **B**, otherwise **A**.
@@ -210,7 +212,7 @@ jwt-toolkit audit <token> --strict --require iss,aud --json
210
212
 
211
213
  ### verify
212
214
 
213
- Checks the signature, then the registered claims. The algorithm must match the key you supply, so an RS256 public key never verifies an HS256 token, and `alg: none` is always rejected.
215
+ Checks the signature, then the registered claims. The key you supply decides the algorithm family, so an RS256 public key never verifies an HS256 token, and `alg: none` is always rejected. A token whose `alg` is `none`, unknown, or from the other family fails the signature check as an invalid token.
214
216
 
215
217
  ```bash
216
218
  jwt-toolkit verify <token> --secret-file hs256.secret --issuer auth.example.com --audience api
@@ -223,14 +225,14 @@ jwt-toolkit verify <token> --jwks-url https://auth.example.com/.well-known/jwks.
223
225
  | --- | --- |
224
226
  | `--secret`, `--secret-file` | HMAC secret for `HS*` tokens. |
225
227
  | `--public-key FILE` | PEM public key or X.509 certificate for `RS*`, `PS*`, `ES*`, and `Ed*` tokens. |
226
- | `--jwks-url URL` | JWKS endpoint (`https://`, `http://`, or `file://`). The token's `kid` selects the key, and its `kty`, `crv`, and `alg` must match the token. |
228
+ | `--jwks-url URL` | JWKS endpoint (`https://`, `http://`, or `file://`). The token's `kid` selects the key, and its `kty`, `crv`, and `alg` must match the token. A key marked `use: enc`, or whose `key_ops` lacks `verify`, is refused. An `http://` URL adds a WARN check, since the key could be swapped in transit. |
227
229
  | `--issuer`, `--audience` | Expected `iss` and `aud`. `aud` may be a string or a list. |
228
230
  | `--leeway SECONDS` | Clock-skew tolerance for `exp` and `nbf`. |
229
231
  | `--json` | Print `{schema_version, valid, checks[]}`. |
230
232
 
231
- Checks performed: signature; `crit` (rejected, since no extensions are supported); `exp` (a token is expired at its `exp` second); `nbf`; `iat` not in the future; and `iss`/`aud` when requested. Time claims must be finite numbers.
233
+ Checks performed: signature; `crit` (rejected, since no extensions are supported); `exp` (a token is expired at its `exp` second); `nbf`; `iat` not in the future; and `iss`/`aud` when requested. Time claims must be finite numbers. A missing `iss` or `aud` fails the check by name.
232
234
 
233
- **Exit codes**: `0` valid, `1` invalid, `2` unusable input, key, or options.
235
+ **Exit codes**: `0` valid, `1` invalid (including `alg: none` and algorithm-confusion tokens), `2` unusable input, key, or options, such as no key or two keys.
234
236
 
235
237
  ### diff
236
238
 
@@ -276,8 +278,8 @@ Mints a token for tests and fixtures. The header always declares the algorithm t
276
278
 
277
279
  ```bash
278
280
  jwt-toolkit sign --payload '{"sub":"1"}' --secret-file hs256.secret
279
- jwt-toolkit sign --payload-file fixture.json --private-key private.pem --alg RS256 --expires-in 15m
280
- echo '{"sub":"1"}' | jwt-toolkit sign --payload-file - --private-key ed25519.pem --alg Ed25519
281
+ jwt-toolkit sign --payload-file fixture.json --private-key private.pem --expires-in 15m
282
+ echo '{"sub":"1"}' | jwt-toolkit sign --payload-file - --private-key rsa.pem --alg PS256
281
283
  ```
282
284
 
283
285
  | Option | Description |
@@ -287,7 +289,7 @@ echo '{"sub":"1"}' | jwt-toolkit sign --payload-file - --private-key ed25519.pem
287
289
  | `--secret`, `--secret-file` | HMAC secret for `HS*`. |
288
290
  | `--private-key FILE` | PEM private key (PKCS#8 or traditional) for `RS*`, `PS*`, `ES*`, and `Ed*`. |
289
291
  | `--passphrase-file FILE` | Passphrase for an encrypted private key. Without it, you are prompted on a terminal; non-interactive runs fail instead of hanging. |
290
- | `--alg ALG` | Signing algorithm, `HS256` by default. |
292
+ | `--alg ALG` | Signing algorithm. Defaults to `HS256` with a secret. With `--private-key` and no `--alg`, it follows the key: `RS256` for RSA, `ES256`/`ES384`/`ES512` by curve, and `Ed25519` or `Ed448`. |
291
293
  | `--header JSON` | Replace the default `{"alg": ..., "typ": "JWT"}` header. |
292
294
 
293
295
  The token is printed on its own line, so `$(jwt-toolkit sign ...)` captures it cleanly.
@@ -322,6 +324,7 @@ Tries every line of a wordlist as the HMAC secret. Use it on your own tokens to
322
324
  jwt-toolkit crack <token> # bundled common-secrets list
323
325
  jwt-toolkit crack <token> rockyou.txt --workers 8
324
326
  jwt-toolkit crack <token> keys.txt --encoding all --output found.txt
327
+ jwt-toolkit crack <token> --json # for CI
325
328
  ```
326
329
 
327
330
  ```
@@ -332,9 +335,9 @@ jwt-toolkit crack <token> keys.txt --encoding all --output found.txt
332
335
  │ Position : #107 of ~313 candidates │
333
336
  │ Candidates tried : 107 │
334
337
  │ Time elapsed : 0.001s │
335
- │ Average rate : 107.7k c/s │
338
+ │ Average rate : 128.8k c/s │
336
339
  │ │
337
- │ This secret is in a common wordlist — it is not safe. │
340
+ │ This secret is in the wordlist, so it is not safe. │
338
341
  │ Generate a strong secret with: jwt-toolkit generate-secret │
339
342
  ╰──────────────────────────────────────────────────────────────────────────────╯
340
343
  ```
@@ -344,7 +347,8 @@ jwt-toolkit crack <token> keys.txt --encoding all --output found.txt
344
347
  | `WORDLIST` | Path to a wordlist. Without it, the curated list bundled with the package is used. |
345
348
  | `--workers N` | Worker processes, 1 to 64, default 4. Lists under 50,000 candidates run in one process. `--threads` is accepted as an alias. |
346
349
  | `--encoding` | Treat each line as `utf-8` text, `hex`, `base64`, or try `all` three. |
347
- | `--output FILE` | Write a found secret to a file. |
350
+ | `--output FILE` | Write a found secret to a file, exactly as the wordlist line holds it. The file is readable by its owner only (mode 0600). |
351
+ | `--json` | Print `{schema_version, found, algorithm, wordlist, encoding, candidates_tried, elapsed_seconds}`; a match adds `secret`, `secret_encoding`, `position`, and `saved_to`. |
348
352
 
349
353
  Wordlists are streamed, so multi-gigabyte lists are fine. Each line is tried exactly as written: only the line ending and a leading byte-order mark are removed, so secrets with spaces or a leading `#` are found.
350
354
 
@@ -374,7 +378,7 @@ Saves the curated wordlist as a file, for use with other tools or as a starting
374
378
  jwt-toolkit download-wordlists --output-dir wordlists
375
379
  ```
376
380
 
377
- The file is fetched over verified TLS from this release's git tag and checked against a pinned SHA-256 before it is kept. `--source URL` downloads from somewhere else without the hash check, and `--force` overwrites an existing file.
381
+ The file is fetched over verified TLS from this release's git tag and checked against a pinned SHA-256 before it is kept. It is downloaded to a temporary file first, so a failed or tampered download never replaces an existing copy. `--source URL` (`https://`, `http://`, or `file://`) downloads from somewhere else without the hash check, and `--force` overwrites an existing file.
378
382
 
379
383
  ## Passing tokens, keys, and secrets
380
384
 
@@ -386,13 +390,13 @@ The file is fetched over verified TLS from this release's git tag and checked ag
386
390
  | `@path/to/token.jwt` | Read the token from a file. |
387
391
  | `-` | Read the token from stdin. |
388
392
 
389
- Surrounding whitespace and line breaks are ignored.
393
+ Surrounding whitespace and line breaks are ignored, and a leading `Bearer ` is dropped, so a value copied from an `Authorization` header works as-is.
390
394
 
391
395
  **HMAC secrets.** `--secret VALUE` is convenient but ends up in shell history and is visible to other users in process listings. Prefer `--secret-file FILE`: the file is read as UTF-8 text, and only a byte-order mark and one trailing newline are removed, so the output of `generate-secret --raw` works unchanged.
392
396
 
393
397
  **Asymmetric keys.** Private keys are PEM files in PKCS#8 or traditional format. Encrypted keys are supported through `--passphrase-file` or an interactive prompt. Public keys may be PEM `SubjectPublicKeyInfo` keys or X.509 certificates.
394
398
 
395
- **JWKS.** `verify --jwks-url` fetches a key set over HTTPS (or reads a `file://` path), selects the key by the token's `kid`, and requires the key type, curve, and any `alg` on the key to match the token.
399
+ **JWKS.** `verify --jwks-url` fetches a key set over HTTPS (or reads a `file://` path), selects the key by the token's `kid`, and requires the key type, curve, and any `alg` on the key to match the token. Responses over 1 MiB and redirects from `https` to `http` are refused.
396
400
 
397
401
  ## Supported algorithms
398
402
 
@@ -416,11 +420,13 @@ jwt-toolkit --quiet --no-color audit "$TOKEN" --json
416
420
 
417
421
  | Option | Environment variable | Effect |
418
422
  | --- | --- | --- |
419
- | `--quiet` | `JWT_TOOLKIT_QUIET=1` | Suppress the banner and non-essential output. |
423
+ | `--quiet` | `JWT_TOOLKIT_QUIET=1` | Drop the banner, progress, and hints. Results and errors are always printed. |
420
424
  | `--no-color` | `NO_COLOR=1` | Disable colors. |
421
425
  | `--no-banner` | `JWT_TOOLKIT_NO_BANNER=1` | Suppress the banner shown by a bare `jwt-toolkit`. |
422
426
 
423
- **JSON output.** `decode`, `audit`, `verify`, `diff`, and `forge` accept `--json`. Every document carries `"schema_version": "0.1"`; a field will not be renamed or removed without a new schema version. Errors use the same envelope with a stable code:
427
+ **Output streams.** Results go to stdout; errors, progress, and hints go to stderr, so `jwt-toolkit sign ... > token.jwt` captures only the token. Under `--json`, error documents are printed to stdout like any other result.
428
+
429
+ **JSON output.** `decode`, `audit`, `verify`, `diff`, `forge`, and `crack` accept `--json`. Every document carries `"schema_version": "0.1"`; a field will not be renamed or removed without a new schema version. Errors use the same envelope with a stable code:
424
430
 
425
431
  ```json
426
432
  {
@@ -431,7 +437,7 @@ jwt-toolkit --quiet --no-color audit "$TOKEN" --json
431
437
  }
432
438
  ```
433
439
 
434
- Error codes include `invalid_structure`, `invalid_base64url`, `invalid_json`, `invalid_json_object`, `invalid_number`, `token_unreadable`, `unsupported_algorithm`, `invalid_key_options`, `key_error`, and `stdin_conflict`.
440
+ Error codes include `invalid_structure`, `invalid_base64url`, `invalid_json`, `invalid_json_object`, `invalid_number`, `token_unreadable`, `unsupported_algorithm`, `invalid_key_options`, `key_error`, `stdin_conflict`, `signature_missing`, `wordlist_missing`, `wordlist_unreadable`, and `wordlist_empty`.
435
441
 
436
442
  **Exit codes.** `0` means the check passed, `1` means it found a problem, and `2` means the input could not be used. The exceptions are [`crack`](#crack), which exits `1` when it finds the secret, and [`diff`](#diff), which only exits `1` with `--exit-code`.
437
443
 
@@ -1,7 +1,7 @@
1
1
  # JWT Toolkit
2
2
 
3
3
  <p align="center">
4
- <a href="https://pypi.org/project/jwt-toolkit/"><img src="https://raw.githubusercontent.com/KhaledSaeed18/jwt-toolkit/main/assets/images/hero.png" alt="jwt-toolkit: audit flags a weak HS256 token, crack finds its secret in the bundled wordlist, and verify checks a strong token's signature and claims" width="900"></a>
4
+ <a href="https://pypi.org/project/jwt-toolkit/"><img src="https://raw.githubusercontent.com/KhaledSaeed18/jwt-toolkit/main/assets/images/hero.png" alt="jwt-toolkit: an HS256 token split into header, payload, and signature, with the signature highlighted because crack recovered its secret from the bundled wordlist" width="900"></a>
5
5
  </p>
6
6
 
7
7
  <p align="center">
@@ -37,12 +37,12 @@ The JWS logic is implemented in the open on top of [`cryptography`](https://cryp
37
37
  | | |
38
38
  | --- | --- |
39
39
  | **Decode** | Pretty-print the header, payload, and signature, with `iat`/`nbf`/`exp` shown in UTC and relative to now. |
40
- | **Audit** | Static analysis with no key required. Flags `alg: none`, weak HMAC use, embedded `jwk`, `jku`/`x5u` over HTTP, `kid` injection shapes, `crit` misuse, missing or excessive lifetimes, and PII in the payload, with CVE references and an A to F grade. |
40
+ | **Audit** | Static analysis with no key required. Flags `alg: none`, stripped signatures, weak HMAC use, embedded `jwk`, `jku`/`x5u` over HTTP, `kid` injection shapes, `crit` misuse, missing or excessive lifetimes, and PII in the payload, with CVE references and an A to F grade. Given the key, it also flags guessable secrets and RSA keys under 2048 bits. |
41
41
  | **Verify** | Signature plus `exp`, `nbf`, `iat`, `iss`, and `aud` checks against an HMAC secret, a PEM key, an X.509 certificate, or a JWKS endpoint. |
42
42
  | **Diff** | Compare two tokens field by field, with JSON Pointer paths and identity, permission, and lifetime fields highlighted. |
43
43
  | **Sign** | Mint test tokens with HMAC, RSA, RSA-PSS, ECDSA, or EdDSA keys, including encrypted private keys, payload files, and lifetimes such as `--expires-in 15m`. |
44
44
  | **Forge** | Generate attack-shaped variants of a token (`alg: none`, algorithm confusion, tampered payloads) to check that your verifier rejects them. |
45
- | **Crack** | Test an HMAC secret against a wordlist across worker processes. A curated list ships with the package. |
45
+ | **Crack** | Test an HMAC secret against a wordlist across worker processes, with `--json` for CI. A curated list ships with the package. |
46
46
  | **Generate** | Produce cryptographically strong secrets, raw for scripts or formatted for humans. |
47
47
 
48
48
  ## Installation
@@ -139,7 +139,7 @@ jwt-toolkit audit <token> --strict --require iss,aud --json
139
139
  ┏━━━━━━━━━━━━┳━━━━━━━━━━━━━━━━┳━━━━━━━━━━━━━━━━━━━━━━━┳━━━━━━━━━━━━━━━━━━━━━━━━┓
140
140
  ┃ Severity ┃ Field ┃ Detail ┃ Recommendation ┃
141
141
  ┡━━━━━━━━━━━━╇━━━━━━━━━━━━━━━━╇━━━━━━━━━━━━━━━━━━━━━━━╇━━━━━━━━━━━━━━━━━━━━━━━━┩
142
- │ WARN │ alg │ HS256 is symmetric — │ Use a │
142
+ │ WARN │ alg │ HS256 is symmetric: │ Use a │
143
143
  │ │ │ the shared secret │ cryptographically │
144
144
  │ │ │ must be strong or it │ strong secret │
145
145
  │ │ │ can be brute-forced │ (jwt-toolkit │
@@ -147,7 +147,7 @@ jwt-toolkit audit <token> --strict --require iss,aud --json
147
147
  │ │ │ │ migrate to an │
148
148
  │ │ │ │ asymmetric algorithm. │
149
149
  ├────────────┼────────────────┼───────────────────────┼────────────────────────┤
150
- │ WARN │ exp │ No exp claim — token │ Always set exp; │
150
+ │ WARN │ exp │ No exp claim: token │ Always set exp; │
151
151
  │ │ │ never expires │ short-lived tokens │
152
152
  │ │ │ │ limit blast radius if │
153
153
  │ │ │ │ leaked. │
@@ -158,8 +158,8 @@ jwt-toolkit audit <token> --strict --require iss,aud --json
158
158
  | --- | --- |
159
159
  | `--strict` | Treat WARN findings as failures (exit 1). |
160
160
  | `--require CLAIMS` | Comma-separated claims that must be present, such as `iss,aud,sub`. Each missing one is a WARN finding. |
161
- | `--secret`, `--secret-file` | Also verify an HMAC signature. |
162
- | `--public-key FILE` | Also verify an asymmetric signature with a PEM key or X.509 certificate. |
161
+ | `--secret`, `--secret-file` | Also verify an HMAC signature. When the secret verifies the token, it is also checked against the bundled common-secrets list and the RFC 7518 minimum length. |
162
+ | `--public-key FILE` | Also verify an asymmetric signature with a PEM key or X.509 certificate, and check the RSA key size. |
163
163
  | `--json` | Print the full report, including every finding and its recommendation. |
164
164
 
165
165
  **What it checks**
@@ -167,10 +167,12 @@ jwt-toolkit audit <token> --strict --require iss,aud --json
167
167
  | Area | Findings |
168
168
  | --- | --- |
169
169
  | Algorithm | `alg: none` in any casing (CRITICAL, CVE-2015-2951); non-registered spellings such as `hs256`; symmetric algorithms that depend on secret strength; unknown or missing `alg`; the deprecated `EdDSA` name. |
170
- | Key smuggling | `jwk` embedded in the header (CRITICAL, CVE-2018-0114); `jku` or `x5u` over plain HTTP (CRITICAL) or pointing at external keys (WARN); HMAC combined with key-bearing headers, the HS/RS confusion shape (CRITICAL, CVE-2016-10555). |
170
+ | Signature | A signed `alg` with the signature removed, the stripped-signature shape (CRITICAL). |
171
+ | Key smuggling | `jwk` embedded in the header (CRITICAL, CVE-2018-0114); `jku` or `x5u` over plain HTTP (CRITICAL) or pointing at external keys (WARN); an `x5c` certificate chain that a verifier must validate against a pinned root (WARN); HMAC combined with key-bearing headers, the HS/RS confusion shape (CRITICAL, CVE-2016-10555). |
171
172
  | Header parameters | `kid` containing path traversal, SQL, or command injection sequences; non-string `kid`; `crit` that is malformed or lists missing parameters; non-boolean `b64`; unexpected `typ`. |
172
173
  | Lifetime | Missing `exp`; expired tokens; `nbf` in the future; `iat` in the future or implausible; very long lifetimes; non-numeric time claims. |
173
- | Claims | Missing `iss`, `aud`, `iat`, or `jti` (INFO), and any claim named in `--require` (WARN). |
174
+ | Claims | Missing `iss`, `aud`, `iat`, or `jti` (INFO), and any claim named in `--require` (WARN); `iss` or `sub` that is not a string, and `aud` that is not a string or list of strings (WARN). |
175
+ | Key material | With `--secret`: a secret in the bundled common-secrets list (CRITICAL) or shorter than the hash output, which RFC 7518 3.2 requires (WARN). With `--public-key`: an RSA key under 2048 bits (CRITICAL, NIST SP 800-131A). Findings never include the secret. |
174
176
  | Payload contents | Sensitive field names such as `password` or `secret`; email addresses; Luhn-valid card numbers anywhere in nested data. |
175
177
 
176
178
  **Grades**: any CRITICAL finding gives **F**, three or more WARN give **C**, one or two WARN give **B**, otherwise **A**.
@@ -179,7 +181,7 @@ jwt-toolkit audit <token> --strict --require iss,aud --json
179
181
 
180
182
  ### verify
181
183
 
182
- Checks the signature, then the registered claims. The algorithm must match the key you supply, so an RS256 public key never verifies an HS256 token, and `alg: none` is always rejected.
184
+ Checks the signature, then the registered claims. The key you supply decides the algorithm family, so an RS256 public key never verifies an HS256 token, and `alg: none` is always rejected. A token whose `alg` is `none`, unknown, or from the other family fails the signature check as an invalid token.
183
185
 
184
186
  ```bash
185
187
  jwt-toolkit verify <token> --secret-file hs256.secret --issuer auth.example.com --audience api
@@ -192,14 +194,14 @@ jwt-toolkit verify <token> --jwks-url https://auth.example.com/.well-known/jwks.
192
194
  | --- | --- |
193
195
  | `--secret`, `--secret-file` | HMAC secret for `HS*` tokens. |
194
196
  | `--public-key FILE` | PEM public key or X.509 certificate for `RS*`, `PS*`, `ES*`, and `Ed*` tokens. |
195
- | `--jwks-url URL` | JWKS endpoint (`https://`, `http://`, or `file://`). The token's `kid` selects the key, and its `kty`, `crv`, and `alg` must match the token. |
197
+ | `--jwks-url URL` | JWKS endpoint (`https://`, `http://`, or `file://`). The token's `kid` selects the key, and its `kty`, `crv`, and `alg` must match the token. A key marked `use: enc`, or whose `key_ops` lacks `verify`, is refused. An `http://` URL adds a WARN check, since the key could be swapped in transit. |
196
198
  | `--issuer`, `--audience` | Expected `iss` and `aud`. `aud` may be a string or a list. |
197
199
  | `--leeway SECONDS` | Clock-skew tolerance for `exp` and `nbf`. |
198
200
  | `--json` | Print `{schema_version, valid, checks[]}`. |
199
201
 
200
- Checks performed: signature; `crit` (rejected, since no extensions are supported); `exp` (a token is expired at its `exp` second); `nbf`; `iat` not in the future; and `iss`/`aud` when requested. Time claims must be finite numbers.
202
+ Checks performed: signature; `crit` (rejected, since no extensions are supported); `exp` (a token is expired at its `exp` second); `nbf`; `iat` not in the future; and `iss`/`aud` when requested. Time claims must be finite numbers. A missing `iss` or `aud` fails the check by name.
201
203
 
202
- **Exit codes**: `0` valid, `1` invalid, `2` unusable input, key, or options.
204
+ **Exit codes**: `0` valid, `1` invalid (including `alg: none` and algorithm-confusion tokens), `2` unusable input, key, or options, such as no key or two keys.
203
205
 
204
206
  ### diff
205
207
 
@@ -245,8 +247,8 @@ Mints a token for tests and fixtures. The header always declares the algorithm t
245
247
 
246
248
  ```bash
247
249
  jwt-toolkit sign --payload '{"sub":"1"}' --secret-file hs256.secret
248
- jwt-toolkit sign --payload-file fixture.json --private-key private.pem --alg RS256 --expires-in 15m
249
- echo '{"sub":"1"}' | jwt-toolkit sign --payload-file - --private-key ed25519.pem --alg Ed25519
250
+ jwt-toolkit sign --payload-file fixture.json --private-key private.pem --expires-in 15m
251
+ echo '{"sub":"1"}' | jwt-toolkit sign --payload-file - --private-key rsa.pem --alg PS256
250
252
  ```
251
253
 
252
254
  | Option | Description |
@@ -256,7 +258,7 @@ echo '{"sub":"1"}' | jwt-toolkit sign --payload-file - --private-key ed25519.pem
256
258
  | `--secret`, `--secret-file` | HMAC secret for `HS*`. |
257
259
  | `--private-key FILE` | PEM private key (PKCS#8 or traditional) for `RS*`, `PS*`, `ES*`, and `Ed*`. |
258
260
  | `--passphrase-file FILE` | Passphrase for an encrypted private key. Without it, you are prompted on a terminal; non-interactive runs fail instead of hanging. |
259
- | `--alg ALG` | Signing algorithm, `HS256` by default. |
261
+ | `--alg ALG` | Signing algorithm. Defaults to `HS256` with a secret. With `--private-key` and no `--alg`, it follows the key: `RS256` for RSA, `ES256`/`ES384`/`ES512` by curve, and `Ed25519` or `Ed448`. |
260
262
  | `--header JSON` | Replace the default `{"alg": ..., "typ": "JWT"}` header. |
261
263
 
262
264
  The token is printed on its own line, so `$(jwt-toolkit sign ...)` captures it cleanly.
@@ -291,6 +293,7 @@ Tries every line of a wordlist as the HMAC secret. Use it on your own tokens to
291
293
  jwt-toolkit crack <token> # bundled common-secrets list
292
294
  jwt-toolkit crack <token> rockyou.txt --workers 8
293
295
  jwt-toolkit crack <token> keys.txt --encoding all --output found.txt
296
+ jwt-toolkit crack <token> --json # for CI
294
297
  ```
295
298
 
296
299
  ```
@@ -301,9 +304,9 @@ jwt-toolkit crack <token> keys.txt --encoding all --output found.txt
301
304
  │ Position : #107 of ~313 candidates │
302
305
  │ Candidates tried : 107 │
303
306
  │ Time elapsed : 0.001s │
304
- │ Average rate : 107.7k c/s │
307
+ │ Average rate : 128.8k c/s │
305
308
  │ │
306
- │ This secret is in a common wordlist — it is not safe. │
309
+ │ This secret is in the wordlist, so it is not safe. │
307
310
  │ Generate a strong secret with: jwt-toolkit generate-secret │
308
311
  ╰──────────────────────────────────────────────────────────────────────────────╯
309
312
  ```
@@ -313,7 +316,8 @@ jwt-toolkit crack <token> keys.txt --encoding all --output found.txt
313
316
  | `WORDLIST` | Path to a wordlist. Without it, the curated list bundled with the package is used. |
314
317
  | `--workers N` | Worker processes, 1 to 64, default 4. Lists under 50,000 candidates run in one process. `--threads` is accepted as an alias. |
315
318
  | `--encoding` | Treat each line as `utf-8` text, `hex`, `base64`, or try `all` three. |
316
- | `--output FILE` | Write a found secret to a file. |
319
+ | `--output FILE` | Write a found secret to a file, exactly as the wordlist line holds it. The file is readable by its owner only (mode 0600). |
320
+ | `--json` | Print `{schema_version, found, algorithm, wordlist, encoding, candidates_tried, elapsed_seconds}`; a match adds `secret`, `secret_encoding`, `position`, and `saved_to`. |
317
321
 
318
322
  Wordlists are streamed, so multi-gigabyte lists are fine. Each line is tried exactly as written: only the line ending and a leading byte-order mark are removed, so secrets with spaces or a leading `#` are found.
319
323
 
@@ -343,7 +347,7 @@ Saves the curated wordlist as a file, for use with other tools or as a starting
343
347
  jwt-toolkit download-wordlists --output-dir wordlists
344
348
  ```
345
349
 
346
- The file is fetched over verified TLS from this release's git tag and checked against a pinned SHA-256 before it is kept. `--source URL` downloads from somewhere else without the hash check, and `--force` overwrites an existing file.
350
+ The file is fetched over verified TLS from this release's git tag and checked against a pinned SHA-256 before it is kept. It is downloaded to a temporary file first, so a failed or tampered download never replaces an existing copy. `--source URL` (`https://`, `http://`, or `file://`) downloads from somewhere else without the hash check, and `--force` overwrites an existing file.
347
351
 
348
352
  ## Passing tokens, keys, and secrets
349
353
 
@@ -355,13 +359,13 @@ The file is fetched over verified TLS from this release's git tag and checked ag
355
359
  | `@path/to/token.jwt` | Read the token from a file. |
356
360
  | `-` | Read the token from stdin. |
357
361
 
358
- Surrounding whitespace and line breaks are ignored.
362
+ Surrounding whitespace and line breaks are ignored, and a leading `Bearer ` is dropped, so a value copied from an `Authorization` header works as-is.
359
363
 
360
364
  **HMAC secrets.** `--secret VALUE` is convenient but ends up in shell history and is visible to other users in process listings. Prefer `--secret-file FILE`: the file is read as UTF-8 text, and only a byte-order mark and one trailing newline are removed, so the output of `generate-secret --raw` works unchanged.
361
365
 
362
366
  **Asymmetric keys.** Private keys are PEM files in PKCS#8 or traditional format. Encrypted keys are supported through `--passphrase-file` or an interactive prompt. Public keys may be PEM `SubjectPublicKeyInfo` keys or X.509 certificates.
363
367
 
364
- **JWKS.** `verify --jwks-url` fetches a key set over HTTPS (or reads a `file://` path), selects the key by the token's `kid`, and requires the key type, curve, and any `alg` on the key to match the token.
368
+ **JWKS.** `verify --jwks-url` fetches a key set over HTTPS (or reads a `file://` path), selects the key by the token's `kid`, and requires the key type, curve, and any `alg` on the key to match the token. Responses over 1 MiB and redirects from `https` to `http` are refused.
365
369
 
366
370
  ## Supported algorithms
367
371
 
@@ -385,11 +389,13 @@ jwt-toolkit --quiet --no-color audit "$TOKEN" --json
385
389
 
386
390
  | Option | Environment variable | Effect |
387
391
  | --- | --- | --- |
388
- | `--quiet` | `JWT_TOOLKIT_QUIET=1` | Suppress the banner and non-essential output. |
392
+ | `--quiet` | `JWT_TOOLKIT_QUIET=1` | Drop the banner, progress, and hints. Results and errors are always printed. |
389
393
  | `--no-color` | `NO_COLOR=1` | Disable colors. |
390
394
  | `--no-banner` | `JWT_TOOLKIT_NO_BANNER=1` | Suppress the banner shown by a bare `jwt-toolkit`. |
391
395
 
392
- **JSON output.** `decode`, `audit`, `verify`, `diff`, and `forge` accept `--json`. Every document carries `"schema_version": "0.1"`; a field will not be renamed or removed without a new schema version. Errors use the same envelope with a stable code:
396
+ **Output streams.** Results go to stdout; errors, progress, and hints go to stderr, so `jwt-toolkit sign ... > token.jwt` captures only the token. Under `--json`, error documents are printed to stdout like any other result.
397
+
398
+ **JSON output.** `decode`, `audit`, `verify`, `diff`, `forge`, and `crack` accept `--json`. Every document carries `"schema_version": "0.1"`; a field will not be renamed or removed without a new schema version. Errors use the same envelope with a stable code:
393
399
 
394
400
  ```json
395
401
  {
@@ -400,7 +406,7 @@ jwt-toolkit --quiet --no-color audit "$TOKEN" --json
400
406
  }
401
407
  ```
402
408
 
403
- Error codes include `invalid_structure`, `invalid_base64url`, `invalid_json`, `invalid_json_object`, `invalid_number`, `token_unreadable`, `unsupported_algorithm`, `invalid_key_options`, `key_error`, and `stdin_conflict`.
409
+ Error codes include `invalid_structure`, `invalid_base64url`, `invalid_json`, `invalid_json_object`, `invalid_number`, `token_unreadable`, `unsupported_algorithm`, `invalid_key_options`, `key_error`, `stdin_conflict`, `signature_missing`, `wordlist_missing`, `wordlist_unreadable`, and `wordlist_empty`.
404
410
 
405
411
  **Exit codes.** `0` means the check passed, `1` means it found a problem, and `2` means the input could not be used. The exceptions are [`crack`](#crack), which exits `1` when it finds the secret, and [`diff`](#diff), which only exits `1` with `--exit-code`.
406
412
 
@@ -0,0 +1,93 @@
1
+ import os
2
+
3
+ import click
4
+
5
+ from jwt_toolkit import __version__
6
+ from jwt_toolkit.cli.banner import COMMANDS, EXAMPLES, render_banner, render_help
7
+ from jwt_toolkit.commands.audit import audit
8
+ from jwt_toolkit.commands.crack import crack
9
+ from jwt_toolkit.commands.decode import decode
10
+ from jwt_toolkit.commands.diff import diff
11
+ from jwt_toolkit.commands.download_wordlists import download_wordlists
12
+ from jwt_toolkit.commands.forge import forge
13
+ from jwt_toolkit.commands.generate_secret import generate_secret
14
+ from jwt_toolkit.commands.sign import sign
15
+ from jwt_toolkit.commands.verify import verify
16
+
17
+ CLI_HELP = (
18
+ "JWT Toolkit: a command-line toolkit for inspecting, verifying, cracking, "
19
+ "and securing JSON Web Tokens.\n\n"
20
+ "Built to expose how JWT signing works and where it breaks. Use it to audit tokens "
21
+ "for misconfigurations, verify signatures and standard claims, brute-force weak HMAC "
22
+ "secrets against a wordlist, and generate cryptographically strong secrets.\n\n"
23
+ "\b\nCommands:\n"
24
+ + "\n".join(f" {name:<20}{summary}" for name, summary in COMMANDS)
25
+ + "\n\n\b\nExamples:\n"
26
+ + "\n".join(f" {command}" for _, command in EXAMPLES)
27
+ + "\n\nRun `jwt-toolkit COMMAND --help` for command-specific options.\n"
28
+ )
29
+
30
+
31
+ class _ToolkitGroup(click.Group):
32
+ # CLI_HELP already lists every command with its full summary; Click's own
33
+ # list would repeat it with truncated text.
34
+ def format_commands(self, ctx: click.Context, formatter: click.HelpFormatter) -> None:
35
+ pass
36
+
37
+
38
+ @click.group(
39
+ cls=_ToolkitGroup,
40
+ invoke_without_command=True,
41
+ context_settings={"help_option_names": ["-h", "--help"]},
42
+ help=CLI_HELP,
43
+ )
44
+ @click.version_option(
45
+ version=__version__,
46
+ prog_name="jwt-toolkit",
47
+ message="%(prog)s %(version)s",
48
+ )
49
+ @click.option(
50
+ "--no-banner",
51
+ is_flag=True,
52
+ envvar="JWT_TOOLKIT_NO_BANNER",
53
+ help="Suppress the startup banner (also: JWT_TOOLKIT_NO_BANNER=1).",
54
+ )
55
+ @click.option(
56
+ "--quiet",
57
+ is_flag=True,
58
+ envvar="JWT_TOOLKIT_QUIET",
59
+ help="Keep results and errors, drop the banner, progress, and hints (also: JWT_TOOLKIT_QUIET=1).",
60
+ )
61
+ @click.option(
62
+ "--no-color",
63
+ is_flag=True,
64
+ envvar="NO_COLOR",
65
+ help="Disable color output (also: NO_COLOR=1).",
66
+ )
67
+ @click.pass_context
68
+ def cli(ctx: click.Context, no_banner: bool, quiet: bool, no_color: bool) -> None:
69
+ # The lazy consoles read these at print time. They are removed again when the
70
+ # command finishes so in-process callers do not inherit them.
71
+ for name, enabled in (("NO_COLOR", no_color), ("JWT_TOOLKIT_QUIET", quiet)):
72
+ if enabled and name not in os.environ:
73
+ os.environ[name] = "1"
74
+ ctx.call_on_close(lambda name=name: os.environ.pop(name, None))
75
+
76
+ # The banner is only rendered for the bare `jwt-toolkit` invocation.
77
+ # Printing it for every subcommand would corrupt --json output and noisily
78
+ # prefix Click's usage errors, so it stays out of the subcommand path.
79
+ if ctx.invoked_subcommand is None:
80
+ if not (no_banner or quiet):
81
+ render_banner()
82
+ render_help()
83
+
84
+
85
+ cli.add_command(decode)
86
+ cli.add_command(sign)
87
+ cli.add_command(audit)
88
+ cli.add_command(generate_secret)
89
+ cli.add_command(verify)
90
+ cli.add_command(diff)
91
+ cli.add_command(forge)
92
+ cli.add_command(crack)
93
+ cli.add_command(download_wordlists)