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

task(fxa-settings): Revert localized content in key download file #15437

Merged
merged 1 commit into from
Jun 15, 2023

Conversation

vpomerleau
Copy link
Contributor

Because

  • Localized plain text file is not rendering as expected on Android and Windows.
  • Hidden directionality characters get copied with key, resulting in the key being marked as invalid during password reset.
  • Reversal is temporary to prevent this issue from blocking deployment while next steps are determined.

This pull request

  • Serve key only in the file download.

Issue that this pull request solves

Closes: #FXA-7688

Checklist

Put an x in the boxes that apply

  • My commit is GPG signed.
  • If applicable, I have modified or added tests which pass locally.
  • I have added necessary documentation (if appropriate).
  • I have verified that my changes render correctly in RTL (if appropriate).

Screenshots (Optional)

Please attach the screenshots of the changes made in case of change in user interface.

Other information (Optional)

Any other information that is important to this pull request.

@vpomerleau vpomerleau requested a review from a team as a code owner June 12, 2023 23:20
Copy link
Contributor

@LZoog LZoog left a comment

Choose a reason for hiding this comment

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

I'll go ahead and r+ but let me know if you want a re-review on anything.

// Non-latin text (e.g., Hebrew) may be displayed as jibberish due to incorrect encoding detection.
// In addition, localized strings contain important directionality markers that are hidden on Mac
// but visible on many other devices. On Apple devices, these directionality markers get copied with the key,
// and the key is rejected as invalid during password reset.
Copy link
Contributor

Choose a reason for hiding this comment

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

What do these markers look like? Is it something we can strip on submit like we do spaces? Doesn't help with the comment about Hebrew though...

What do our localized plaintext emails look like, are they not experiencing these issues? If they aren't, the fix (not in this PR) might be to repurpose our Localizer class to be either used here (sounds like Reino was already thinking about using it client-side), or the logic needed from it pulled and used. We probably need a similar ticket filed if our emails experience the same thing.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The markers are rendered differently depending on the device/application. Sometimes invisible, sometimes square boxes, sometimes little symbols with FSI/PDI letters.

We could strip them out on submit or leave the key out of the localized string to resolve FXA-7571 , but we're left with the issue that there are directionality markers around other bits of text in this download file including brand terms, and that doesn't look great on most devices/applications except Apple's FXA-7564.

Our plain text emails do include directionality markers, but they're hidden in maildev. Not sure if they might be visible in other email clients. The confirmation codes are fine functionality-wise because they're on their own line and not included as a variable in a localized string --> no directionality marker(s) around the emailed codes.

Copy link
Contributor

@LZoog LZoog Jun 15, 2023

Choose a reason for hiding this comment

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

Well, that is a tricky problem. I'm just reiterating the ticket here but looks like Windows is not respecting the directionality markers at all if I'm seeing the screenshots correctly; English shows the unicode control characters and renders LTR (probably default) and RTL languages show the unicode control characters and are still rendering LTR.

Notepad is notorious for not displaying unicode correctly, but it's strange it's also occurring in Notepad++... If we don't use PDFs (unsure if that would solve this), this is not ideal but I wonder if Windows would interpret "overrides" or "embedding" better than "isolates"? I'm not sure if we can parse the text and replace [U+2068] with \u202E (not 100% sure that's how it'd need to be in code) or if that would need to happen on the l10n side somehow. 🤔

Copy link
Contributor Author

Choose a reason for hiding this comment

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

TLDR; Getting encoding right on all devices/apps is very tricky. For the time being, I've reverted the default download to "key only" but included a few options that we can test in staging with a param. Also filed a spike to investigate options https://mozilla-hub.atlassian.net/browse/FXA-7790 because this testing was growing beyond the scope of this ticket.

Windows is not respecting the directionality markers at all

The directionality markers are useful when the text contains a mix of LTR and RTL text, but it won't specify if the file as a whole should be displayed in RTL. If the Windows OS is set to Hebrew (for example), text in Notepad will be displayed in RTL by default (or so I've understood). Switching between RTL and LTR is manual if the text direction does not match the OS direction (this is also true for Mac).

English shows the unicode control characters

The FSI/PDI characters can be optionally shown/hidden in Notepad with app settings, we just can't assume that the characters will be hidden by default.

If we don't use PDFs (unsure if that would solve this)

Switching to PDF will have it's own set of problems, because then we'll have to conditionally apply styling incl. directionality markers to the PDF that we're generating on the fly, based on the user's locale (BUT at least we would have more control over the output... maybe. PDFs can also have problems with encoding http://www.rdpslides.com/psfaq/ENCODING.PDF)

I wonder if Windows would interpret "overrides" or "embedding" better than "isolates"? I'm not sure if we can parse the text and replace [U+2068] with \u202E (not 100% sure that's how it'd need to be in code) or if that would need to happen on the l10n side somehow. 🤔

I'm not sure if Windows might interpret those other characters more easily, but the trouble with "overrides" and "embedding" is that they can have spillover effect on surrounding text. The Unicode standards recommend using "isolates".

// and the key is rejected as invalid during password reset.

// Not tested - could possibly force recognition of UTF-8 encoding by adding BOM at the beginning of the blob
const BOM = new Uint8Array([0xef, 0xbb, 0xbf]);
Copy link
Contributor

Choose a reason for hiding this comment

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

Does BOM mean anything in particular? Also if you want to test this in staging (if we're not planning to go to prod right now anyway), we could potentially enable this with a parameter instead of setting keyWithContext to false.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

BOM stands for "byte order mark". I've read that it can be used to identify the encoding of a text file, but I'm not sure if it would resolve the issue where some text is jibberish on Android.
https://learn.microsoft.com/en-us/globalization/encoding/byte-order-mark

Good call on enabling with a parameter so we can test if it makes a difference on stage.

Copy link
Contributor

@LZoog LZoog Jun 15, 2023

Choose a reason for hiding this comment

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

@vpomerleau Ah, TIL. Have you tried specifying charset in the type or maybe there's another way to force utf-8? Like, type: 'text/plain;charset=utf-8'. Not sure if that'll work though.

You could maybe also try TextEncoder to convert each string to utf-8.

@vpomerleau vpomerleau requested a review from a team as a code owner June 14, 2023 23:38
# "Key" here refers to the term "account recovery key"
recovery-key-file-key-value-v2 = Key: { $recoveryKeyValue }
# "Key" here refers to the term "account recovery key", a randomly generated code in latin characters
recovery-key-file-key-value-v3 = Key:
Copy link
Contributor Author

Choose a reason for hiding this comment

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

@bcolsson With this PR, the download file only contains the key unless we add a query parameter to the URL (on local and stage only). With the query param enabled, we can test the detailed file with the key removed from the localized string.

Copy link
Contributor

Choose a reason for hiding this comment

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

Is in latin characters accurate? It can contain numbers 0-9 and any letters with the exception of I, L, O, and U. Probably not useful to say it's base32 Crockford 😝, maybe just a 32-character generated code?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

base32 Crockford might be too specific here, but I've clarified the comment 👍

@vpomerleau vpomerleau marked this pull request as draft June 15, 2023 16:43
@vpomerleau
Copy link
Contributor Author

Found an old Android device I can use for testing - switching back to draft to test @LZoog's ideas.

Because:

* Localized plain text file is not rendering as expected on Android and Windows.
* Hidden directionality characters get copied with key, resulting in the key being marked as invalid during password reset.
* Reversal is temporary to prevent this issue from blocking deployment while next steps are determined.

This commit:

* Serve key only in the file download.
* Add an optional query param to test downloading a detailed file 1) with BOM (byte-order-mark), 2) with charset defined, or 3) with TextEncoder
* Add stories to download the 3 test options

Closes #FXA-7688
@vpomerleau vpomerleau marked this pull request as ready for review June 15, 2023 20:09
@vpomerleau vpomerleau merged commit 59a7cdf into main Jun 15, 2023
@vpomerleau vpomerleau deleted the FXA-7688 branch June 15, 2023 22:20
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.

3 participants