Repository navigation
Mask preservedUserSession/preservedAccount tokens in Onyx state export - #96907
Conversation
…ask session tokens Co-authored-by: mkhutornyi <mkhutornyi@users.noreply.github.com>
|
@codex review |
|
@MelvinBot review |
|
The only failing check is PR Author Checklist / checklist — the There's nothing to fix in code here — this check passes only once a human checks the boxes in the Every other check passes; the two Next step: as the co-author, complete the |
|
Codex Review: Didn't find any major issues. What shall we delve into next? Reviewed commit: ℹ️ About Codex in GitHubCodex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you
If Codex has suggestions, it will comment; otherwise it will react with 👍. When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback". |
Review — LGTM ✅The fix is correct and correctly scoped. Verified the mechanism end-to-end:
Coverage is complete: Two minor, non-blocking suggestions
Neither is blocking — happy to see this merge as-is once the checklist boxes are ticked. |
DetailsExplanation of ChangeFollow-up to the Onyx state export audit (issue #90977), addressing a security report about
This gives both keys explicit entries in
They are removed from the Fixed Issues$ #90977 TestsSuggested manual verification: sign in, use "Import state" so
Offline testsN/A QA StepsN/A
PR Author Checklist
Screenshots/VideosAndroid: NativeAndroid: mWeb ChromeiOS: NativeiOS: mWeb SafariMacOS: Chrome / Safari@MelvinBot please set the PR body to the content in the details section above |
|
✅ Done — I've set the PR description to the content from the details section (with the author checklist boxes and |
|
@MelvinBot mark as ready for review |
|
@mkhutornyi Please copy/paste the Reviewer Checklist from here into a new comment on this PR and complete it. If you have the K2 extension, you can simply click: [this button] |
|
Done — this PR is now marked Ready for review. 🚀 |
Reviewer Checklist
Screenshots/VideosAndroid: HybridAppAndroid: mWeb ChromeiOS: HybridAppiOS: mWeb SafariMacOS: Chrome / Safaridemo.mov |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 334c9f9d71
ℹ️ About Codex in GitHub
Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".
| [ONYXKEYS.PRESERVED_USER_SESSION]: { | ||
| allowList: ['email', 'accountID', 'loading', 'creationDate', 'errors'], | ||
| maskList: [], | ||
| }, |
There was a problem hiding this comment.
Omit preserved sessions from exported dumps
When an Onyx dump is exported while the app is already in imported-state mode, this rule writes preservedUserSession back into the dump with randomized tokens. Importing that dump later overwrites the freshly saved local preserved session because cleanAndTransformState() only omits session/credentials, not preservedUserSession, and importOnyxRegularState() then multiSets the dump value; exiting imported state will restore the masked tokens as session, leaving the user with an invalid session instead of their original login. Since this key is only local restoration state, it should be removed from exports or omitted on import rather than exported masked.
Useful? React with 👍 / 👎.
There was a problem hiding this comment.
@MelvinBot address #96907 (comment) only if valid
There was a problem hiding this comment.
Valid — addressed in b639f00.
The concern is real: preservedUserSession/preservedAccount are local-only restoration state, and the import flow saves the user's real session into them right before Onyx.multiSet(dump). Since keysToOmit didn't list them, a dump exported while in imported-state mode would carry those keys and overwrite the freshly-saved real session — then on exit clearOnyxAndResetApp restores it as SESSION, leaving the user with an invalid login.
Fix: added both keys to keysToOmit so they're dropped from the imported dump (same pattern already used for CREDENTIALS), and added a regression test in ImportOnyxStateTest.ts. I kept the export-side masking in this PR as defense-in-depth — the tokens still shouldn't sit in a dump even when unmasked, and now they can't round-trip back into a session either.
ImportOnyxStateTest + ExportOnyxStateTest (36 tests) pass, and typecheck/lint/fmt are clean.
…clobber restoration state
Co-authored-by: mkhutornyi <mkhutornyi@users.noreply.github.com>
Co-authored-by: {"message":"Not Found","documentation_url":"https://docs.github.com/rest/issues/comments#get-an-issue-comment","status":"404"} <{"message":"Not Found","documentation_url":"https://docs.github.com/rest/issues/comments#get-an-issue-comment","status":"404"}@users.noreply.github.com>
|
@mkhutornyi Please copy/paste the Reviewer Checklist from here into a new comment on this PR and complete it. If you have the K2 extension, you can simply click: [this button] |
|
🚧 chuckdries has triggered a test Expensify/App build. You can view the workflow run here. |
|
🧪🧪 Use the links below to test this adhoc build on Android, iOS, and Web. Happy testing! 🧪🧪
|
|
✋ This PR was not deployed to staging yet because QA is ongoing. It will be automatically deployed to staging after the next production release. |
|
🚀 Deployed to staging by https://github.com/chuckdries in version: 9.4.44-0 🚀
|
|
🤖 No help site changes required. I reviewed the changes in this PR against Expensify's help site files under Why:
@mkhutornyi, since no help site changes are required, there's no draft PR to review. If you'd still like a net-new article documenting the Export/Import Onyx state troubleshooting flow, reply and I'll draft one. |
|
🚀 Deployed to production by https://github.com/marcaaron in version: 9.4.44-6 🚀
Bundle Size Analysis (Sentry): |
Explanation of Change
Follow-up to the Onyx state export audit (issue #90977), addressing a security report about
PRESERVED_USER_SESSIONleaking session data.PRESERVED_USER_SESSIONholds a fullSessionobject (includingauthToken,encryptedAuthToken, andsupportAuthToken) andPRESERVED_ACCOUNTholds a fullAccount. Both keys were only being handled by themaskFragileDataheuristic fallback, which does not mask token fields — they aren't emails and aren't inkeysToMask— so the auth tokens were exported as-is (unmasked when the mask toggle was off, and passed through even when it was on).This gives both keys explicit entries in
ONYX_KEY_EXPORT_RULESwith the same rules as their live counterparts:PRESERVED_USER_SESSION→ same allow/mask lists asSESSION(keepsemail,accountID,loading,creationDate,errors; masks everything else, including the tokens).PRESERVED_ACCOUNT→ same allow/mask lists asACCOUNT.They are removed from the
onyxKeysToMaskFragileDatabucket and added to theknownSensitiveKeysdenylist test so they can never be reclassified as safe. This keeps the debug value of the export while ensuring the preserved session tokens are masked, consistent with howSESSION/ACCOUNTare already treated.Fixed Issues
$ #90977
PROPOSAL: #90977 (comment)
Tests
Suggested manual verification: sign in, use "Import state" so
PRESERVED_USER_SESSION/PRESERVED_ACCOUNTget populated, then export Onyx state (Settings → Troubleshoot → Export Onyx state) and confirm thepreservedUserSession/preservedAccountobjects show maskedauthToken/encryptedAuthToken/supportAuthTokenvalues (not the real tokens), both with the mask toggle on and off.Offline tests
N/A
QA Steps
N/A
PR Author Checklist
### Fixed Issuessection aboveTestssectionOffline stepssectionQA stepssectiontoggleReportand notonIconClick)Avatar, I verified the components usingAvatarare working as expected)StyleUtils.getBackgroundAndBorderStyle(theme.componentBG))npm run compress-svg)Avataris modified, I verified thatAvataris working as expected in all cases)Designlabel and/or tagged@Expensify/designso the design team can review the changes.mainbranch was merged into this PR after a review, I tested again and verified the outcome was still expected according to theTeststeps.Screenshots/Videos
Android: Native
Android: mWeb Chrome
iOS: Native
iOS: mWeb Safari
MacOS: Chrome / Safari