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

Allow strict base64 decoding #259

Merged
merged 1 commit into from
Dec 9, 2022

Conversation

AlexanderYastrebov
Copy link
Contributor

By default base64 decoder works in non-strict mode which allows tweaking signatures having padding without failing validation.

This creates a potential problem if application treats token value as an identifier.

For example ES256 signature has length of 64 bytes and two padding symbols (stripped by default). Therefore its base64-encoded value can only end with A, Q, g and w. In non-strict mode last symbol could be tweaked resulting in 16 distinct token values having the same signature and passing validation.

This change adds backward-compatible global config variable DecodeStrict (similar to existing DecodePaddingAllowed) that enables strict base64 decoder mode.

See also golang/go#15656.

Signed-off-by: Alexander Yastrebov [email protected]

By default base64 decoder works in non-strict mode which
allows tweaking signatures having padding without failing validation.

This creates a potential problem if application treats token value as an identifier.

For example ES256 signature has length of 64 bytes and two padding symbols (stripped by default).
Therefore its base64-encoded value can only end with A, Q, g and w.
In non-strict mode last symbol could be tweaked resulting in 16 distinct
token values having the same signature and passing validation.

This change adds backward-compatible global config variable DecodeStrict
(similar to existing DecodePaddingAllowed) that enables strict base64 decoder mode.

See also golang/go#15656.

Signed-off-by: Alexander Yastrebov <[email protected]>
@AlexanderYastrebov
Copy link
Contributor Author

I made it backward-compatible but IMO this could be true by default. Let me know what you think, I'll update the PR if needed.

@oxisto
Copy link
Collaborator

oxisto commented Dec 3, 2022

I made it backward-compatible but IMO this could be true by default. Let me know what you think, I'll update the PR if needed.

I would keep it as false by default for this version and we can think about making it true for v5.

@oxisto oxisto merged commit 9358574 into golang-jwt:main Dec 9, 2022
@AlexanderYastrebov AlexanderYastrebov deleted the strict-decode branch December 9, 2022 18:07
mend-for-github-com bot referenced this pull request in DelineaXPM/dsv-cli Feb 20, 2023
…v4.5.0 (#75)

This PR contains the following updates:

| Package | Type | Update | Change |
|---|---|---|---|
| [github.com/golang-jwt/jwt/v4](https://togithub.com/golang-jwt/jwt) |
require | minor | `v4.4.3` -> `v4.5.0` |

---

### Release Notes

<details>
<summary>golang-jwt/jwt</summary>

### [`v4.5.0`](https://togithub.com/golang-jwt/jwt/releases/tag/v4.5.0)

[Compare
Source](https://togithub.com/golang-jwt/jwt/compare/v4.4.3...v4.5.0)

#### What's Changed

- Allow strict base64 decoding by
[@&#8203;AlexanderYastrebov](https://togithub.com/AlexanderYastrebov) in
[https://github.com/golang-jwt/jwt/pull/259](https://togithub.com/golang-jwt/jwt/pull/259)

**Full Changelog**:
golang-jwt/jwt@v4.4.3...v4.5.0

</details>

---

### Configuration

📅 **Schedule**: Branch creation - "before 3am on Monday" (UTC),
Automerge - At any time (no schedule defined).

🚦 **Automerge**: Enabled.

♻ **Rebasing**: Whenever PR is behind base branch, or you tick the
rebase/retry checkbox.

🔕 **Ignore**: Close this PR and you won't be reminded about this update
again.

---

- [ ] <!-- rebase-check -->If you want to rebase/retry this PR, check
this box

<!--renovate-debug:eyJjcmVhdGVkSW5WZXIiOiIzNC4xMDAuMSIsInVwZGF0ZWRJblZlciI6IjM0LjEwMC4xIn0=-->

Co-authored-by: mend-for-github-com[bot] <50673670+mend-for-github-com[bot]@users.noreply.github.com>
oxisto pushed a commit to moneszarrugh/jwt that referenced this pull request Feb 21, 2023
By default base64 decoder works in non-strict mode which
allows tweaking signatures having padding without failing validation.

This creates a potential problem if application treats token value as an identifier.

For example ES256 signature has length of 64 bytes and two padding symbols (stripped by default).
Therefore its base64-encoded value can only end with A, Q, g and w.
In non-strict mode last symbol could be tweaked resulting in 16 distinct
token values having the same signature and passing validation.

This change adds backward-compatible global config variable DecodeStrict
(similar to existing DecodePaddingAllowed) that enables strict base64 decoder mode.

See also golang/go#15656.

Signed-off-by: Alexander Yastrebov <[email protected]>
oxisto pushed a commit to twocs/jwt that referenced this pull request Mar 29, 2023
By default base64 decoder works in non-strict mode which
allows tweaking signatures having padding without failing validation.

This creates a potential problem if application treats token value as an identifier.

For example ES256 signature has length of 64 bytes and two padding symbols (stripped by default).
Therefore its base64-encoded value can only end with A, Q, g and w.
In non-strict mode last symbol could be tweaked resulting in 16 distinct
token values having the same signature and passing validation.

This change adds backward-compatible global config variable DecodeStrict
(similar to existing DecodePaddingAllowed) that enables strict base64 decoder mode.

See also golang/go#15656.

Signed-off-by: Alexander Yastrebov <[email protected]>
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.

2 participants