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]>
This commit is contained in:
Sameh KhamisandManjunath Paparaju committed 2026-11-18 16:50:46 -08:00
1 parent 46e831620e
commit 8885177e2e
3 files changed
+218 -22

No files matched your search

+31 -11
View File
@@ -8043,44 +8043,64 @@ 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"); an
IP address ("10.0.0.1"); a wallet's recovery phrase (12, 15, 18, 21 or 24
different lower-case words of three to eight letters); a line that is one
lower-case word of twenty letters or more (a passphrase run together); 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 "〒", before the address or
after a place's name ("Shibuya 150-0002"), 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 capitalised name ("Bearer Island" is a place),
"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 letters and digits after its label ("license
ABC1234"), "otp", "2fa", "mfa", "cvv", "cvc" or a verification, one-time,
security, auth or login code followed by a code in any case that is not a
capitalised name ("otp abcdef"; "OTP Bank" is a place), 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
`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) 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,
+103 -11
View File
@@ -62,6 +62,7 @@ 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)
);
}
@@ -89,7 +90,7 @@ function foldLine(text) {
/** 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 +120,31 @@ 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".
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\s+\p{L}{2,6}\b/iu.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';
// A wallet's recovery phrase: 12, 15, 18, 21 or 24 different words, all
// of three to eight letters in lower case ("abandon ability able …"). A
// request that long nearly always has a short word ("to", "in", "me").
const words = line.trim().split(/\s+/);
if (
[12, 15, 18, 21, 24].includes(words.length) &&
new Set(words).size === words.length &&
words.every((word) => /^[a-z]{3,8}$/.test(word))
)
return 'other';
// A passphrase run together ("correcthorsebatterystaple"): a line that
// is one word of twenty letters or more, all lower case. A long place
// name is written with its capital ("Llanfairpwllgwyngyll"), and a long
// word inside a name ("… selskokhozyaystvennoy opytnoy stantsii") has
// others beside it.
if (words.length === 1 && /^[a-z]{20,}$/.test(words[0])) 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 +172,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 +190,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{L}{3,},?\s)\d{3}-\d{4}(?=\s*$|,)/gu,
' x ',
)
.replace(/#/g, ' x ')
@@ -176,9 +202,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*[:=#]?\s*\d/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 +219,11 @@ 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+(?=[a-z0-9-]*\d)(?=[a-z0-9-]*[a-z])[a-z0-9-]{4,}/i.test(
line,
) ||
/\b(?:my secret is|passphrase|mnemonic|seed phrase|recovery phrase)\b\s*[:=]?\s*\S/i.test(
line,
) ||
@@ -216,7 +250,8 @@ function privacyReason(text) {
.some(
(token) =>
/^(?:sk[-_]|rk_|pk_live|ghp_|xox[abposr]-)/i.test(token) ||
/^(?:AIza|eyJ|AKIA)/.test(token) ||
/^(?:AIza|eyJ)/.test(token) ||
/^AKIA[0-9A-Z]{12,}$/.test(token) ||
mayBeSecret(token),
)
)
@@ -224,6 +259,12 @@ function privacyReason(text) {
return longNumber ? 'number' : null;
}
/** A value after "bearer" that is not a capitalised name ("Bearer Island"). */
function bearerToken(line) {
const match = /\bbearer\b\s*[:=#]?\s*(\S+)/i.exec(line);
return Boolean(match) && !/^\p{Lu}\p{Ll}+$/u.test(match[1]);
}
/**
* 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 +272,14 @@ 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").
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*[.!]?\s*$/i.exec(
line,
);
if (coded && !/^\p{Lu}(?:\p{Ll}+|\p{Lu}+)$/u.test(coded[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,
@@ -292,6 +341,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,
@@ -384,11 +470,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])]
+84
View File
@@ -3,8 +3,10 @@ import test from 'node:test';
import {
citiesInRegion,
createPlaceSuggester,
houseAddress,
inExtent,
mayBePrivate,
onlyNumbersLookPrivate,
resetPlaceSuggestions,
} from './placeSuggestions.js';
@@ -427,3 +429,85 @@ 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',
'correcthorsebatterystaple',
'license ABC1234',
'passport X1234567',
'plate 7ABC123',
'otp abcdef',
'verification code abcdef',
'cvv abc',
'Bearer abcdef',
'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',
'Shibuya 150-0002',
'Llanfairpwllgwyngyllgogerychwyrndrobwllllantysiliogogogoch',
'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'],
);
});