Withhold an SSN's last four, a code before ", thanks" and a recovery phrase written with commas or numbers

"ssn ending 1234" and "ssn last four 1234" are private again, as before
this change; a code may be followed by a comma, "cheers", "thanks a
lot" or more than one "!"; a recovery phrase is twelve BIP39 words in a
row, so commas, numbering, a closing period or "my seed is" before it no
longer hide it. The spelled-out email patterns start only at a word, which
keeps long inputs fast.

Co-authored-by: Manjunath Paparaju <[email protected]>
This commit is contained in:
Sameh KhamisandManjunath Paparaju committed 2026-11-18 18:38:13 -08:00
1 parent 2487500927
commit 3f5221b837
3 files changed
+49 -20

No files matched your search

+23 -15
View File
@@ -154,13 +154,13 @@ function privacyReason(text) {
return 'other';
if (
/[\p{L}\p{N}._%+-]\s*[([{<]\s*at\s*[)\]}>]\s*[\p{L}\p{N}-]/iu.test(line) ||
/\b\S+\s+at\s+\S+\s+(?:dot|punto|ponto|period|punkt|[([{<]\s*dot\s*[)\]}>])\s+\p{L}{2,24}\b/iu.test(
/(?<!\S)\S{1,64}\s+at\s+\S+\s+(?:dot|punto|ponto|period|punkt|[([{<]\s*dot\s*[)\]}>])\s+\p{L}{2,24}\b/iu.test(
line,
) ||
/\b\S+\s+at\s+[\p{L}\p{N}-]+\s*[([{<]\s*dot\s*[)\]}>]\s*\p{L}{2,24}\b/iu.test(
/(?<!\S)\S{1,64}\s+at\s+[\p{L}\p{N}-]+\s*[([{<]\s*dot\s*[)\]}>]\s*\p{L}{2,24}\b/iu.test(
line,
) ||
/\b[\p{L}\p{N}._%+-]+\s+at\s+[\p{L}\p{N}-]+(?:\.[\p{L}\p{N}-]+)*\s*\.\s*(?:com|net|org|edu|gov|mil|io|co|me|info|biz|app|dev|ai|[a-z]{2})\b/iu.test(
/(?<![\p{L}\p{N}._%+-])[\p{L}\p{N}._%+-]{1,64}\s+at\s+[\p{L}\p{N}-]+(?:\.[\p{L}\p{N}-]+)*\s*\.\s*(?:com|net|org|edu|gov|mil|io|co|me|info|biz|app|dev|ai|[a-z]{2})\b/iu.test(
line,
)
)
@@ -187,13 +187,19 @@ function privacyReason(text) {
})
)
return 'other';
// A wallet's recovery phrase, whole or nearly ("abandon ability able
// …"): twelve to twenty-four words, every one on the BIP39 list ("can you
// tell where the most …" is a question). Too long to be sent for
// suggestions anyway, it is kept from the assistant too.
const words = line.trim().toLowerCase().split(/\s+/);
if (words.length >= 12 && words.length <= 24 && words.every(isBip39Word))
return 'other';
// A wallet's recovery phrase ("abandon ability able …"): twelve words in
// a row on the BIP39 list ("can you tell where the most …" is a
// question). Too long to be sent for suggestions anyway, it is kept from
// the assistant too.
// Written with commas, numbered ("1. abandon 2. ability") or after a few
// words ("my seed is …"): twelve of the list's words in a row.
let run = 0;
for (const token of line.toLowerCase().split(/[\s,;]+/)) {
const word = token.replace(/^\d+[.)]?/, '').replace(/[^a-z]+$/, '');
if (!word && token) continue;
run = isBip39Word(word) ? run + 1 : 0;
if (run >= 12) return 'other';
}
// Coordinates and grid references are a spot, not a number to keep: only
// text the place search itself reads as coordinates, as typed ("١٢٣٤,
// ٥٦٧٨" folded would read as a spot, but is not one).
@@ -256,7 +262,7 @@ function privacyReason(text) {
// but a capitalised name is a token, and a social security number has
// digits.
bearerToken(line) ||
/\bssn\b(?:\s+(?:is|no\.?|number|#))*\s*[:=#]?\s*(?:\d|[x*]{2})/i.test(
/\bssn\b(?:\s+(?:is|are|no\.?|number|#|ending|ends?|in|with|last|four|4|digits))*\s*[:=#]?\s*(?:\d|[x*]{2})/i.test(
line,
) ||
// The word for "password" in the interface's languages.
@@ -284,7 +290,9 @@ function privacyReason(text) {
line,
) ||
// An email spelled out to slip past a filter: "john at example dot com".
/\b\S+\s+at\s+\S+\s+dot\s+(?:com|net|org|edu|gov|io|co)\b/i.test(line) ||
/(?<!\S)\S{1,64}\s+at\s+\S+\s+dot\s+(?:com|net|org|edu|gov|io|co)\b/i.test(
line,
) ||
/\b(?:pin|otp|2fa|mfa|cvv|cvc|(?:door|access|gate|alarm|entry|security|verification|one-time|auth|login) code|card ending(?: in)?)(?:\s+(?:code|number|is|no\.?))*\s*[:=#]?\s*\d/i.test(
line,
) ||
@@ -371,7 +379,7 @@ function codeAfterLabel(line) {
// After a label in lower case, any value is a code ("verification code
// Abc"); after one written as a name, only a value that is not one.
const coded =
/\b((?:otp|2fa|mfa|cvv|cvc|(?:verification|one-time|security|auth|login) code)(?:\s+is)?)\s+([a-z0-9][a-z0-9-]{2,})(?:\s+(?:thanks|thank you|thx|please|pls|ok|now))?\s*[.!]?\s*$/i.exec(
/\b((?:otp|2fa|mfa|cvv|cvc|(?:verification|one-time|security|auth|login) code)(?:\s+is)?)\s+([a-z0-9][a-z0-9-]{2,})(?:[\s,;-]+(?:thanks|thank you|thx|ty|cheers|please|pls|ok|now)(?:\s+(?:a lot|so much|very much|again))?)?[\s.!?]*$/i.exec(
line,
);
if (coded) {
@@ -398,7 +406,7 @@ function codeAfterLabel(line) {
}
// A value in mixed case that is no name ("PIN aBcD", "gate code aBcD").
const mixed =
/\b(?:pin|(?:door|access|gate|alarm|entry) code)(?:\s+is)?\s+([a-z0-9-]{4,})(?:\s+(?:thanks|thank you|thx|please|pls|ok|now))?\s*[.!]?\s*$/i.exec(
/\b(?:pin|(?:door|access|gate|alarm|entry) code)(?:\s+is)?\s+([a-z0-9-]{4,})(?:[\s,;-]+(?:thanks|thank you|thx|ty|cheers|please|pls|ok|now)(?:\s+(?:a lot|so much|very much|again))?)?[\s.!?]*$/i.exec(
line,
);
if (
@@ -409,7 +417,7 @@ function codeAfterLabel(line) {
)
return true;
const match =
/\b((?:pin|cvv|cvc|otp|2fa|mfa|(?:door|access|gate|alarm|entry|security|verification|one-time|auth|login) code)(?:\s+is)?)\s+([a-z0-9][a-z0-9-]{3,})(?:\s+(?:thanks|thank you|thx|please|pls|ok|now))?\s*[.!]?\s*$/i.exec(
/\b((?:pin|cvv|cvc|otp|2fa|mfa|(?:door|access|gate|alarm|entry|security|verification|one-time|auth|login) code)(?:\s+is)?)\s+([a-z0-9][a-z0-9-]{3,})(?:[\s,;-]+(?:thanks|thank you|thx|ty|cheers|please|pls|ok|now)(?:\s+(?:a lot|so much|very much|again))?)?[\s.!?]*$/i.exec(
line,
);
if (!match) return false;
+20
View File
@@ -462,6 +462,18 @@ test('spelled-out emails, addresses, phrases, codes and short phone numbers stay
'the code to my door is 4821',
'AB 12 34 56 C',
'my id is AB12345',
'ssn ending 1234',
'ssn last four 1234',
'SSN ends in 6789',
'otp ABCDEF, thanks',
'pin AbCd, thanks',
'otp ABCDEF thanks!!',
'verification code ABCDEF thanks a lot',
'otp ABCDEF cheers',
'abandon ability able about above absent absorb abstract absurd abuse access accident.',
'abandon, ability, able, about, above, absent, absorb, abstract, absurd, abuse, access, accident',
'1. abandon 2. ability 3. able 4. about 5. above 6. absent 7. absorb 8. abstract 9. absurd 10. abuse 11. access 12. accident',
'my seed is abandon ability able about above absent absorb abstract absurd abuse access accident',
'My ID 12345',
'john at gmail .com',
'john at gmail punto com',
@@ -628,3 +640,11 @@ test('a line longer than a place name is never sent for suggestions', async () =
await service.suggest('1 2 3 4 5 6 7 8 9 10 11');
assert.equal(sent, 1);
});
test('a long line is read quickly', () => {
for (const unit of ['a-', 'a.', '1-', 'a ', '//[a:']) {
const started = performance.now();
mayBePrivate(unit.repeat(10000));
assert.ok(performance.now() - started < 1000, unit);
}
});