Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Validate sub and jti claims for the token #1005

Merged
merged 2 commits into from
Oct 13, 2024

Conversation

Divan009
Copy link
Contributor

@Divan009 Divan009 commented Oct 10, 2024

Closes #959

  • Added validation logic for both the 'sub' (subject) and 'jti' (JWT ID) claims.
  • Introduced _validate_sub and _validate_jti methods for verifying these claims.
  • Updated the decode_complete function to include options for verifying the 'sub' and 'jti' claims.
  • Update the positional arguments in decode and decode_complete function, to accept subject
  • Changelog updated
  • TestCases Added

@Divan009
Copy link
Contributor Author

Hi @jpadilla

Apologies for the inconvenience, but I had to create a new PR with the same commits after accidentally deleting my fork, which removed the original PR.

Thanks for your understanding! :)

@jpadilla
Copy link
Owner

great, thanks!

@jpadilla jpadilla merged commit 6dc23b3 into jpadilla:master Oct 13, 2024
24 of 27 checks passed
github-actions bot pushed a commit to bo4e/BO4E-CLI that referenced this pull request Nov 18, 2024
Bumps [pyjwt[crypto]](https://github.com/jpadilla/pyjwt) from 2.9.0 to
2.10.0.
<details>
<summary>Release notes</summary>
<p><em>Sourced from <a
href="https://github.com/jpadilla/pyjwt/releases">pyjwt[crypto]'s
releases</a>.</em></p>
<blockquote>
<h2>2.10.0</h2>
<h2>What's Changed</h2>
<ul>
<li>chore: use sequence for typing rather than list by <a
href="https://github.com/imnotjames"><code>@​imnotjames</code></a> in <a
href="https://redirect.github.com/jpadilla/pyjwt/pull/970">jpadilla/pyjwt#970</a></li>
<li>Add support for Python 3.13 by <a
href="https://github.com/hugovk"><code>@​hugovk</code></a> in <a
href="https://redirect.github.com/jpadilla/pyjwt/pull/972">jpadilla/pyjwt#972</a></li>
<li>[pre-commit.ci] pre-commit autoupdate by <a
href="https://github.com/pre-commit-ci"><code>@​pre-commit-ci</code></a>
in <a
href="https://redirect.github.com/jpadilla/pyjwt/pull/971">jpadilla/pyjwt#971</a></li>
<li>Add an RTD config file to resolve RTD build failures by <a
href="https://github.com/kurtmckee"><code>@​kurtmckee</code></a> in <a
href="https://redirect.github.com/jpadilla/pyjwt/pull/977">jpadilla/pyjwt#977</a></li>
<li>docs: Update <code>iat</code> exception docs by <a
href="https://github.com/pachewise"><code>@​pachewise</code></a> in <a
href="https://redirect.github.com/jpadilla/pyjwt/pull/974">jpadilla/pyjwt#974</a></li>
<li>Remove algorithm requirement for JWT API by <a
href="https://github.com/luhn"><code>@​luhn</code></a> in <a
href="https://redirect.github.com/jpadilla/pyjwt/pull/975">jpadilla/pyjwt#975</a></li>
<li>[pre-commit.ci] pre-commit autoupdate by <a
href="https://github.com/pre-commit-ci"><code>@​pre-commit-ci</code></a>
in <a
href="https://redirect.github.com/jpadilla/pyjwt/pull/978">jpadilla/pyjwt#978</a></li>
<li>Create SECURITY.md by <a
href="https://github.com/auvipy"><code>@​auvipy</code></a> in <a
href="https://redirect.github.com/jpadilla/pyjwt/pull/973">jpadilla/pyjwt#973</a></li>
<li>docs fix: decode_complete scope and algorithms by <a
href="https://github.com/RbnRncn"><code>@​RbnRncn</code></a> in <a
href="https://redirect.github.com/jpadilla/pyjwt/pull/982">jpadilla/pyjwt#982</a></li>
<li>fix doctest for docs/usage.rst by <a
href="https://github.com/pachewise"><code>@​pachewise</code></a> in <a
href="https://redirect.github.com/jpadilla/pyjwt/pull/986">jpadilla/pyjwt#986</a></li>
<li>fix test_utils.py not to xfail by <a
href="https://github.com/pachewise"><code>@​pachewise</code></a> in <a
href="https://redirect.github.com/jpadilla/pyjwt/pull/987">jpadilla/pyjwt#987</a></li>
<li>Correct jwt.decode audience param doc expression by <a
href="https://github.com/peter279k"><code>@​peter279k</code></a> in <a
href="https://redirect.github.com/jpadilla/pyjwt/pull/994">jpadilla/pyjwt#994</a></li>
<li>Add PS256 encoding and decoding usage by <a
href="https://github.com/peter279k"><code>@​peter279k</code></a> in <a
href="https://redirect.github.com/jpadilla/pyjwt/pull/992">jpadilla/pyjwt#992</a></li>
<li>Add API docs for PyJWK by <a
href="https://github.com/luhn"><code>@​luhn</code></a> in <a
href="https://redirect.github.com/jpadilla/pyjwt/pull/980">jpadilla/pyjwt#980</a></li>
<li>Refactor project configuration files from setup.cfg to
pyproject.toml PEP-518 by <a
href="https://github.com/cleder"><code>@​cleder</code></a> in <a
href="https://redirect.github.com/jpadilla/pyjwt/pull/995">jpadilla/pyjwt#995</a></li>
<li>Add JWK support to JWT encode by <a
href="https://github.com/luhn"><code>@​luhn</code></a> in <a
href="https://redirect.github.com/jpadilla/pyjwt/pull/979">jpadilla/pyjwt#979</a></li>
<li>Update pre-commit hooks to lint pyproject.toml by <a
href="https://github.com/cleder"><code>@​cleder</code></a> in <a
href="https://redirect.github.com/jpadilla/pyjwt/pull/1002">jpadilla/pyjwt#1002</a></li>
<li>Add EdDSA algorithm encoding/decoding usage by <a
href="https://github.com/peter279k"><code>@​peter279k</code></a> in <a
href="https://redirect.github.com/jpadilla/pyjwt/pull/993">jpadilla/pyjwt#993</a></li>
<li>Ruff linter and formatter changes by <a
href="https://github.com/gagandeepp"><code>@​gagandeepp</code></a> in <a
href="https://redirect.github.com/jpadilla/pyjwt/pull/1001">jpadilla/pyjwt#1001</a></li>
<li>Validate <code>sub</code> and <code>jti</code> claims for the token
by <a href="https://github.com/Divan009"><code>@​Divan009</code></a> in
<a
href="https://redirect.github.com/jpadilla/pyjwt/pull/1005">jpadilla/pyjwt#1005</a></li>
<li>Add ES256 usage by <a
href="https://github.com/Gautam-Hegde"><code>@​Gautam-Hegde</code></a>
in <a
href="https://redirect.github.com/jpadilla/pyjwt/pull/1003">jpadilla/pyjwt#1003</a></li>
<li>Encode EC keys with a fixed bit length by <a
href="https://github.com/way-dave"><code>@​way-dave</code></a> in <a
href="https://redirect.github.com/jpadilla/pyjwt/pull/990">jpadilla/pyjwt#990</a></li>
<li>[pre-commit.ci] pre-commit autoupdate by <a
href="https://github.com/pre-commit-ci"><code>@​pre-commit-ci</code></a>
in <a
href="https://redirect.github.com/jpadilla/pyjwt/pull/1000">jpadilla/pyjwt#1000</a></li>
<li>Drop support for Python 3.8 by <a
href="https://github.com/kkirsche"><code>@​kkirsche</code></a> in <a
href="https://redirect.github.com/jpadilla/pyjwt/pull/1007">jpadilla/pyjwt#1007</a></li>
<li>Prepare 2.10.0 release by <a
href="https://github.com/benvdh"><code>@​benvdh</code></a> in <a
href="https://redirect.github.com/jpadilla/pyjwt/pull/1011">jpadilla/pyjwt#1011</a></li>
<li>Bump codecov/codecov-action from 4 to 5 by <a
href="https://github.com/dependabot"><code>@​dependabot</code></a> in <a
href="https://redirect.github.com/jpadilla/pyjwt/pull/1014">jpadilla/pyjwt#1014</a></li>
<li>[pre-commit.ci] pre-commit autoupdate by <a
href="https://github.com/pre-commit-ci"><code>@​pre-commit-ci</code></a>
in <a
href="https://redirect.github.com/jpadilla/pyjwt/pull/1006">jpadilla/pyjwt#1006</a></li>
</ul>
<h2>New Contributors</h2>
<ul>
<li><a
href="https://github.com/imnotjames"><code>@​imnotjames</code></a> made
their first contribution in <a
href="https://redirect.github.com/jpadilla/pyjwt/pull/970">jpadilla/pyjwt#970</a></li>
<li><a href="https://github.com/kurtmckee"><code>@​kurtmckee</code></a>
made their first contribution in <a
href="https://redirect.github.com/jpadilla/pyjwt/pull/977">jpadilla/pyjwt#977</a></li>
<li><a href="https://github.com/pachewise"><code>@​pachewise</code></a>
made their first contribution in <a
href="https://redirect.github.com/jpadilla/pyjwt/pull/974">jpadilla/pyjwt#974</a></li>
<li><a href="https://github.com/RbnRncn"><code>@​RbnRncn</code></a> made
their first contribution in <a
href="https://redirect.github.com/jpadilla/pyjwt/pull/982">jpadilla/pyjwt#982</a></li>
<li><a href="https://github.com/peter279k"><code>@​peter279k</code></a>
made their first contribution in <a
href="https://redirect.github.com/jpadilla/pyjwt/pull/994">jpadilla/pyjwt#994</a></li>
<li><a href="https://github.com/cleder"><code>@​cleder</code></a> made
their first contribution in <a
href="https://redirect.github.com/jpadilla/pyjwt/pull/995">jpadilla/pyjwt#995</a></li>
<li><a
href="https://github.com/gagandeepp"><code>@​gagandeepp</code></a> made
their first contribution in <a
href="https://redirect.github.com/jpadilla/pyjwt/pull/1001">jpadilla/pyjwt#1001</a></li>
<li><a href="https://github.com/Divan009"><code>@​Divan009</code></a>
made their first contribution in <a
href="https://redirect.github.com/jpadilla/pyjwt/pull/1005">jpadilla/pyjwt#1005</a></li>
<li><a
href="https://github.com/Gautam-Hegde"><code>@​Gautam-Hegde</code></a>
made their first contribution in <a
href="https://redirect.github.com/jpadilla/pyjwt/pull/1003">jpadilla/pyjwt#1003</a></li>
<li><a href="https://github.com/way-dave"><code>@​way-dave</code></a>
made their first contribution in <a
href="https://redirect.github.com/jpadilla/pyjwt/pull/990">jpadilla/pyjwt#990</a></li>
</ul>
<p><strong>Full Changelog</strong>: <a
href="https://github.com/jpadilla/pyjwt/compare/2.9.0...2.10.0">https://github.com/jpadilla/pyjwt/compare/2.9.0...2.10.0</a></p>
</blockquote>
</details>
<details>
<summary>Changelog</summary>
<p><em>Sourced from <a
href="https://github.com/jpadilla/pyjwt/blob/master/CHANGELOG.rst">pyjwt[crypto]'s
changelog</a>.</em></p>
<blockquote>
<h2><code>v2.10.0
&lt;https://github.com/jpadilla/pyjwt/compare/2.9.0...2.10.0&gt;</code>__</h2>
<p>Changed</p>
<pre><code>
- Remove algorithm requirement from JWT API, instead relying on JWS API
for enforcement, by @luhn in
`[#975](jpadilla/pyjwt#975)
&lt;https://github.com/jpadilla/pyjwt/pull/975&gt;`__
- Use ``Sequence`` for parameter types rather than ``List`` where
applicable by @imnotjames in
`[#970](jpadilla/pyjwt#970)
&lt;https://github.com/jpadilla/pyjwt/pull/970&gt;`__
- Add JWK support to JWT encode by @luhn in
`[#979](jpadilla/pyjwt#979)
&lt;https://github.com/jpadilla/pyjwt/pull/979&gt;`__
- Encoding and decoding payloads using the `none` algorithm by @jpadilla
in `#c2629f6
&lt;https://github.com/jpadilla/pyjwt/commit/c2629f66c593459e02616048443231ccbe18be16&gt;`
<p>Before:</p>
<p>.. code-block:: pycon</p>
<p>&gt;&gt;&gt; import jwt
&gt;&gt;&gt; jwt.encode({&quot;payload&quot;: &quot;abc&quot;},
key=None, algorithm=None)</p>
<p>After:</p>
<p>.. code-block:: pycon</p>
<p>&gt;&gt;&gt; import jwt
&gt;&gt;&gt; jwt.encode({&quot;payload&quot;: &quot;abc&quot;},
key=None, algorithm=&quot;none&quot;)</p>
<ul>
<li>Added validation for 'sub' (subject) and 'jti' (JWT ID) claims in
tokens by <a
href="https://github.com/Divan009"><code>@​Divan009</code></a> in
<code>[#1005](jpadilla/pyjwt#1005)
&amp;lt;https://github.com/jpadilla/pyjwt/pull/1005&amp;gt;</code>__</li>
<li>Refactor project configuration files from <code>setup.cfg</code> to
<code>pyproject.toml</code> by <a
href="https://github.com/cleder"><code>@​cleder</code></a> in
<code>[#995](jpadilla/pyjwt#995)
&amp;lt;https://github.com/jpadilla/pyjwt/pull/995&amp;gt;</code>__</li>
<li>Ruff linter and formatter changes by <a
href="https://github.com/gagandeepp"><code>@​gagandeepp</code></a> in
<code>[#1001](jpadilla/pyjwt#1001)
&amp;lt;https://github.com/jpadilla/pyjwt/pull/1001&amp;gt;</code>__</li>
<li>Drop support for Python 3.8 (EOL) by <a
href="https://github.com/kkirsche"><code>@​kkirsche</code></a> in
<code>[#1007](jpadilla/pyjwt#1007)
&amp;lt;https://github.com/jpadilla/pyjwt/pull/1007&amp;gt;</code>__</li>
</ul>
<p>Fixed</p>
<pre><code>
- Encode EC keys with a fixed bit length by @etianen in
`[#990](jpadilla/pyjwt#990)
&amp;lt;https://github.com/jpadilla/pyjwt/pull/990&amp;gt;`__
- Add an RTD config file to resolve Read the Docs build failures by
@kurtmckee in `[#977](jpadilla/pyjwt#977)
&amp;lt;https://github.com/jpadilla/pyjwt/pull/977&amp;gt;`__
- Docs: Update ``iat`` exception docs by @pachewise in
`[#974](jpadilla/pyjwt#974)
&amp;lt;https://github.com/jpadilla/pyjwt/pull/974&amp;gt;`__
- Docs: Fix ``decode_complete`` scope and algorithms by @RbnRncn in
`[#982](jpadilla/pyjwt#982)
&amp;lt;https://github.com/jpadilla/pyjwt/pull/982&amp;gt;`__
- Fix doctest for ``docs/usage.rst`` by @pachewise in
`[#986](jpadilla/pyjwt#986)
&amp;lt;https://github.com/jpadilla/pyjwt/pull/986&amp;gt;`__
- Fix ``test_utils.py`` not to xfail by @pachewise in
`[#987](jpadilla/pyjwt#987)
&amp;lt;https://github.com/jpadilla/pyjwt/pull/987&amp;gt;`__
- Docs: Correct `jwt.decode` audience param doc expression by @peter279k
in `[#994](jpadilla/pyjwt#994)
&amp;lt;https://github.com/jpadilla/pyjwt/pull/994&amp;gt;`__

Added
</code></pre>
<ul>
<li>Add support for python 3.13 by <a
href="https://github.com/hugovk"><code>@​hugovk</code></a> in
<code>[#972](jpadilla/pyjwt#972)
&amp;lt;https://github.com/jpadilla/pyjwt/pull/972&amp;gt;</code>__</li>
<li>Create SECURITY.md by <a
href="https://github.com/auvipy"><code>@​auvipy</code></a> and <a
href="https://github.com/jpadilla"><code>@​jpadilla</code></a> in
<code>[#973](jpadilla/pyjwt#973)
&amp;lt;https://github.com/jpadilla/pyjwt/pull/973&amp;gt;</code>__</li>
<li>Docs: Add PS256 encoding and decoding usage by <a
href="https://github.com/peter279k"><code>@​peter279k</code></a> in
<code>[#992](jpadilla/pyjwt#992)
&amp;lt;https://github.com/jpadilla/pyjwt/pull/992&amp;gt;</code>__
&lt;/tr&gt;&lt;/table&gt;
</code></pre></li>
</ul>
</blockquote>
<p>... (truncated)</p>
</details>
<details>
<summary>Commits</summary>
<ul>
<li><a
href="https://github.com/jpadilla/pyjwt/commit/783f324e5d2155462515ced45718fc164dd04db2"><code>783f324</code></a>
[pre-commit.ci] pre-commit autoupdate (<a
href="https://redirect.github.com/jpadilla/pyjwt/issues/1006">#1006</a>)</li>
<li><a
href="https://github.com/jpadilla/pyjwt/commit/0116fc6cb2b5088b02efa4506ecb6dcea42d72b3"><code>0116fc6</code></a>
Bump codecov/codecov-action from 4 to 5 (<a
href="https://redirect.github.com/jpadilla/pyjwt/issues/1014">#1014</a>)</li>
<li><a
href="https://github.com/jpadilla/pyjwt/commit/b032353bd93fee330cb79a351cc4d03affee19f5"><code>b032353</code></a>
feat: surface <code>jwt.decode_complete(...)</code></li>
<li><a
href="https://github.com/jpadilla/pyjwt/commit/a759c455cde3e9ff99afe25e9fc56278af666ff3"><code>a759c45</code></a>
Prepare 2.10.0 release (<a
href="https://redirect.github.com/jpadilla/pyjwt/issues/1011">#1011</a>)</li>
<li><a
href="https://github.com/jpadilla/pyjwt/commit/b6b8bce07717b0b4bb7816b99c33ab9e6907059a"><code>b6b8bce</code></a>
Drop support for Python 3.8 (<a
href="https://redirect.github.com/jpadilla/pyjwt/issues/1007">#1007</a>)</li>
<li><a
href="https://github.com/jpadilla/pyjwt/commit/189c2561c47030d2e34aea040cf135ae4997a2d8"><code>189c256</code></a>
Update index.rst</li>
<li><a
href="https://github.com/jpadilla/pyjwt/commit/19008577fbda9cbce879defa2c7cd6387f8ca66f"><code>1900857</code></a>
Update index.rst</li>
<li><a
href="https://github.com/jpadilla/pyjwt/commit/8fe9eab822cf7d9ea1e424379d64e29abfe33f34"><code>8fe9eab</code></a>
Update README.rst</li>
<li><a
href="https://github.com/jpadilla/pyjwt/commit/6f73f6f75c6fa9b35302d7d71b8015fcfc5d5802"><code>6f73f6f</code></a>
[pre-commit.ci] pre-commit autoupdate (<a
href="https://redirect.github.com/jpadilla/pyjwt/issues/1000">#1000</a>)</li>
<li><a
href="https://github.com/jpadilla/pyjwt/commit/c2629f66c593459e02616048443231ccbe18be16"><code>c2629f6</code></a>
update changelog</li>
<li>Additional commits viewable in <a
href="https://github.com/jpadilla/pyjwt/compare/2.9.0...2.10.0">compare
view</a></li>
</ul>
</details>
<br />


[![Dependabot compatibility
score](https://dependabot-badges.githubapp.com/badges/compatibility_score?dependency-name=pyjwt[crypto]&package-manager=pip&previous-version=2.9.0&new-version=2.10.0)](https://docs.github.com/en/github/managing-security-vulnerabilities/about-dependabot-security-updates#about-compatibility-scores)

Dependabot will resolve any conflicts with this PR as long as you don't
alter it yourself. You can also trigger a rebase manually by commenting
`@dependabot rebase`.

[//]: # (dependabot-automerge-start)
[//]: # (dependabot-automerge-end)

---

<details>
<summary>Dependabot commands and options</summary>
<br />

You can trigger Dependabot actions by commenting on this PR:
- `@dependabot rebase` will rebase this PR
- `@dependabot recreate` will recreate this PR, overwriting any edits
that have been made to it
- `@dependabot merge` will merge this PR after your CI passes on it
- `@dependabot squash and merge` will squash and merge this PR after
your CI passes on it
- `@dependabot cancel merge` will cancel a previously requested merge
and block automerging
- `@dependabot reopen` will reopen this PR if it is closed
- `@dependabot close` will close this PR and stop Dependabot recreating
it. You can achieve the same result by closing it manually
- `@dependabot show <dependency name> ignore conditions` will show all
of the ignore conditions of the specified dependency
- `@dependabot ignore this major version` will close this PR and stop
Dependabot creating any more for this major version (unless you reopen
the PR or upgrade to it yourself)
- `@dependabot ignore this minor version` will close this PR and stop
Dependabot creating any more for this minor version (unless you reopen
the PR or upgrade to it yourself)
- `@dependabot ignore this dependency` will close this PR and stop
Dependabot creating any more for this dependency (unless you reopen the
PR or upgrade to it yourself)


</details>

Signed-off-by: dependabot[bot] <[email protected]>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Implement sub and jti check
2 participants