Page MenuHomePhabricator

[Flow202][web][skip-ci] [21/x] Avoid localforage.getItem with unclear type param for web encryption key
ClosedPublic

Authored by ashoat on Nov 26 2023, 11:11 PM.
Tags
None
Referenced Files
Unknown Object (File)
Fri, Nov 29, 4:08 PM
Unknown Object (File)
Fri, Nov 29, 3:52 PM
Unknown Object (File)
Tue, Nov 26, 3:55 AM
Unknown Object (File)
Mon, Nov 25, 9:41 PM
Unknown Object (File)
Sun, Nov 24, 12:13 AM
Unknown Object (File)
Oct 27 2024, 9:02 PM
Unknown Object (File)
Oct 19 2024, 2:39 AM
Unknown Object (File)
Oct 19 2024, 2:39 AM
Subscribers

Details

Summary

After rebasing my Flow upgrade stack, I noticed a bunch of new errors: https://gist.github.com/Ashoat/b83564168fda704b2ce9d8051d0f472e

I played around a bit and it seems like an incompatibility between CryptoKey and SubtleCrypto$JsonWebKey introduced in D9535 and D9661, here and here.

@marcin's proposed this solution, which addresses the issue by avoiding calling localforage.getItem in a situation where the type param is ambiguous.

NOTE: CI will fail on this diff. I considered the possibility of fixing Flow errors BEFORE upgrading Flow, but it wasn't possible... in some cases, the fixes to support the new version of Flow caused errors in the old version. I could have hidden these type errors with $FlowFixMe lines and then later revert those, but that seemed like too much busy work.

Depends on D9786

Test Plan

Confirm the Flow errors go away

Diff Detail

Repository
rCOMM Comm
Lint
Lint Not Applicable
Unit
Tests Not Applicable

Event Timeline

@marcin – if you suspect my assessment is incorrect, would appreciate it if you could patch this diff locally (yarn arcpatch D9984) and see if you can come up with an alternative way to get the Flow errors in web to go away

marcin requested changes to this revision.Nov 27 2023, 3:54 AM

After examining CryptoKey and SubtleCrypto$JsonWeKey types I came to a conclusion that they are indeed different types. The CryptoKey type is meant to represent in-memory data structure that is not readable from JS. The SubtleCrypto$JsonWeKey type represents JS-readable form of the former that can be written directly to file, persisted to IndexedDB if the browser does not implement structured clone algorithm. Looks like flow got more restrictive in newer version so we must be more specific in our code. This patch fixes errors you linked without changing CryptoKey typing: https://gist.github.com/marcinwasowicz/3f1478ede2702b8e96d168b5d8a52b2c

This revision now requires changes to proceed.Nov 27 2023, 3:54 AM

Thanks @marcin. I rewrote your code to avoid your inline await (which breaks out conventions), and reversed the condition to reduce indentation. Update coming soon

@marcin's approach (with some changes)

ashoat retitled this revision from [Flow202][web][skip-ci] [21/x] Update CryptoKey to be an alias of SubtleCrypto$JsonWebKey to [Flow202][web][skip-ci] [21/x] Avoid localforage.getItem with unclear type param for web encryption key.Nov 27 2023, 9:04 AM
ashoat edited the summary of this revision. (Show Details)
This revision is now accepted and ready to land.Nov 27 2023, 9:06 AM