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

ensure decode_password function properly handles plaintext but valid base64 passwords #5698

Merged
merged 2 commits into from
Jan 21, 2025

Conversation

adamsachs
Copy link
Contributor

@adamsachs adamsachs commented Jan 21, 2025

Closes HJ-397

Description Of Changes

Handles the UnicodeDecodeError that is raised by decode_password if it is given a plaintext password that's also valid base64. The exception is caught, and the input string is returned as it was provided, under the assumption that it is a plaintext (and not base64-encoded) password.

See issue description for more details. This impacts some user-related endpoints (e.g. reset password, accept invite) if the user provides a password that also happens to be valid base64. Notably, the utilities also ignore invalid base64 characters like _, so a value like e.g. Test_1234 is treated as valid base64, since the _ is ignored and its length of 8 is a multiple of 4.

Code Changes

  • catch and ignore UnicodeDecodeError in decode_password utility function, assuming input string is a plaintext password

Steps to Confirm

  • confirmed locally that I can (still) create a user and manually set their password to Test_1234 (i think this was working before, because we send a base64 encoded password in the request from the UI in this workflow)
  • confirmed i can now accept a user invite and set my password to Test_1234, which i also confirmed was broken before:
image

Pre-Merge Checklist

  • Issue requirements met
  • All CI pipelines succeeded
  • CHANGELOG.md updated
    • Add a db-migration This indicates that a change includes a database migration label to the entry if your change includes a DB migration
    • Add a high-risk This issue suggests changes that have a high-probability of breaking existing code label to the entry if your change includes a high-risk change (i.e. potential for performance impact or unexpected regression) that should be flagged
  • Followup issues:
    • Followup issues created (include link)
    • No followup issues
  • Database migrations:
    • Ensure that your downrev is up to date with the latest revision on main
    • Ensure that your downgrade() migration is correct and works
      • If a downgrade migration is not possible for this change, please call this out in the PR description!
    • No migrations
  • Documentation:
    • Documentation complete, PR opened in fidesdocs
    • Documentation issue created in fidesdocs
    • If there are any new client scopes created as part of the pull request, remember to update public-facing documentation that references our scope registry
    • No documentation updates required

Copy link

vercel bot commented Jan 21, 2025

The latest updates on your projects. Learn more about Vercel for Git ↗︎

1 Skipped Deployment
Name Status Preview Comments Updated (UTC)
fides-plus-nightly ⬜️ Ignored (Inspect) Visit Preview Jan 21, 2025 7:27pm

Copy link
Contributor Author

@adamsachs adamsachs left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

some quick notes -

@@ -104,7 +104,12 @@ def test_str_to_b64_str() -> None:
"password, expected",
[
("Testpassword1!", "Testpassword1!"),
(
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this new test was failing before the fix

@@ -13,7 +13,7 @@ def decode_password(password: str) -> str:
"""
try:
return b64_str_to_str(password)
except Error:
except (Error, UnicodeDecodeError):
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

decided to keep this minimal in scope - only catching the error i know can be thrown in the error case. handling more generic errors/exceptions would be more likely to lead to unintended side effects, IMO.

also didn't add any sort of logging here as it could get very noisy, but i'd be open to an argument for that

@adamsachs adamsachs changed the title ensure decode function properly handles plaintext but valid base64 passwords ensure decode_password function properly handles plaintext but valid base64 passwords Jan 21, 2025
@adamsachs adamsachs self-assigned this Jan 21, 2025
Copy link

cypress bot commented Jan 21, 2025

fides    Run #11904

Run Properties:  status check failed Failed #11904  •  git commit 8bb30a227c ℹ️: Merge 3730654f1a5b1a3146eaa6d866f1067ab146f926 into 7043171c4d6f3564c93e39b48abf...
Project fides
Branch Review refs/pull/5698/merge
Run status status check failed Failed #11904
Run duration 01m 08s
Commit git commit 8bb30a227c ℹ️: Merge 3730654f1a5b1a3146eaa6d866f1067ab146f926 into 7043171c4d6f3564c93e39b48abf...
Committer Adam Sachs
View all properties for this run ↗︎

Test results
Tests that failed  Failures 1
Tests that were flaky  Flaky 0
Tests that did not run due to a developer annotating a test with .skip  Pending 0
Tests that did not run due to a failure in a mocha hook  Skipped 0
Tests that passed  Passing 3
⚠️ You've recorded test results over your free plan limit.
Upgrade your plan to view test results.
View all changes introduced in this branch ↗︎

Tests for review

Copy link

codecov bot commented Jan 21, 2025

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 87.14%. Comparing base (7043171) to head (1a387b3).

Additional details and impacted files
@@           Coverage Diff           @@
##             main    #5698   +/-   ##
=======================================
  Coverage   87.14%   87.14%           
=======================================
  Files         388      388           
  Lines       24034    24034           
  Branches     2594     2594           
=======================================
  Hits        20944    20944           
  Misses       2529     2529           
  Partials      561      561           

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

Copy link
Contributor

@Kelsey-Ethyca Kelsey-Ethyca left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@adamsachs
Copy link
Contributor Author

failing tests look flaky to me, merging 👍

@adamsachs adamsachs merged commit bbba31d into main Jan 21, 2025
34 of 37 checks passed
@adamsachs adamsachs deleted the asachs/HJ-397 branch January 21, 2025 20:16
adamsachs added a commit that referenced this pull request Jan 21, 2025
Copy link

cypress bot commented Jan 21, 2025

fides    Run #11905

Run Properties:  status check passed Passed #11905  •  git commit bbba31d7fe: ensure `decode_password` function properly handles plaintext but valid base64 pa...
Project fides
Branch Review main
Run status status check passed Passed #11905
Run duration 00m 51s
Commit git commit bbba31d7fe: ensure `decode_password` function properly handles plaintext but valid base64 pa...
Committer Adam Sachs
View all properties for this run ↗︎

Test results
Tests that failed  Failures 0
Tests that were flaky  Flaky 0
Tests that did not run due to a developer annotating a test with .skip  Pending 0
Tests that did not run due to a failure in a mocha hook  Skipped 0
Tests that passed  Passing 4
⚠️ You've recorded test results over your free plan limit.
Upgrade your plan to view test results.
View all changes introduced in this branch ↗︎

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