Compare commits

...
Author SHA1 Message Date
Sameh KhamisandManjunath Paparaju d15c69a8ae Add the changelog entry for the place privacy fixes
Co-authored-by: Manjunath Paparaju <[email protected]>
2026-11-18 17:21:40 -08:00
Sameh KhamisandManjunath Paparaju 2a4079e9f8 Keep SSNs with "is", "Bearer:" values and codes in capitals private, and let West Point through
"ssn is 123456" and a masked "ssn: xxx-xx-1234", "Bearer: island", codes
in capitals after their label ("OTP ABCDEF", "PIN ABCD", any CVV), a
document number or ID right after its colon, "lockbox number 4821", a UK
National Insurance number in lower case and an IPv6 host in a link are
private. A recovery phrase starting with "find" or holding "please" (both
on its word list) is caught. "Point" is not read as a spelled dot, so
"meet at West Point tomorrow" is looked up, and Idaho's code follows a town
written in any case ("BOISE ID 83702", "Coeur d'Alene ID 83814").

Co-authored-by: Manjunath Paparaju <[email protected]>
2026-11-18 17:21:32 -08:00
Sameh KhamisandManjunath Paparaju 200c788ac1 Let Idaho, questions and long place names through, and keep more tokens and codes private
"Boise ID 83702" names Idaho rather than an identity number. A long question
for the assistant is no recovery phrase: a phrase holds none of the common
words its list lacks ("the", "and", "are"). A long lower-case place name
is no passphrase, an address of up to ten words is sent as the Omnibar reads
it, and "mfa boston", "otp bank" and "security code plaza" are names.

"Authorization: Bearer" and any value after "bearer" but a place word are
tokens, and so are GitLab, Hugging Face and SendGrid keys and a code in a
link. Door, alarm and lockbox numbers (not a zip or area code), a spaced UK
National Insurance number, "my id is …", and emails spelled with "punto",
"period", a spaced dot or letter by letter are private too.

Co-authored-by: Manjunath Paparaju <[email protected]>
2026-11-18 17:13:12 -08:00
Sameh KhamisandManjunath Paparaju 35049fd7f7 Keep more shapes of phones, codes, tokens, emails and IP addresses private
Review found "Alice 555-0100" sent as a Japanese postcode, recovery phrases
with a repeated word, a capitalised bearer token, codes after a lower-case
label in other cases ("verification code Abc", "PIN aBcD"), "john at
gmail.com" and "(dot)" forms, passport numbers of digits only, "ID AB123"
and IPv6 addresses. They now stay in the browser, and the suggester never
sends a line of more than eight words. "Bearer Island, Canada", "bearer
island", a ZIP+4 after two spaces and a Japanese postcode after Japanese
script are looked up again.

Co-authored-by: Manjunath Paparaju <[email protected]>
2026-11-18 16:59:35 -08:00
Sameh KhamisandManjunath Paparaju 8885177e2e Keep spelled-out emails, IP addresses, recovery phrases and lower-case codes from the place service
Place suggestions still sent "john(at)gmail.com", "10.0.0.1", a wallet's
recovery phrase, a passphrase run together, "license ABC1234", lower-case
codes after a code label ("otp abcdef", "cvv abc") and short phone numbers
read as an address ("Jo 12345-6789", "Mo 0171 12345"), and a phone's three
and four digits could still be searched as a place on purpose. They now stay
in the browser. Real places that only looked private are looked up again:
Akiak, Bearer Island, SSN Station, Shibuya 150-0002. A suggested house is
named in its country's order ("Hauptstraße 12"), and one without a street
keeps its number.

Co-authored-by: Manjunath Paparaju <[email protected]>
2026-11-18 16:50:46 -08:00
4 changed files with 521 additions and 33 deletions

No files matched your search

+7
View File
@@ -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).
+59 -16
View File
@@ -8026,10 +8026,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
@@ -8043,49 +8046,89 @@ 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 ("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"; 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 to twenty-four short words with none of
the common words a phrase list lacks, such as "the", "and" or "are", so a
long question still goes to Ask GEV), "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
+262 -16
View File
@@ -62,10 +62,49 @@ export function onlyNumbersLookPrivate(text) {
// is ("card 4111 …", "phone +1 415 …", "token 12345678").
groups.every((group) => group.length <= 6) &&
groups.join('').length <= 9 &&
!/(?<!\d)\d{3}[ .-]\d{4}(?!\d)/.test(line) &&
!NUMBER_CONTEXT.test(line)
);
}
/**
* The most words a line sent for place suggestions may have: as many as the
* Omnibar reads as a place's name (ten with a number, as an address has).
*/
const suggestMaxWords = (text) => (/\d/.test(text) ? 10 : 8);
/**
* Common words no wallet's recovery phrase holds (they are not on the BIP39
* list): a line with one is a sentence, however many short words it has.
*/
const NOT_SEED_WORDS = new Set([
'the',
'and',
'are',
'for',
'from',
'with',
'how',
'why',
'which',
'would',
'could',
'should',
'does',
'was',
'were',
'flights',
]);
/**
* "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 = /(\S+)(,?\s)ID(?=\.?,?\s+\d{5}(?:-\d{4})?(?!\S))/gu;
const ID_OWNERS =
/^(?:my|your|our|his|her|their|employee|student|staff|member|user|customer|patient|national|voter|photo|tax|card|the|an?)$/i;
/**
* Words that say a number is an account, a card, a phone or a secret, in the
* interface's languages where they differ ("Karte", "Telefon", "tarjeta").
@@ -84,12 +123,16 @@ function foldLine(text) {
.normalize('NFKC')
.replace(/\p{Cf}/gu, '')
.replace(/[\u2018\u2019]/g, "'")
.replace(/(?![0-9])\p{Nd}/gu, '0');
.replace(/(?![0-9])\p{Nd}/gu, '0')
.replace(/\s+/g, ' ')
.replace(IDAHO_BEFORE_ZIP, (whole, word, gap) =>
ID_OWNERS.test(word) ? 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 +162,59 @@ 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) ||
/\b\S+\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(
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(
line,
)
)
return 'other';
// An IPv6 host in a link ("https://[::1]/").
if (/\[[0-9a-f:.]*:[0-9a-f:.]*:[0-9a-f:.]*\]/i.test(line)) return 'other';
// An IP address ("10.0.0.1").
if (/(?<![\d.])\d{1,3}(?:\.\d{1,3}){3}(?![\d.])/.test(line)) return 'other';
// An IPv6 address ("::1", "fe80::1%eth0", "2001:db8:0:0:0:0:2:1"): hex
// groups with "::", or five colons or more (a time has two).
if (
line.split(' ').some((token) => {
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, whole or nearly ("abandon ability able
// …"): twelve to twenty-four words of three to eight letters, none a
// common word the phrase list lacks ("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((word) => /^[a-z]{3,8}$/.test(word)) &&
!words.some((word) => NOT_SEED_WORDS.has(word))
)
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 +242,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 +260,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,9 +272,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(
line,
) ||
/\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|no\.?|number|#))*\s*[:=#]?\s*[\dx*]{3}/i.test(line) ||
// The word for "password" in the interface's languages.
// A whole word only: "Sachsenhausen" holds "senha" but is a place.
/(?<!\p{L})(?:contraseña|passwort|kennwort|mot de passe|senha|parola d'ordine|lösenord|пароль|пароля|密码|密碼|パスワード|비밀번호|סיסמה|كلمة (?:السر|المرور))(?!\p{L})\s*[:=#]?\s*\S/iu.test(
@@ -190,6 +289,16 @@ 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,
) ||
@@ -204,7 +313,27 @@ function privacyReason(text) {
/\b(?:pin|otp|2fa|mfa|cvv|cvc|(?:door|access|gate|alarm|entry|security|verification|one-time|auth|login) code)\s*(?:[:=#]|\s[-–—]\s|-)\s*[a-z0-9]/i.test(
line,
) ||
codeAfterLabel(line)
codeAfterLabel(line) ||
// A door, alarm or lockbox number ("code 4821", "garage code 4821",
// "the code to my door is 4821").
// A postcode, dialling code or airport code is not one ("zip code
// 90210", "area code 415").
/\b(?<!\b(?:zip|postal|post|postcode|area|country|dialing|dialling|airport|iata|icao|country)\s)(?:code|alarm|lockbox|lock box|combination|combo|keypad)(?:\s+(?:number|no\.?|is|code|pin))*\s*[:=#]?\s*\d{3,8}\b/i.test(
line,
) ||
/\b(?<!\b(?:zip|postal|post|area|country|dialing|dialling|airport)\s)code\b.{0,30}?\bis\s*[:=]?\s*\d{3,8}\b/i.test(
line,
) ||
// A UK National Insurance number, spaced ("AB 12 34 56 C").
/\b[a-z]{2}\s?\d{2}\s?\d{2}\s?\d{2}\s?[a-d]\b/i.test(line) ||
// "my id is AB12345", "id no. 4471".
/\bid\s+(?:is|no\.?|number|#)\s*[:=#]?\s*(?=[a-z0-9-]*\d)[a-z0-9-]{4,}/i.test(
line,
) ||
// A one-time code in a link ("…/callback?code=abcdef").
/[?&](?:code|token|access_token|key|sig|signature|auth)=[^&\s]{4,}/i.test(
line,
)
)
return 'other';
if (
@@ -215,8 +344,12 @@ function privacyReason(text) {
.map((token) => token.replace(/^[^\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 +357,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,6 +383,48 @@ 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,})(?:\s+(?:thanks|thank you|thx|please|pls|ok))?\s*[.!]?\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").
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"); a CVV is never a name.
if (labelIsName) {
if (/^cv[vc]\b/i.test(label)) return true;
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,})\s*[.!]?\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(
line,
@@ -238,7 +432,9 @@ function codeAfterLabel(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 +488,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 +541,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 +624,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])]
+193 -1
View File
@@ -3,8 +3,10 @@ import test from 'node:test';
import {
citiesInRegion,
createPlaceSuggester,
houseAddress,
inExtent,
mayBePrivate,
onlyNumbersLookPrivate,
resetPlaceSuggestions,
} from './placeSuggestions.js';
@@ -394,7 +396,6 @@ test('streets named for keys, tokens and codes, and ZIP+4 after a state, are pla
'GATE CODE LANE',
'SECURITY CODE PLAZA',
'OTP Bank',
'MFA BOSTON',
'Auth Code ABCD Street',
'California 90210-1234',
'Austin Texas 78701-1234',
@@ -402,7 +403,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 +431,191 @@ 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',
'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]/',
'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',
// 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);
});