-
Notifications
You must be signed in to change notification settings - Fork 2.9k
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
fix: handle URL-safe base64 decoding for JWT #38991
base: main
Are you sure you want to change the base?
Conversation
- Updated the JWT decoding logic to use URL-safe base64 decoding. - Added padding to the base64 encoded string to ensure proper decoding. - This fixes the issue where UTF-8 decoding errors occurred due to missing padding in the base64 string. Changes: - Replaced `base64.decodebytes` with `base64.urlsafe_b64decode`. - Added logic to calculate and append necessary padding to the base64 string.
Thank you for your contribution @baku2san! We will review the pull request and get back to you soon. |
API change check API changes are not detected in this pull request. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for the PR and improving the JWT payload decoding! Left a suggestion inline.
Do you mind also adding this change to the async decorator as well?
sdk/identity/azure-identity/azure/identity/_internal/decorators.py
Outdated
Show resolved
Hide resolved
@microsoft-github-policy-service agree |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for the updates. Seems like the black reformatting might be causing some conflicts. To be sure that we use the same black versioning/configuration that the CI uses, try running it via tox
(from inside the sdk/identity/azure-identity
directory):
pip install tox
tox run -e black -c ../../../eng/tox/tox.ini --root . -- azure
sdk/identity/azure-identity/azure/identity/_internal/decorators.py
Outdated
Show resolved
Hide resolved
sdk/identity/azure-identity/azure/identity/aio/_internal/decorators.py
Outdated
Show resolved
Hide resolved
…s.py Co-authored-by: Paul Van Eck <paulvaneck@microsoft.com>
…ators.py Co-authored-by: Paul Van Eck <paulvaneck@microsoft.com>
…ith the designated version
Thanks for the guidance on using tox for Black formatting. I've followed your instructions and reformatted the code accordingly. I have verified and confirmed that the expression padding_needed = -len(base64_meta_data) % 4 is correct for determining the necessary padding in Base64 encoding. The results clearly show that this method accurately calculates the required padding, ensuring the data length is a multiple of 4. Thank you for your assistance in clarifying this!
import pandas as pd
lengths = range(11) # This will create a range from 0 to 10
results = []
for length in lengths:
expr1 = -(length % 4)
expr2 = -length % 4
expr3 = 4 - (length % 4)
results.append((length, expr1, expr2, expr3))
df = pd.DataFrame(results, columns=["len(base64_meta_data)", "padding_needed = -(len(base64_meta_data) % 4)", "padding_needed = -len(base64_meta_data) % 4", "base"])
print(df) |
Description
This pull request addresses an issue with JWT decoding where URL-safe base64 decoding was not being used, leading to UTF-8 decoding errors. The changes ensure that the base64 encoded string is properly padded and decoded using URL-safe base64 decoding.
RFC4648
Changes:
base64.decodebytes
withbase64.urlsafe_b64decode
.All SDK Contribution checklist:
General Guidelines and Best Practices
Testing Guidelines