diff --git a/docs/CURRENT-STATE.md b/docs/CURRENT-STATE.md index af4bd7243f..573cb130ff 100644 --- a/docs/CURRENT-STATE.md +++ b/docs/CURRENT-STATE.md @@ -8117,7 +8117,9 @@ still gets the row: only picking it sends anything. One-time and verification co OTP, 2FA, MFA, CVV and CVC values, "card ending" digits, passphrases, recovery or seed phrases (twelve words in a row on the BIP39 English list in `src/search/bip39Words.js`, also with commas, numbered or after "my seed -is", so a long question or request still goes to Ask GEV), "my secret is …", an email spelled +is", so a long question or request still goes to Ask GEV; twelve with three +words for places or things on a map, such as "park", "beach" or "airport", +are a list of places), "my secret is …", an email spelled out ("john at example dot com", "punto com", or letter by letter), a door, alarm or lockbox number ("code 4821"; "zip code 90210" and "area code 415" are places), "Authorization: Bearer …", a code in a link (`?code=…`), a diff --git a/src/search/placeSuggestions.js b/src/search/placeSuggestions.js index 5ad854a31d..e3f3e1c938 100644 --- a/src/search/placeSuggestions.js +++ b/src/search/placeSuggestions.js @@ -15,6 +15,23 @@ export const isCjk = (text) => CJK.test(String(text || '')); /** The fewest characters a place name is looked up from. */ export const minPlaceChars = (text) => (isCjk(text) ? 2 : 3); +/** + * Words on the BIP39 list that name places and things on a map, for telling + * a list of places from a recovery phrase. + */ +const MAP_WORDS = new Set( + ( + 'airport bar beach bike boat bridge bus cafe car castle city coast coffee ' + + 'country desert east elevator ferry fire flight forest garden harbor ' + + 'hospital hotel house island lake market moon mountain museum north ' + + 'ocean office park planet pizza rain river road rocket satellite school ' + + 'sea ship shop snow south space station storm street sun ' + + 'swim taxi tower town traffic train truck tunnel valley village ' + + 'weather west wind world zoo canyon church stadium bank restaurant ' + + 'map area today tomorrow near' + ).split(' '), +); + /** * Text that may hold something private, which is never looked up, offered * as a place or sent anywhere: @@ -192,13 +209,25 @@ function privacyReason(text) { // 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. + // words ("my seed is …"): twelve of the list's words in a row. The list + // has many words for places and things on a map, and a phrase is drawn at + // random from all of it: twelve with three of those ("coffee, bar, + // hotel, museum, park …") is a list of places. let run = 0; + let mapWords = 0; for (const token of line.toLowerCase().split(/[\s,;]+/)) { - const word = token.replace(/^\d+[.)]?/, '').replace(/[^a-z]+$/, ''); + const word = token + .replace(/^\d+[.)]?/, '') + .replace(/(?<=[a-z])[^a-z]+$/, ''); if (!word && token) continue; - run = isBip39Word(word) ? run + 1 : 0; - if (run >= 12) return 'other'; + if (!isBip39Word(word)) { + run = 0; + mapWords = 0; + continue; + } + run += 1; + if (MAP_WORDS.has(word)) mapWords += 1; + if (run >= 12 && mapWords < 3) 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 ("١٢٣٤, @@ -331,7 +360,9 @@ function privacyReason(text) { .split(/\s+/) // A key in quotes or brackets ("\"sk-…\"") and a postcode before a // comma ("SW1A2AA,") are read without them. - .map((token) => token.replace(/^[^\p{L}\p{N}]+|[^\p{L}\p{N}]+$/gu, '')) + .map((token) => + token.replace(/^[^\p{L}\p{N}]+|(?<=[\p{L}\p{N}])[^\p{L}\p{N}]+$/gu, ''), + ) .some( (token) => /^(?:sk[-_]|rk_|pk_live|ghp_|gho_|ghu_|ghs_|github_pat_|glpat-|hf_|xox[abposr]-)/i.test( @@ -379,7 +410,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|ty|cheers|please|pls|ok|now)(?:\s+(?:a lot|so much|very much|again))?)?[\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,63})(?:(?:\s*[,;]\s*|\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) { @@ -406,7 +437,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|ty|cheers|please|pls|ok|now)(?:\s+(?:a lot|so much|very much|again))?)?[\s.!?]*$/i.exec( + /\b(?:pin|(?:door|access|gate|alarm|entry) code)(?:\s+is)?\s+([a-z0-9-]{4,64})(?:(?:\s*[,;]\s*|\s+)(?:thanks|thank you|thx|ty|cheers|please|pls|ok|now)(?:\s+(?:a lot|so much|very much|again))?)?[\s.!?]*$/i.exec( line, ); if ( @@ -417,7 +448,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|ty|cheers|please|pls|ok|now)(?:\s+(?:a lot|so much|very much|again))?)?[\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,63})(?:(?:\s*[,;]\s*|\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; diff --git a/src/search/placeSuggestions.test.mjs b/src/search/placeSuggestions.test.mjs index d20411f32d..b6f17b0bd6 100644 --- a/src/search/placeSuggestions.test.mjs +++ b/src/search/placeSuggestions.test.mjs @@ -539,6 +539,10 @@ test('places that only looked private are looked up', () => { 'meet at West Point tomorrow', 'OTP Bank', 'GATE CODE LANE', + // Lists of places, though every word is on the BIP39 list. + 'coffee, bar, hotel, museum, park, beach, hospital, school, market, bridge, tower, airport', + '1. beach 2. park 3. museum 4. zoo 5. bridge 6. tower 7. market 8. castle 9. island 10. lake 11. river 12. canyon', + 'show only bus, train, car, truck, ship, boat traffic over city bridge today', // Questions for the assistant, however many short words they have. 'can you tell where the most flights are going over texas today', 'are there any storms near florida right now that might cause delays', @@ -642,9 +646,13 @@ test('a line longer than a place name is never sent for suggestions', async () = }); test('a long line is read quickly', () => { - for (const unit of ['a-', 'a.', '1-', 'a ', '//[a:']) { + for (const line of [ + ...['a-', 'a.', '1-', 'a ', '//[a:'].map((unit) => unit.repeat(10000)), + `otp a${'-'.repeat(20000)}!x`, + `gate code a${'-'.repeat(20000)}!x`, + ]) { const started = performance.now(); - mayBePrivate(unit.repeat(10000)); - assert.ok(performance.now() - started < 1000, unit); + mayBePrivate(line); + assert.ok(performance.now() - started < 1000, line.slice(0, 12)); } });