diff --git a/changelog.d/1830-place-privacy.md b/changelog.d/1830-place-privacy.md new file mode 100644 index 0000000000..ebb9aea283 --- /dev/null +++ b/changelog.d/1830-place-privacy.md @@ -0,0 +1,7 @@ +- More private text typed into the Omnibar or Location search stays off the + place service: emails spelled out or spaced, IP addresses, wallet recovery + phrases, door, alarm and lockbox numbers, codes after their labels, + document and ID numbers, SSNs, more API token shapes and codes in links. + More real places get through: "Boise ID 83702", house numbers in the + order their country writes them, addresses of up to ten words, and long + questions for Ask GEV (manjunath22466, samehkhamis, #1830). diff --git a/docs/CURRENT-STATE.md b/docs/CURRENT-STATE.md index 5803d88fbf..5b8f248514 100644 --- a/docs/CURRENT-STATE.md +++ b/docs/CURRENT-STATE.md @@ -8117,10 +8117,13 @@ while the tab is hidden. A place search on its own runs through Location and shares its cancellation and errors, keeping the separate Location draft intact. -While typing, a short line (six words or fewer, no `?`, not a command, +While typing, a short line (six words or fewer, ten with a number in it +as an address has, no `?`, not a command, coordinates, a hex code, a callsign such as UAL2110 or N123AB, and nothing that may be private) is sent to -Photon for place suggestions: at most one request every 500 ms per tab, +Photon for place suggestions (the suggester itself never sends a line of +more than eight words, or ten with a number): at most one request every +500 ms per tab, and none for a minute after a refusal. Photon is the keyless geocoder the place search already uses; a submitted search is not part of this spacing. A line that may be one name ("Satellite Beach") is looked up whole. While @@ -8134,49 +8137,93 @@ digits and "@" count, and digits of any script count as digits. It is any line with: an "@" with something right on both sides, ending a word, starting a lowercase handle ("@jdoe"), or spaced before a domain ("john @ gmail.com") (an email address or a handle, also while it is typed; spaced, as in "Nanjampeta @ -Chandambylu", it is part of a name); seven digits or more with nothing but spaces, +Chandambylu", it is part of a name); an email spelled around a filter +("john(at)gmail.com", "john[at]gmail[dot]com", "john at gmail dot de", +"john at gmail.com", "john at gmail (dot) com"); an IP address +("10.0.0.1", "::1", "fe80::1", "https://[::1]/"); a wallet's recovery +phrase (see below); seven digits or more with nothing but spaces, punctuation, symbols or format characters between them (a phone, card, SSN or account number or its start: "+1 415 555", "4111 1111", "123 45 6789", "123456789", "4111.1111.1111.1111", "123–45–6789"; a street address's house number -and its postcode are read apart: five digits, or between the street and +and its postcode are read apart (a house number never starts with 0, and +a polite word such as "thanks" after the digits is not a city): five digits, or between the street and the city "00-950", "111 21", "125009", "1100-053", or four digits after a -comma ("Straße 120, 1070 Wien"); and so are a US ZIP+4 after a word, -a Brazilian CEP, a Japanese postcode after "〒" or before the address, and +comma ("Straße 120, 1070 Wien"); and so are a US ZIP+4 after a state's +code or name ("Alice 12345-6789" and "Jo 12345-6789" stay private), +a Brazilian CEP, a Japanese postcode after "〒" or next to the address in +Japanese script ("東京都千代田区100-0001"; after a Latin name, as in +"Shibuya 150-0002", it reads as a phone number), and digits on either side of "#", so "Hauptstrasse 12 10115 Berlin", "DC 20500-0003", "〒100-0001 東京都千代田区" and "Calle 100 # 19-61" are places, while a seven-digit postcode alone such as "Tel Aviv 6100000" still reads as private); a phone number written with dots; two letters, two digits and ten more letters or digits (an IBAN's shape); "password", -"passcode", "passwd", "ssn", "pw", "pwd" or "bearer" followed by anything, -"token", "secret", "api key", "key" or "pass" followed by ":" or "=", a +"passcode", "passwd", "pw" or "pwd" followed by anything, "bearer" +followed by anything but a short capitalised name or a place word such as +island or lake ("Bearer Island", "bearer island" are places), +"ssn" followed by a digit, also after "ending", "ends in" or "last four" +("SSN Station" is a place), "token", "secret", +"api key", "key" or "pass" followed by ":" or "=", a licence, plate, +passport, membership, account, policy, ticket, booking, confirmation or +reference number with a digit after its label ("license ABC1234", +"passport no. 123456"), "ID" in capitals followed by a number ("ID +AB123"), "otp", "2fa", "mfa", "cvv", "cvc" or a verification, one-time, +security, auth or login code followed by a code (any value after a label +in lower case, "verification code Abc", also before "thanks", ", thanks", "cheers" or "thanks a lot"; after a label +written as a name, any value that is not one: "OTP Bank" and "Security +Code Plaza" are places), a "pin" or door, access, gate, alarm or entry +code followed by a value in mixed case ("PIN aBcD"), a door, access, gate, alarm, entry or security code followed by a digit, "api key", "access token" or "secret key" followed by a word of six characters or more, the word for "password" in the interface's languages (contraseña, Passwort, mot de passe, пароль…) followed by anything, or "pin" (also "pin code", "pin number", "pin is") followed by a digit; a word -starting `sk_`, `sk-`, `rk_`, `pk_live`, `ghp_` or a Slack token's `xoxb-` and the like (any case) or -`AIza`, `eyJ` or `AKIA`; or a word that may be a password or key, with letters and digits mixed +starting `sk_`, `sk-`, `rk_`, `pk_live`, `ghp_`, `github_pat_`, `glpat-`, `hf_`, a SendGrid +`SG.` key or a Slack token's `xoxb-` and the like (any case) or +`AIza` or `eyJ`, or an AWS key id (`AKIA` and twelve capitals or digits +more; "Akiak" is a place); or a word that may be a password or key, with letters and digits mixed within one run (a number beside a word, as in "Yanino-1", "2-chōme" or "Route-66", is a name): eight characters or more, six or more with four letters and a digit ("hunter22", "Area51"), or six or more with letters, digits and a symbol ("Tr0ub4dor&3"). The password words match whole words -only ("Sachsenhausen" is a place). Over the bundled names (139,502), five -read as private: two with stray digits ("Maliga0N", "Jerónim67") and three -with number lists or codes. When the text may be private the field says +only ("Sachsenhausen" is a place). Over the bundled names (139,502), six +read as private: two with stray digits ("Maliga0N", "Jerónim67"), two +joined by "@" to a lower-case handle ("Pulipadu @Govardhanagiri") and two +with number lists or dates. When the text may be private the field says so ("Looks private, so nothing is searched or sent"), and a line whose only private sign is an address-sized run of digits (no group over six -digits, nine at most in all, counted as they fold, and no word such as +digits, nine at most in all, counted as they fold, no three digits +followed by four as a phone number writes them, and no word such as card, code, key, phone or account beside them, in English and some other European languages; compounds such as "Kreditkartennummer" and words in other scripts are not read), with words beside it, gets a row to search it as a place on purpose ("Search … as a place anyway"), which runs the ordinary place search and its online services only when picked; a bare number, an email or handle, a password, key, code or IBAN gets none. +A suggested house is named by its number and its street (or, without a +street, its locality, district or city) in the order its country writes them: "10 Downing +Street", "Hauptstraße 12". A nine-digit number or a short phone number written with no such word still gets the row: only picking it sends anything. One-time and verification codes, OTP, 2FA, MFA, CVV and CVC values, "card ending" digits, passphrases, -recovery or seed phrases, "my secret is …" and an email spelled out ("john -at example dot com") are private too. Text that parses as coordinates or a +recovery or seed phrases (twelve words in a row on the BIP39 English list +in `src/search/bip39Words.js`, also with commas, numbered, quoted, joined by +dashes or slashes, or after "my seed is", so a long question or request +still goes to Ask GEV; twelve with four words for places or for asking about +them, such as "park", "airport", "near" or "today", are a list or a request, +which lets about one phrase in a hundred through), "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 +spaced UK National Insurance number and "my id is …" are private too. +"Boise ID 83702" names Idaho. Some private text is not caught: a +passphrase run together as one word (a long place name is one word too), +a lower-case word after "otp", "2fa" or "mfa" ("mfa boston" is a name; +"otp ABCDEF" is caught) and a code of lower-case letters after "pin" or +"gate code" ("PIN ABCD" is caught). +A Japanese postcode after a Latin name is refused ("Shibuya 150-0002"), and +so is a name in capitals after a code's label ("MFA BOSTON", which cannot +be told from "OTP ABCDEF"). Text that parses as coordinates or a grid reference is not private. A place's name is six words at most, or ten when it has a number in it (an address: "1600 Pennsylvania Ave NW Washington DC 20500"). The places picked from the Omnibar's rows and chips that carry a position diff --git a/scripts/format-scope.json b/scripts/format-scope.json index d2f4f549a3..080febd46b 100644 --- a/scripts/format-scope.json +++ b/scripts/format-scope.json @@ -1601,6 +1601,7 @@ "src/data/wikidataCities.js", "src/data/wikidataCities.test.mjs", "scripts/build-wikidata-cities.mjs", + "src/search/bip39Words.js", "src/search/placeSuggestions.test.mjs", "scripts/wikidataPlaceTiles.mjs", "src/tooling/wikidataPlaceTiles.test.mjs", diff --git a/scripts/package-boundaries.json b/scripts/package-boundaries.json index 2289a8318d..dbbfdf35bd 100644 --- a/scripts/package-boundaries.json +++ b/scripts/package-boundaries.json @@ -307,7 +307,8 @@ "src/ui/omnibarRows.js", "src/search/gridReference.js", "src/search/coordinateParser.js", - "src/search/placeSuggestions.js" + "src/search/placeSuggestions.js", + "src/search/bip39Words.js" ], "external": ["vue", "pinia", "vue-i18n"] }, diff --git a/src/search/bip39Words.js b/src/search/bip39Words.js new file mode 100644 index 0000000000..0c8fa29f63 --- /dev/null +++ b/src/search/bip39Words.js @@ -0,0 +1,210 @@ +/** + * @module search/bip39Words + * @description The 2048 words of the BIP39 English list, from which wallet + * recovery phrases are made (github.com/bitcoin/bips, bip-0039/english.txt). + * Only read to keep a typed phrase from leaving the browser. + */ + +const WORDS = ` +abandon ability able about above absent absorb abstract absurd abuse +access accident account accuse achieve acid acoustic acquire across +act action actor actress actual adapt add addict address adjust admit +adult advance advice aerobic affair afford afraid again age agent +agree ahead aim air airport aisle alarm album alcohol alert alien all +alley allow almost alone alpha already also alter always amateur +amazing among amount amused analyst anchor ancient anger angle angry +animal ankle announce annual another answer antenna antique anxiety +any apart apology appear apple approve april arch arctic area arena +argue arm armed armor army around arrange arrest arrive arrow art +artefact artist artwork ask aspect assault asset assist assume asthma +athlete atom attack attend attitude attract auction audit august aunt +author auto autumn average avocado avoid awake aware away awesome +awful awkward axis baby bachelor bacon badge bag balance balcony ball +bamboo banana banner bar barely bargain barrel base basic basket +battle beach bean beauty because become beef before begin behave +behind believe below belt bench benefit best betray better between +beyond bicycle bid bike bind biology bird birth bitter black blade +blame blanket blast bleak bless blind blood blossom blouse blue blur +blush board boat body boil bomb bone bonus book boost border boring +borrow boss bottom bounce box boy bracket brain brand brass brave +bread breeze brick bridge brief bright bring brisk broccoli broken +bronze broom brother brown brush bubble buddy budget buffalo build +bulb bulk bullet bundle bunker burden burger burst bus business busy +butter buyer buzz cabbage cabin cable cactus cage cake call calm +camera camp can canal cancel candy cannon canoe canvas canyon capable +capital captain car carbon card cargo carpet carry cart case cash +casino castle casual cat catalog catch category cattle caught cause +caution cave ceiling celery cement census century cereal certain chair +chalk champion change chaos chapter charge chase chat cheap check +cheese chef cherry chest chicken chief child chimney choice choose +chronic chuckle chunk churn cigar cinnamon circle citizen city civil +claim clap clarify claw clay clean clerk clever click client cliff +climb clinic clip clock clog close cloth cloud clown club clump +cluster clutch coach coast coconut code coffee coil coin collect color +column combine come comfort comic common company concert conduct +confirm congress connect consider control convince cook cool copper +copy coral core corn correct cost cotton couch country couple course +cousin cover coyote crack cradle craft cram crane crash crater crawl +crazy cream credit creek crew cricket crime crisp critic crop cross +crouch crowd crucial cruel cruise crumble crunch crush cry crystal +cube culture cup cupboard curious current curtain curve cushion custom +cute cycle dad damage damp dance danger daring dash daughter dawn day +deal debate debris decade december decide decline decorate decrease +deer defense define defy degree delay deliver demand demise denial +dentist deny depart depend deposit depth deputy derive describe desert +design desk despair destroy detail detect develop device devote +diagram dial diamond diary dice diesel diet differ digital dignity +dilemma dinner dinosaur direct dirt disagree discover disease dish +dismiss disorder display distance divert divide divorce dizzy doctor +document dog doll dolphin domain donate donkey donor door dose double +dove draft dragon drama drastic draw dream dress drift drill drink +drip drive drop drum dry duck dumb dune during dust dutch duty dwarf +dynamic eager eagle early earn earth easily east easy echo ecology +economy edge edit educate effort egg eight either elbow elder electric +elegant element elephant elevator elite else embark embody embrace +emerge emotion employ empower empty enable enact end endless endorse +enemy energy enforce engage engine enhance enjoy enlist enough enrich +enroll ensure enter entire entry envelope episode equal equip era +erase erode erosion error erupt escape essay essence estate eternal +ethics evidence evil evoke evolve exact example excess exchange excite +exclude excuse execute exercise exhaust exhibit exile exist exit +exotic expand expect expire explain expose express extend extra eye +eyebrow fabric face faculty fade faint faith fall false fame family +famous fan fancy fantasy farm fashion fat fatal father fatigue fault +favorite feature february federal fee feed feel female fence festival +fetch fever few fiber fiction field figure file film filter final find +fine finger finish fire firm first fiscal fish fit fitness fix flag +flame flash flat flavor flee flight flip float flock floor flower +fluid flush fly foam focus fog foil fold follow food foot force forest +forget fork fortune forum forward fossil foster found fox fragile +frame frequent fresh friend fringe frog front frost frown frozen fruit +fuel fun funny furnace fury future gadget gain galaxy gallery game gap +garage garbage garden garlic garment gas gasp gate gather gauge gaze +general genius genre gentle genuine gesture ghost giant gift giggle +ginger giraffe girl give glad glance glare glass glide glimpse globe +gloom glory glove glow glue goat goddess gold good goose gorilla +gospel gossip govern gown grab grace grain grant grape grass gravity +great green grid grief grit grocery group grow grunt guard guess guide +guilt guitar gun gym habit hair half hammer hamster hand happy harbor +hard harsh harvest hat have hawk hazard head health heart heavy +hedgehog height hello helmet help hen hero hidden high hill hint hip +hire history hobby hockey hold hole holiday hollow home honey hood +hope horn horror horse hospital host hotel hour hover hub huge human +humble humor hundred hungry hunt hurdle hurry hurt husband hybrid ice +icon idea identify idle ignore ill illegal illness image imitate +immense immune impact impose improve impulse inch include income +increase index indicate indoor industry infant inflict inform inhale +inherit initial inject injury inmate inner innocent input inquiry +insane insect inside inspire install intact interest into invest +invite involve iron island isolate issue item ivory jacket jaguar jar +jazz jealous jeans jelly jewel job join joke journey joy judge juice +jump jungle junior junk just kangaroo keen keep ketchup key kick kid +kidney kind kingdom kiss kit kitchen kite kitten kiwi knee knife knock +know lab label labor ladder lady lake lamp language laptop large later +latin laugh laundry lava law lawn lawsuit layer lazy leader leaf learn +leave lecture left leg legal legend leisure lemon lend length lens +leopard lesson letter level liar liberty library license life lift +light like limb limit link lion liquid list little live lizard load +loan lobster local lock logic lonely long loop lottery loud lounge +love loyal lucky luggage lumber lunar lunch luxury lyrics machine mad +magic magnet maid mail main major make mammal man manage mandate mango +mansion manual maple marble march margin marine market marriage mask +mass master match material math matrix matter maximum maze meadow mean +measure meat mechanic medal media melody melt member memory mention +menu mercy merge merit merry mesh message metal method middle midnight +milk million mimic mind minimum minor minute miracle mirror misery +miss mistake mix mixed mixture mobile model modify mom moment monitor +monkey monster month moon moral more morning mosquito mother motion +motor mountain mouse move movie much muffin mule multiply muscle +museum mushroom music must mutual myself mystery myth naive name +napkin narrow nasty nation nature near neck need negative neglect +neither nephew nerve nest net network neutral never news next nice +night noble noise nominee noodle normal north nose notable note +nothing notice novel now nuclear number nurse nut oak obey object +oblige obscure observe obtain obvious occur ocean october odor off +offer office often oil okay old olive olympic omit once one onion +online only open opera opinion oppose option orange orbit orchard +order ordinary organ orient original orphan ostrich other outdoor +outer output outside oval oven over own owner oxygen oyster ozone pact +paddle page pair palace palm panda panel panic panther paper parade +parent park parrot party pass patch path patient patrol pattern pause +pave payment peace peanut pear peasant pelican pen penalty pencil +people pepper perfect permit person pet phone photo phrase physical +piano picnic picture piece pig pigeon pill pilot pink pioneer pipe +pistol pitch pizza place planet plastic plate play please pledge pluck +plug plunge poem poet point polar pole police pond pony pool popular +portion position possible post potato pottery poverty powder power +practice praise predict prefer prepare present pretty prevent price +pride primary print priority prison private prize problem process +produce profit program project promote proof property prosper protect +proud provide public pudding pull pulp pulse pumpkin punch pupil puppy +purchase purity purpose purse push put puzzle pyramid quality quantum +quarter question quick quit quiz quote rabbit raccoon race rack radar +radio rail rain raise rally ramp ranch random range rapid rare rate +rather raven raw razor ready real reason rebel rebuild recall receive +recipe record recycle reduce reflect reform refuse region regret +regular reject relax release relief rely remain remember remind remove +render renew rent reopen repair repeat replace report require rescue +resemble resist resource response result retire retreat return reunion +reveal review reward rhythm rib ribbon rice rich ride ridge rifle +right rigid ring riot ripple risk ritual rival river road roast robot +robust rocket romance roof rookie room rose rotate rough round route +royal rubber rude rug rule run runway rural sad saddle sadness safe +sail salad salmon salon salt salute same sample sand satisfy satoshi +sauce sausage save say scale scan scare scatter scene scheme school +science scissors scorpion scout scrap screen script scrub sea search +season seat second secret section security seed seek segment select +sell seminar senior sense sentence series service session settle setup +seven shadow shaft shallow share shed shell sheriff shield shift shine +ship shiver shock shoe shoot shop short shoulder shove shrimp shrug +shuffle shy sibling sick side siege sight sign silent silk silly +silver similar simple since sing siren sister situate six size skate +sketch ski skill skin skirt skull slab slam sleep slender slice slide +slight slim slogan slot slow slush small smart smile smoke smooth +snack snake snap sniff snow soap soccer social sock soda soft solar +soldier solid solution solve someone song soon sorry sort soul sound +soup source south space spare spatial spawn speak special speed spell +spend sphere spice spider spike spin spirit split spoil sponsor spoon +sport spot spray spread spring spy square squeeze squirrel stable +stadium staff stage stairs stamp stand start state stay steak steel +stem step stereo stick still sting stock stomach stone stool story +stove strategy street strike strong struggle student stuff stumble +style subject submit subway success such sudden suffer sugar suggest +suit summer sun sunny sunset super supply supreme sure surface surge +surprise surround survey suspect sustain swallow swamp swap swarm +swear sweet swift swim swing switch sword symbol symptom syrup system +table tackle tag tail talent talk tank tape target task taste tattoo +taxi teach team tell ten tenant tennis tent term test text thank that +theme then theory there they thing this thought three thrive throw +thumb thunder ticket tide tiger tilt timber time tiny tip tired tissue +title toast tobacco today toddler toe together toilet token tomato +tomorrow tone tongue tonight tool tooth top topic topple torch tornado +tortoise toss total tourist toward tower town toy track trade traffic +tragic train transfer trap trash travel tray treat tree trend trial +tribe trick trigger trim trip trophy trouble truck true truly trumpet +trust truth try tube tuition tumble tuna tunnel turkey turn turtle +twelve twenty twice twin twist two type typical ugly umbrella unable +unaware uncle uncover under undo unfair unfold unhappy uniform unique +unit universe unknown unlock until unusual unveil update upgrade +uphold upon upper upset urban urge usage use used useful useless usual +utility vacant vacuum vague valid valley valve van vanish vapor +various vast vault vehicle velvet vendor venture venue verb verify +version very vessel veteran viable vibrant vicious victory video view +village vintage violin virtual virus visa visit visual vital vivid +vocal voice void volcano volume vote voyage wage wagon wait walk wall +walnut want warfare warm warrior wash wasp waste water wave way wealth +weapon wear weasel weather web wedding weekend weird welcome west wet +whale what wheat wheel when where whip whisper wide width wife wild +will win window wine wing wink winner winter wire wisdom wise wish +witness wolf woman wonder wood wool word work world worry worth wrap +wreck wrestle wrist write wrong yard year yellow you young youth zebra +zero zone zoo +`; + +let words = null; + +/** Whether `word` (lower case) is on the list. */ +export function isBip39Word(word) { + words ??= new Set(WORDS.split(/\s+/).filter(Boolean)); + return words.has(word); +} diff --git a/src/search/placeSuggestions.js b/src/search/placeSuggestions.js index 6fa20b11b5..02e37b7bcc 100644 --- a/src/search/placeSuggestions.js +++ b/src/search/placeSuggestions.js @@ -1,3 +1,4 @@ +import { isBip39Word } from './bip39Words.js'; import { normalizePhotonFeature, photonSearchUrl } from '../keylessGeocoder.js'; import { parseCoordinateQuery } from './coordinateParser.js'; import { @@ -14,6 +15,31 @@ 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, or that a + * request about one is made of, for telling a list of places or a request + * from a recovery phrase. + */ +const MAP_WORDS = new Set( + ( + 'airport alley arena bar beach bike boat border bridge bus cabin camp ' + + 'canal canyon capital car castle cave city cliff clinic coast coffee ' + + 'country cruise dentist desert dune east elevator farm field fire ' + + 'flight forest gallery garage garden gym harbor hill hospital hotel ' + + 'island jungle kitchen lake library market meadow moon mountain museum ' + + 'nation north ocean office opera palace park pizza planet police pond ' + + 'pool rail rain ranch region ridge river road rocket route school sea ' + + 'ship shop ski snow soccer south space square stadium street subway sun ' + + 'swamp taxi tennis tornado tower town traffic train truck tunnel valley ' + + 'van vessel village volcano wagon weather west wine zoo ' + + // Words a request about a map is made of. + 'any area around best cheap city close day dinner early find food ' + + 'fresh good hour live local lunch main minute morning near night now ' + + 'old open spot that there this time today tomorrow travel trip view ' + + 'visit walk weekend what when where world' + ).split(' '), +); + /** * Text that may hold something private, which is never looked up, offered * as a place or sent anywhere: @@ -62,10 +88,27 @@ export function onlyNumbersLookPrivate(text) { // is ("card 4111 …", "phone +1 415 …", "token 12345678"). groups.every((group) => group.length <= 6) && groups.join('').length <= 9 && + !/(? (/\d/.test(text) ? 10 : 8); + +/** + * "Boise ID 83702", "Coeur d'Alene ID 83814": Idaho's code before a ZIP + * code, after a town's name (not after "my" or "employee", whose "ID" is an + * identity number). + */ +const IDAHO_BEFORE_ZIP = + /(? + ID_OWNERS.test(word.replace(/\p{P}+$/u, '')) + ? whole + : `${word}${gap}Idaho`, + ); } /** A US ZIP+4 after a state's code or name, as an address writes it. */ const US_ZIP4 = new RegExp( - String.raw`(?<=(?:^|\s)(?:[a-z]{2}|[a-z]\.[a-z]|Alabama|Alaska|Arizona|Arkansas|California|Colorado|Connecticut|Delaware|Florida|Georgia|Hawaii|Idaho|Illinois|Indiana|Iowa|Kansas|Kentucky|Louisiana|Maine|Maryland|Massachusetts|Mass|Michigan|Minnesota|Mississippi|Missouri|Montana|Nebraska|Nevada|New Hampshire|New Jersey|New Mexico|New York|North Carolina|North Dakota|Ohio|Oklahoma|Oregon|Pennsylvania|Rhode Island|South Carolina|South Dakota|Tennessee|Texas|Utah|Vermont|Virginia|Washington|West Virginia|Wisconsin|Wyoming|Puerto Rico)\.?,?\s)\d{5}-\d{4}\b`, + String.raw`(?<=(?:^|\s)(?:A[KLRZ]|C[AOT]|D[CE]|FL|GA|HI|I[ADLN]|K[SY]|LA|M[ADEINOST]|N[CDEHJMVY]|O[HKR]|PA|PR|RI|S[CD]|T[NX]|UT|V[AT]|W[AIVY]|[a-z]\.[a-z]|Alabama|Alaska|Arizona|Arkansas|California|Colorado|Connecticut|Delaware|Florida|Georgia|Hawaii|Idaho|Illinois|Indiana|Iowa|Kansas|Kentucky|Louisiana|Maine|Maryland|Massachusetts|Mass|Michigan|Minnesota|Mississippi|Missouri|Montana|Nebraska|Nevada|New Hampshire|New Jersey|New Mexico|New York|North Carolina|North Dakota|Ohio|Oklahoma|Oregon|Pennsylvania|Rhode Island|South Carolina|South Dakota|Tennessee|Texas|Utah|Vermont|Virginia|Washington|West Virginia|Wisconsin|Wyoming|Puerto Rico)\.?,?\s)\d{5}-\d{4}\b`, 'giu', ); @@ -119,6 +168,80 @@ function privacyReason(text) { ) ) return 'other'; + // An email written around a filter: "john(at)gmail.com", + // "john[at]gmail[dot]com", "john at gmail dot com". + // Also "john at gmail.com" and a "(dot)" or "[dot]" in any of them. + // Spaced letter by letter ("j o h n @ g m a i l . c o m"). + if ( + /(?:^|\s)(?:\S\s){3,}@\s?(?:\S\s?){2,}/u.test(line) && + /[^@]@[\p{L}\p{N}-]+\.\p{L}{2,}/u.test(line.replace(/\s+/g, '')) + ) + return 'other'; + if ( + /[\p{L}\p{N}._%+-]\s*[([{<]\s*at\s*[)\]}>]\s*[\p{L}\p{N}-]/iu.test(line) || + /(?])\s+\p{L}{2,24}\b/iu.test( + line, + ) || + /(?]\s*\p{L}{2,24}\b/iu.test( + line, + ) || + /(?= 2 && (host.includes('::') || colons >= 5)) return 'other'; + } + // An IP address ("10.0.0.1"). + if (/(? { + const bare = token + .replace(/^[[(]+|(?<=[^\]),.;])[\]),.;]+$/g, '') + .replace(/%\w+$/, ''); + const colons = (bare.match(/:/g) || []).length; + return ( + /^[0-9a-f:.]+$/i.test(bare) && + colons >= 2 && + (bare.includes('::') || colons >= 5) + ); + }) + ) + 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"), joined by + // dashes or slashes, or after a few words ("my seed is …"): twelve of + // the list's words in a row. The list has many words for places and for + // asking about them, and a phrase is drawn at random from all of it: + // twelve with four of those ("coffee, bar, hotel, museum, park …", "find + // good food open now near this area") are a list or a request, which a + // phrase is about once in a hundred. + const recent = []; + for (const token of line.toLowerCase().split(/[\s,;|/.\-\u2013\u2014]+/)) { + // Numbered ("1.", "(1)", "1:", "#1", "[1]") or quoted words; "and" + // before the last word joins it. + const word = token + .replace(/^["'“”„‚«»‹›‘’([{<#]*\d*[)\]:]?["'“”„‚«»‹›‘’([{<]*/, '') + .replace(/(?<=[a-z])[^a-z]+$/, ''); + if (!word || word === 'and') continue; + if (!isBip39Word(word)) { + recent.length = 0; + continue; + } + recent.push(MAP_WORDS.has(word)); + if (recent.length > 12) recent.shift(); + if (recent.length === 12 && recent.filter(Boolean).length < 4) + 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). @@ -146,7 +269,7 @@ function privacyReason(text) { .replace( // After a street word, or before the city ("12, 10115 Berlin"); // "030 12345" alone is a phone number. - /(?<=\p{L}\.?\s)\d{1,4}[a-z]?,?\s+\d{5}(?:-\d{3})?(?=\s+\p{L}|$)|(?<=^|\s)\d{1,4}[a-z]?,?\s+\d{5}(?:-\d{3})?(?=\s+\p{L})/giu, + /(?<=\p{L}\.?\s)[1-9]\d{0,3}[a-z]?,?\s+\d{5}(?:-\d{3})?(?=\s+(?!(?:thanks|thank|thx|please|pls|ok|okay|now|asap|call|text)\b)\p{L}|$)|(?<=^|\s)[1-9]\d{0,3}[a-z]?,?\s+\d{5}(?:-\d{3})?(?=\s+(?!(?:thanks|thank|thx|please|pls|ok|okay|now|asap|call|text)\b)\p{L})/giu, ' ', ) // Other postcodes after a street's house number and before the city (a @@ -164,7 +287,7 @@ function privacyReason(text) { .replace(US_ZIP4, ' x ') .replace(/\b\d{5}-\d{3}\b/g, ' x ') .replace( - /〒\s?\d{3}-\d{4}|\b\d{3}-\d{4}(?=\s*[\p{Script=Han}\p{Script=Hiragana}\p{Script=Katakana}])/gu, + /〒\s?\d{3}-\d{4}|\b\d{3}-\d{4}(?=\s*[\p{Script=Han}\p{Script=Hiragana}\p{Script=Katakana}])|(?<=[\p{Script=Han}\p{Script=Hiragana}\p{Script=Katakana}]\s*)\d{3}-\d{4}\b/gu, ' x ', ) .replace(/#/g, ' x ') @@ -176,7 +299,12 @@ function privacyReason(text) { // An IBAN. if (/\b[a-z]{2}\d{2}(?:\s?[a-z0-9]){10,}/i.test(line)) return 'other'; if ( - /\b(?:password|passcode|passwd|ssn|pw|pwd|bearer)\b\s*[:=#]?\s*\S/i.test( + /\b(?:password|passcode|passwd|pw|pwd)\b\s*[:=#]?\s*\S/i.test(line) || + // "Bearer Island" and "SSN Station" are places: after "bearer" any value + // but a capitalised name is a token, and a social security number has + // digits. + bearerToken(line) || + /\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. @@ -190,11 +318,23 @@ function privacyReason(text) { line, ) || /\b(?:token|secret|api[ _-]?key|key|pass)\s*[:=]\s*\S/i.test(line) || + // A number on a document or account after its label: "license ABC1234", + // "passport X1234567", "plate 7ABC123", "member no. 12345". + /\b(?:licen[cs]e|plate|passport|member(?:ship)?|account|acct|policy|ticket|booking|confirmation|ref(?:erence)?)(?:\s+(?:no\.?|number|#|is))*(?:\s*[:=#]\s*|\s+)(?=[a-z0-9-]*\d)[a-z0-9-]{4,}/i.test( + line, + ) || + // An identity number after "ID" in capitals ("ID AB123"); "Id" and + // "id" are words. + /\bID(?:\s+(?:no\.?|number|#|is))*(?:\s*[:=#]\s*|\s+)(?=[A-Za-z0-9-]*\d)[A-Za-z0-9-]{4,}/.test( + line, + ) || /\b(?:my secret is|passphrase|mnemonic|seed phrase|recovery phrase)\b\s*[:=]?\s*\S/i.test( 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) || + /(? 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_|xox[abposr]-)/i.test(token) || - /^(?:AIza|eyJ|AKIA)/.test(token) || + /^(?:sk[-_]|rk_|pk_live|ghp_|gho_|ghu_|ghs_|github_pat_|glpat-|hf_|xox[abposr]-)/i.test( + token, + ) || + /^SG\.[\w-]{8,}\.[\w-]{8,}$/.test(token) || + /^(?:AIza|eyJ)/.test(token) || + /^AKIA[0-9A-Z]{12,}$/.test(token) || mayBeSecret(token), ) ) @@ -224,6 +391,25 @@ function privacyReason(text) { return longNumber ? 'number' : null; } +/** + * A value after "bearer" that is not a word a place's name is made of + * ("Bearer Island"); after "Authorization:" any value is a token. + */ +function bearerToken(line) { + if (/\bauthori[sz]ation\s*:\s*bearer\b\s*\S/i.test(line)) return true; + for (const match of line.matchAll(/\bbearer\b(\s*[:=#]?\s*)(\S+)/gi)) { + const value = match[2].replace(/(?<=[^,.;:!?)])[,.;:!?)]+$/, ''); + // Only a word after a space may be a name: "Bearer: island" is a token. + if (/^\s+$/.test(match[1]) && PLACE_WORDS.test(value)) continue; + return true; + } + return false; +} + +/** Words a place's name is made of, after a label word ("bearer island"). */ +const PLACE_WORDS = + /^(?:island|islands|isle|lake|creek|river|point|bay|mountain|mount|hill|hills|valley|station|road|street|lane|avenue|park|beach|falls|springs?|county|city|town|village|plaza|square|mall|center|centre|tower|building|court|bank)$/i; + /** * A code after a label that can only be a code, without a colon ("PIN * A7B2", "verification code ABCDEF", "otp 7GH2K"): holding a digit, or in @@ -231,14 +417,59 @@ function privacyReason(text) { * "GATE CODE LANE", "OTP Bank" and "Auth Code ABCD Street" stay places. */ function codeAfterLabel(line) { + // Labels that only ever name a code take one in lower case too ("otp + // abcdef", "cvv abc", "verification code abcdef"); a capitalised word + // after them is a name ("OTP Bank", "MFA Boston"). + // 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,63})(?:(?:\s*[,;]\s*|\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) { + const [, label, value] = coded; + const labelIsName = /\p{Lu}/u.test(label); + // A word a place's name is made of is no code ("security code plaza", + // "otp bank"); after the short labels a code in letters is written in + // capitals ("otp ABCDEF"), so a lower-case word is a name ("mfa + // boston"). + // A CVV is never a name. + if (/^cv[vc]\b/i.test(label)) return true; + const shortLabel = /^(?:otp|2fa|mfa)\b/i.test(label); + const named = + PLACE_WORDS.test(value) || (shortLabel && /^\p{Ll}+$/u.test(value)); + if (!labelIsName && !named) return true; + // After a label written as a name, a value in capitals is a code ("OTP + // ABCDEF", "Verification code ABC"), one capitalised a name ("OTP + // Bank"). + if (labelIsName) { + if (/^\p{Lu}[\p{Lu}\d-]+$/u.test(value) && !PLACE_WORDS.test(value)) + return true; + if (!/^\p{Lu}(?:\p{Ll}+|\p{Lu}+)$/u.test(value)) return true; + } + } + // 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,64})(?:(?:\s*[,;]\s*|\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 ( + mixed && + /\p{Ll}/u.test(mixed[1]) && + /\p{Lu}/u.test(mixed[1]) && + !/^\p{Lu}\p{Ll}+$/u.test(mixed[1]) + ) + 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*[.!]?\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+[-–—]+\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; const [, label, value] = match; if (/\d/.test(value)) return true; - return value === value.toUpperCase() && label !== label.toUpperCase(); + // A code in capitals ("PIN ABCD", "GATE CODE ABCD"), but not a word a + // place's name is made of ("GATE CODE LANE"). + return value === value.toUpperCase() && !PLACE_WORDS.test(value); } /** @@ -292,6 +523,43 @@ export function resetPlaceSuggestions() { shared.pending.clear(); } +/** + * Countries that write a house's number before its street ("10 Downing + * Street", "12 rue de Rivoli"); elsewhere it follows ("Hauptstraße 12"). + */ +const NUMBER_FIRST = new Set([ + 'US', + 'CA', + 'GB', + 'IE', + 'AU', + 'NZ', + 'FR', + 'LU', + 'MC', + 'ZA', + 'IN', + 'PH', + 'SG', + 'MY', + 'HK', + 'TH', + 'LK', + 'NG', + 'GH', + 'KE', + 'JM', + 'TT', +]); + +/** A house's number and street as its country writes them, or ''. */ +export function houseAddress({ houseNumber, street, countryCode }) { + if (!houseNumber || !street) return ''; + return NUMBER_FIRST.has(String(countryCode || 'US').toUpperCase()) + ? `${houseNumber} ${street}` + : `${street} ${houseNumber}`; +} + /** List Photon candidates while typing. The submitted search owns navigation. */ export function createPlaceSuggester({ endpoint, @@ -308,7 +576,14 @@ export function createPlaceSuggester({ const text = String(query ?? '') .trim() .slice(0, MAX_QUERY_CHARS); - if (!enabled || text.length < minPlaceChars(text) || mayBePrivate(text)) + // A line longer than a place's name is never sent: a pasted sentence + // or phrase is no place, and may be private in ways not read here. + if ( + !enabled || + text.length < minPlaceChars(text) || + text.split(/\s+/).length > suggestMaxWords(text) || + mayBePrivate(text) + ) return []; const language = (globalThis.document?.documentElement?.lang || 'en') .slice(0, 2) @@ -384,11 +659,17 @@ export function createPlaceSuggester({ type, street, housenumber: houseNumber, + locality, + district, } = feature.properties ?? {}; - // A house has no name of its own: its street and number are its - // name, so two houses on one street stay two places. - const address = - street && houseNumber ? `${houseNumber} ${street}` : ''; + // A house has no name of its own: its street (or, without one, its + // locality) and number are its name, written in the country's own + // order, so two houses on one street stay two places. + const address = houseAddress({ + houseNumber, + street: street || locality || district || city, + countryCode, + }); const name = normalized.name || address || city || state || country; if (!name) continue; const detail = [...new Set([city, state, country])] diff --git a/src/search/placeSuggestions.test.mjs b/src/search/placeSuggestions.test.mjs index 7063008116..4df112e6ae 100644 --- a/src/search/placeSuggestions.test.mjs +++ b/src/search/placeSuggestions.test.mjs @@ -3,8 +3,10 @@ import test from 'node:test'; import { citiesInRegion, createPlaceSuggester, + houseAddress, inExtent, mayBePrivate, + onlyNumbersLookPrivate, resetPlaceSuggestions, } from './placeSuggestions.js'; @@ -392,9 +394,11 @@ test('streets named for keys, tokens and codes, and ZIP+4 after a state, are pla 'Access Token Road', 'Api Key Lane', 'GATE CODE LANE', + 'meet at Central Park [12:30:00]', + '10 Main St 123456 A Block', + 'show every plane over london then show every ship near boston please', 'SECURITY CODE PLAZA', 'OTP Bank', - 'MFA BOSTON', 'Auth Code ABCD Street', 'California 90210-1234', 'Austin Texas 78701-1234', @@ -402,7 +406,10 @@ test('streets named for keys, tokens and codes, and ZIP+4 after a state, are pla '12, 10115 Berlin', ]) assert.equal(mayBePrivate(line), false, line); + // All in capitals, a name cannot be told from a code: "MFA BOSTON" is + // kept back with "OTP ABCDEF". for (const line of [ + 'MFA BOSTON', 'gate code: abcd', 'PIN A7B2', 'PIN is A7B2', @@ -427,3 +434,240 @@ test('the same text asked again while its request is out is sent once', async () await Promise.all([service.suggest('Paris'), service.suggest('Paris')]); assert.equal(sent, 1); }); + +test('spelled-out emails, addresses, phrases, codes and short phone numbers stay private', () => { + for (const line of [ + 'john(at)gmail.com', + 'john[at]gmail[dot]com', + 'john at gmail dot de', + '10.0.0.1', + 'abandon ability able about above absent absorb abstract absurd abuse access accident', + 'Abandon ability able about above absent absorb abstract absurd abuse access accident acid', + 'license ABC1234', + 'passport X1234567', + 'plate 7ABC123', + 'otp ABCDEF', + 'verification code abcdef', + 'cvv abc', + 'Bearer abcdef', + 'Bearer Abcdefgh', + 'Authorization: Bearer Xyz', + 'glpat-abcdef123456', + 'hf_abcdefghijk', + 'SG.abcdefghij.klmnopqrstuv', + 'https://x.com/?code=abcdef', + 'code 4821', + 'garage code 4821', + 'lockbox 4821', + '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', + 'otp ab12cd - thanks', + 'gate code aBcD - thanks,', + 'gate code aBcD – thanks', + '"abandon ability able about above absent absorb abstract absurd abuse access accident"', + '“abandon ability able about above absent absorb abstract absurd abuse access accident”', + '«abandon ability able about above absent absorb abstract absurd abuse access accident»', + '»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', + '(1) abandon (2) ability (3) able (4) about (5) above (6) absent (7) absorb (8) abstract (9) absurd (10) abuse (11) access (12) accident', + 'gate code aBcD - thanks', + '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', + 'john.doe at example period com', + 'j o h n @ g m a i l . c o m', + 'ssn is 123456', + 'ssn: xxx-xx-1234', + 'Bearer: island', + 'Bearer=lake', + 'OTP ABCDEF', + 'CVV ABC', + 'Verification code ABC', + 'PIN ABCD', + 'passport:123456', + 'ID:12345', + 'abandon please abandon abandon abandon abandon abandon abandon abandon abandon abandon abstract', + 'find abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon', + 'lockbox number 4821', + 'lockbox is 4821', + 'ab 12 34 56 c', + 'https://[::1]/', + 'my, ID 12345', + 'ssn 1', + 'cvv BANK', + 'PIN ABCD thanks', + 'OTP ABCDEF now', + 'AB123456C', + 'ssn 123', + 'Jo 12345-6789', + 'Joe 1234 12345 thanks', + 'Mo 0171 12345', + ]) + assert.equal(mayBePrivate(line), true, line); + // A phone's three and four digits are not offered as an address. + assert.equal(onlyNumbersLookPrivate('is 555 0100 thanks'), false); +}); + +test('places that only looked private are looked up', () => { + for (const line of [ + 'Akiak', + 'Bearer Island', + 'SSN Station', + 'Bearer Island, Canada', + 'bearer island', + 'Washington DC 20500-0003', + '東京都千代田区100-0001', + 'Security Code Plaza', + 'Idaho Falls', + 'meet at 12:30:45', + 'Llanfairpwllgwyngyllgogerychwyrndrobwllllantysiliogogogoch', + 'llanfairpwllgwyngyll', + 'Boise ID 83702', + 'Boise, ID 83702', + 'Hayden ID 83835-1234', + 'mfa boston', + 'otp bank', + 'security code plaza', + 'zip code 90210', + 'area code 415', + 'Settipalle @ K.Bandarlapalle', + 'boise ID 83702', + "Coeur d'Alene ID 83814", + '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', + 'museum, gallery, library, palace, square, alley, canal, garden, hill, cave, farm, field', + 'find any good cheap fresh food open now near this area 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', + 'OTP Bank', + // A long request is not a recovery phrase. + 'show flights over texas near austin with altitude above thirty thousand feet please', + 'show fires near austin then show flights above texas with labels please', + ]) + assert.equal(mayBePrivate(line), false, line); +}); + +test('a house is named by its number and street in the order its country writes them', async () => { + assert.equal( + houseAddress({ + houseNumber: '10', + street: 'Downing Street', + countryCode: 'gb', + }), + '10 Downing Street', + ); + assert.equal( + houseAddress({ + houseNumber: '12', + street: 'Hauptstraße', + countryCode: 'DE', + }), + 'Hauptstraße 12', + ); + assert.equal(houseAddress({ houseNumber: '12', street: '' }), ''); + // Without a street, a house's number and its locality name it, so two + // houses in one hamlet stay two places, not the city twice. + const house = (number) => ({ + geometry: { type: 'Point', coordinates: [11.2, 47.6] }, + properties: { + housenumber: number, + locality: 'Mittenwald Au', + city: 'Mittenwald', + country: 'Germany', + countrycode: 'de', + osm_value: 'house', + }, + }); + const service = createPlaceSuggester({ + endpoint: 'https://fixture.test/api/', + fetchImpl: async () => + Response.json({ features: [house('3'), house('5')] }), + }); + assert.deepEqual( + (await service.suggest('Mittenwald Au')).map((place) => place.name), + ['Mittenwald Au 3', 'Mittenwald Au 5'], + ); +}); + +test('codes, phones, tokens, emails and addresses in further shapes stay private', () => { + for (const line of [ + // A phone's three and four digits after a name, as a postcode can't be + // told from it ("Shibuya 150-0002" is refused for that). + 'Alice 555-0100', + 'Shibuya 150-0002', + `${Array(23).fill('abandon').join(' ')} art`, + 'Bearer Abcdefghijklmnopqrstuvwxyz', + 'Bearer Island bearer abcdef', + 'verification code Abc', + 'verification code ABC', + 'verification code abc thanks', + 'PIN aBcD', + 'gate code aBcD', + 'john at gmail.com', + 'john at gmail (dot) com', + 'john at gmail [dot] com', + 'john at gmail dot technology', + 'passport number 123456', + 'passport no. 123456', + 'ID AB123', + '::1', + 'fe80::1', + '2001:db8:0:0:0:0:2:1', + ]) + assert.equal(mayBePrivate(line), true, line); +}); + +test('a line longer than a place name is never sent for suggestions', async () => { + let sent = 0; + const service = createPlaceSuggester({ + endpoint: 'https://fixture.test/api/', + fetchImpl: async () => { + sent++; + return Response.json({ features: [] }); + }, + }); + assert.deepEqual( + await service.suggest('one two three four five six seven eight nine'), + [], + ); + assert.equal(sent, 0); + // An address has more words: as many as the Omnibar reads as a place. + await service.suggest('350 Fifth Avenue, New York, NY 10118, United States'); + assert.equal(sent, 1); + 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 line of [ + ...['a-', 'a.', '1-', 'a ', '//[a:'].map((unit) => unit.repeat(10000)), + `otp a${'-'.repeat(20000)}!x`, + `gate code a${'-'.repeat(20000)}!x`, + `${','.repeat(20000)}!x`, + `bearer x${','.repeat(20000)}z`, + ]) { + const started = performance.now(); + mayBePrivate(line); + assert.ok(performance.now() - started < 1000, line.slice(0, 12)); + } +});